Skip to main content
Fast analytics in the database begin with a table layout that matches your query patterns. This guide distills hands‑on experience into clear rules for partitioning, helping you:
  • Scan less data via aggressive partition pruning
  • Manage lifecycle tasks (TTL, GDPR deletes, tiering) with metadata‑only ops;
  • Scale smoothly as tenant counts, data volume, or retention windows grow.
  • Controlled write amplification–New data lands in the “hot” partition; compaction happens in historical partitions
Keep this advice close when modeling a new table or refactoring an old one—each section gives purpose‑driven criteria, design heuristics, and operational guard‑rails so you avoid costly re‑partitioning down the road.

Partitioning vs. Bucketing–different jobs

Understanding the distinction between partitioning and bucketing is fundamental when designing performant tables. While both help manage large datasets, they serve different purposes:
  • Partitioning allows the database to skip entire blocks of data at query time using partition pruning, and enables metadata-only lifecycle operations like dropping old or tenant-specific data.
  • Bucketing, on the other hand, helps distribute data across tablets to parallelize query execution and balance load, especially when combined with hash functions.

When should I partition?

Choosing the partition key

  1. Time‑first default–If 80 % of queries include a time filter, lead with date_trunc('day', dt).
  2. Tenant isolation–Add tenant_id into the key when you need to manage the data in tenant basis
  3. Retention alignment–Put the column you plan to purge on into the key.
  4. Composite keys: PARTITION BY tenant_id, date_trunc('day', dt) prunes perfectly but creates #tenants × #days partitions. Keep below ≈ 100 k total or FE memory & BE compaction suffer.

Picking granularity

The granularity of PARTITION BY date_trunc('day', dt) should be adjusted based on the use case. You can use “hour,” “day,” or “month,” etc. See date_trunc
  • Rule of thumb: Keep each partition ≤ 100 GB and ≤ 20 k tablets/partition across replicas.
  • Mixed granularity: Starting from version 3.4, the database supports mixed granularity by merging historical partitions into coarser granularity.

Example recipes

Click‑stream fact (single‑tenant)

SaaS metrics (multi‑tenant, pattern A)

Recommended for most SaaS workloads. Prunes on time, keeps tenant rows co‑located.

Whale tenant composite (pattern B)

When tenant-specific DML/DDL is necessary or large-scale tenants are present, be cautious of potential partition explosion.