A million partitions, opened only when touched.
Hash partitioning spreads one logical table over many file sets by a frozen hash of its key. Partitions open lazily, on first touch, under an open budget, and close again when idle, so a table can have far more partitions than the process has file descriptors.
One key, one partition, and the rest stay closed
A partitioned table is many file sets chosen by a frozen hash of the key. A statement that fixes the key opens one of them; partitions are opened on first touch and closed again when idle.
- 1A keyed statement
SELECT * FROM assets WHERE tenant_id = 42 fixes the partition key.
- 2Frozen hash
The key is hashed with a hash that never changes, so tenant 42 always lands in the same partition.
- 3One partition of 64
Only partition 39 can hold tenant 42's rows. The other 63 are not consulted.
- 4Opened on first touch
Partition 39 opens now, counted against an open budget. Nothing was opened at startup.
- 5Idle ones close
Partitions nobody has touched for a while close, their persistent index sealed on the way out.
- 6A query without the key
SELECT count(*) fans out under one snapshot, opening partitions scan-only for the duration.
Declare it like PostgreSQL
A statement that fixes the key, or its leading column, touches only the partitions that can hold its rows. Any other reads all of them under one snapshot. Each partition has its own files, locks, indexes and vacuum state.
CREATE TABLE assets ( tenant_id BIGINT NOT NULL, asset_group_id BIGINT NOT NULL, asset_id UUID NOT NULL, body TEXT, PRIMARY KEY (tenant_id, asset_group_id, asset_id) ) PARTITION BY HASH (tenant_id, asset_group_id); SELECT * FROM assets WHERE tenant_id = 42; -- one partition
Lazy partitions
No partition opens at startup. A partition opens on its first read or write, counts against an open budget managed by a sharded CLOCK, and is closed when idle, its persistent index sealed on the way out. A fan-out scan opens partitions scan-only. Descriptors are released promptly.
Reshape it while it runs
A tenant that outgrows its partition gets one of its own, on its own disk, or is split by the next key column.
- Foreign keys in both directions
- An UPDATE that changes the key moves the row
- ADD COLUMN and CREATE INDEX apply to every partition
- Placement across storage locations, per partition
ALTER TABLE assets ISOLATE KEY (tenant_id = 42) TO '/mnt/nvme2'; ALTER TABLE assets SPLIT KEY (tenant_id = 42) INTO 8; ALTER TABLE assets SPLIT PARTITION FOR (tenant_id = 7); ALTER TABLE assets MERGE PARTITIONS FOR (tenant_id = 7), FOR (tenant_id = 9); STORAGE MOVE PARTITION assets FOR (tenant_id = 7) TO '/mnt/disk2';