Narrow Table
A narrow table is a database table structure characterized by a small number of columns, typically containing fewer than 10 fields. This design pattern is particularly relevant for time-series data where each record captures a specific measurement or event with minimal attributes.
Understanding narrow tables
Narrow tables represent a fundamental database design pattern that contrasts with wide tables. In a narrow table structure, each row contains only essential fields, making it particularly efficient for:
- Sequential reads of specific columns
- Time-series data storage
- High-volume data ingestion
- Column-oriented storage systems
For example, a narrow table storing temperature sensor readings might contain just three columns: timestamp, sensor_id, and temperature_value.
Next generation time-series database
QuestDB is an open-source time-series database optimized for market and heavy industry data. Built from scratch in Java and C++, it offers high-throughput ingestion and fast SQL queries with time-series extensions.
Benefits of narrow table design
Storage efficiency
Narrow tables excel in columnar database systems because:
- Less memory is required for loading column data
- Better compression ratios are achievable
- More efficient use of CPU cache lines
- Reduced I/O overhead during queries
Query performance
Queries on narrow tables often perform better because:
- Fewer columns need to be processed
- Simpler query plans
- More efficient column pruning
- Better utilization of database page cache
Next generation time-series database
QuestDB is an open-source time-series database optimized for market and heavy industry data. Built from scratch in Java and C++, it offers high-throughput ingestion and fast SQL queries with time-series extensions.
Common use cases
Time-series data
Narrow tables are particularly well-suited for time-series applications:
Market data storage
In financial markets, narrow tables efficiently store tick-level data:
SELECT * FROM tradesWHERE symbol = 'AAPL'SAMPLE BY 1h;
This query demonstrates efficient sampling of a narrow table containing market trades data.
Design considerations
When implementing narrow tables, consider:
- Denormalization trade-offs
- Join complexity with related data
- Impact on application-level data access
- Storage system characteristics
The decision to use narrow tables should align with:
- Query patterns
- Data access requirements
- Storage engine capabilities
- Performance objectives
For example, if your application frequently needs to access related attributes, the overhead of joining multiple narrow tables might outweigh the benefits of the narrow structure.
Best practices
-
Identify core attributes:
- Keep only essential columns
- Move rarely accessed fields to separate tables
- Consider query patterns when deciding column inclusion
-
Optimize for common queries:
- Align column selection with frequent query patterns
- Consider denormalization when beneficial
- Balance storage efficiency with query performance
-
Monitor performance:
- Track query execution times
- Monitor storage utilization
- Assess join overhead
- Evaluate compression effectiveness
The effectiveness of narrow tables often depends on the underlying storage engine and its optimization capabilities for column-oriented access patterns.