A Greenplum column-oriented table has 200 columns and daily partitions for three years — why does that hurt, and what instead?
Each column of each partition is a separate file on every segment: 200 columns × 1,095 days is about 219,000 files per segment, which costs planning, catalog and file-open work. Partition by month instead, with fewer, fuller partitions, and set storage per partition.
- Partitioning a column-oriented table as finely as possible without counting columns × partitions files per segment
- Expecting pruning to make the partition count free, though planning and catalog work grow with it
- Adding a second partition level, which multiplies the file count again
- What decides the right partition grain for a fact table: query filters, retention, or partition size?
- Why might the current month stay heap while older months become column-oriented and compressed?
Where all the files come from (Greenplum and its forks Arenadata DB and Greengage DB). In an append-optimized column-oriented table every column is a separate file on every segment, and every partition is its own table with its own files. So per segment: columns × partitions.
| Layout | Partitions | Files per segment |
|---|---|---|
| 200 columns, daily for 3 years | 1,095 | ≈ 219,000 |
| 200 columns, monthly for 3 years | 36 | ≈ 7,200 |
| second level: day × 50 regions | 54,750 | ≈ 11,000,000 |
Partition pruning does not make that cost zero. The planner handles metadata for every partition, the catalog grows, ANALYZE, VACUUM and backups walk every file, and every segment holds open the files of every column a query reads. A daily partition of a column table on 48 segments is also small: if a day holds a few million rows, cutting them into 48 parts and 200 files leaves too little for column storage and compression to pay off.
What to do instead:
- Monthly (or weekly) partitions: pruning on a date range is nearly as effective, with tens of times fewer files. Old data is dropped a month at a time.
- Storage per partition: the current month, still being loaded and corrected, heap or row-oriented; closed months column-oriented and compressed.
- No second partition level when queries nearly always filter on date alone.
CREATE TABLE fact_events (event_date date, user_id bigint /* ... 198 more columns */)
WITH (appendoptimized = true, orientation = column, compresstype = zstd)
DISTRIBUTED BY (user_id)
PARTITION BY RANGE (event_date)
(START (date '2024-01-01') INCLUSIVE END (date '2027-01-01') EXCLUSIVE EVERY (INTERVAL '1 month'));