Home/Labs/Partition & Z-Order Pruner
All 280 Labs
INTERACTIVE LAB✂️

Partitioning & Clustering Lab (Interactive)

Match flat, date-partitioned, and Z-ordered layouts to three WHERE clauses and price the scan in dollars. Compute scanned terabytes, BigQuery-style billing at $6.25/TB, and latency for directory pruning, micro-partition min/max skipping, and space-filling curve clustering.

Partition Pruning & Z-Order Clustering

Match the physical layout to the WHERE clause and watch BigQuery-style scan billing collapse.

Storage layout
Clustering key strategy
Dashboard query filter
Table size
28.5 TB
730 days x 40 GB
Bytes scanned
819 MB
0.003% of table
Query cost
$0.00488
full scan would be $178
Est. latency
40 ms
100.00% pruning gain
Coarse directory pruning eliminates whole date folders first; micro-partition min/max metadata then skips irrelevant 16-50 MB clusters. Rule of thumb: partition only low-cardinality date/region columns, cluster high-cardinality tenant/status columns — never partition by tenant_id or you rebuild the small-files disaster at catalog scale.

How It Works Under the Hood

Analytical billing follows bytes scanned, so physical layout is a pricing decision. Date partitioning prunes whole directories: a one-day query over five years reads 0.06% of storage. Clustering sorts micro-partitions inside each folder so min/max metadata skips irrelevant 16-50 MB blocks for tenant or status filters. Linear multi-column sorting biases toward the leading column, leaving tenant-only queries unpruned, while Z-Ordering interleaves dimension bits along a Morton curve so filtering any subset of clustered columns prunes effectively.

Core Architectural Principles

  • Directory partition pruning removes entire date folders from the execution plan before scanning.
  • Micro-partition min/max bounds let clustered columns skip blocks that cannot match the predicate.
  • Z-Order interleaving gives balanced pruning for single-dimension filters that linear ORDER BY cannot.
Interview Round Script

When optimizing a dashboard, present layout as a two-tier strategy: coarse date partitioning for time-slice pruning, clustering keys on high-frequency filters like tenant_id, and never partition on high-cardinality IDs because that explodes into millions of tiny files. Mention $/TB scanned economics to prove the cost reasoning, and cite re-clustering maintenance compute as the honest cost.

Key Trade-Offs

Pruning slashes scan cost and latency but over-partitioning and re-clustering add file sprawl and background compute.

Related Curriculum Chapter

Partitioning & Clustering for Analytics Workloads

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs