Partition skew and overhead
Overview
Partition skew means uneven data or workload distribution. A large active partition can dominate scans and writes even when other partitions are small. Too many partitions can increase planning time, metadata, memory and index maintenance. Range keys help retention and time filters, list keys suit stable categories, and hash keys may spread many distinct values but do not split one hot key automatically. Partitioning does not guarantee a speedup.
First example
WITH counts AS (SELECT COUNT(*) AS n FROM pt_early UNION ALL SELECT COUNT(*) FROM pt_late)SELECT MAX(n),MIN(n),1.0*MAX(n)/NULLIF(MIN(n),0) FROM counts;Observed SQLite result (rows in JSON):
[ [ 4, 2, 2 ]]How it works
The first query reports actual range populations of 4 and 2. Their largest-to-smallest ratio is 2 for nonempty partitions. The second compares region populations (east 4, west 2). Empty partitions need separate reporting because dividing by zero is undefined. Row counts alone do not measure query load, storage or latency; use workload and plan evidence. In production consider partition count, time granularity, and local index overhead.
Practical example
SELECT region,COUNT(*) FROM pt_all GROUP BY region ORDER BY region;Observed SQLite result (rows in JSON):
[ [ "east", 4 ], [ "west", 2 ]]Practice and mistakes
Practice: add a hypothetical 100 rows to the late range and recalculate skew. Hint 1: compare the two populations, not their key widths. Hint 2: consider frequent day filters and retention together. Do not claim physical speed improvements without controlled measurements.
PostgreSQL 17 example — NOT RUN
BEGIN;CREATE TEMP TABLE bm_pt(day integer NOT NULL,id integer NOT NULL,PRIMARY KEY(day,id)) PARTITION BY RANGE(day);CREATE TEMP TABLE bm_pt_early PARTITION OF bm_pt FOR VALUES FROM (1) TO (11);CREATE TEMP TABLE bm_pt_late PARTITION OF bm_pt FOR VALUES FROM (11) TO (21);INSERT INTO bm_pt VALUES (1,1),(5,2),(10,3),(10,4),(11,5),(20,6);SELECT tableoid::regclass AS part,COUNT(*) FROM bm_pt GROUP BY tableoid;ROLLBACK;Expected result, not executed: "Counts 4 and 2; no runtime or disk benchmark."