NEW RasterizedDB 1.1.0 is out: sharding and the gateway, the message broker, roles and row-level security, compression, .NET on NuGet, and the enterprise edition. What's new ›
PARTITIONING

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.

HOW IT WORKS · ANIMATED 12 s cycle

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.

STATEMENT SELECT * FROM assets WHERE tenant_id = 42 FROZEN HASH hash(42) → partition 39 the same partition, forever assets · 64 PARTITIONS 39 p39 → PARTITION STATE closed: no files open open, counted in the budget opened p39 on first touch closed 4 idle partitions persistent index sealed at close SELECT count(*) no key: all 64, scan-only, one snapshot
  1. 1
    A keyed statement

    SELECT * FROM assets WHERE tenant_id = 42 fixes the partition key.

  2. 2
    Frozen hash

    The key is hashed with a hash that never changes, so tenant 42 always lands in the same partition.

  3. 3
    One partition of 64

    Only partition 39 can hold tenant 42's rows. The other 63 are not consulted.

  4. 4
    Opened on first touch

    Partition 39 opens now, counted against an open budget. Nothing was opened at startup.

  5. 5
    Idle ones close

    Partitions nobody has touched for a while close, their persistent index sealed on the way out.

  6. 6
    A query without the key

    SELECT count(*) fans out under one snapshot, opening partitions scan-only for the duration.

1 / 3

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.

SQL
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
2 / 3

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.

64partitions by default
2²⁰partitions measured in one table
0partitions opened at startup
3 / 3

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
SQL
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';
✓ page rendered in 192 µs axum + tera + htmx · no other javascript