Bucketing
A concise field guide to choosing between Hash Bucketing and Random Bucketing in StarRocks, including their mechanics, trade‑offs, and recommended use cases.
Quick‑Look Comparison
| Aspect | Hash Bucketing | Random Bucketing |
|---|---|---|
| Example | DISTRIBUTED BY HASH(id) BUCKETS 16 | DISTRIBUTED BY RANDOM |
| Key declaration | Required HASH(col1, …) | None – rows assigned round‑robin |
| Initial bucket count when omitted | Auto‑chosen at CREATE, then fixed | Auto‑chosen at CREATE; can grow if bucket_size set |
| Tablet split / shrink | Manual ALTER … BUCKETS | Automatic split ⇢ growth only (≥ v3.2) |
| Skew resistance | Depends on key cardinality | High – uniform by design |
| Bucket pruning | ✅ (filters, joins) | 🚫 (full tablet scan) |
| Colocate joins | ✅ | 🚫 |
| Local aggregation / bucket-shuffle joins | ✅ | 🚫 |
| Supported table types | All | Duplicate Key tables only |
Hash Bucketing
How it Works
Rows are assigned to tablets by hashing one or more columns. Tablet count is fixed after creation unless manually altered.
Requirements
- Must pick a stable, evenly, high‑cardinality key up front. The cardinality should typically be 1000 times more than the number of BE nodes to prevent data skew among hash buckets.
- Choose an appropriate bucket size initially, ideally ranging between 1 to 10 GB.
Strengths
- Query locality – selective filters and joins touch fewer tablets.
- Colocate joins – fact/dim tables can share hash keys for high‑speed joins.
- Predictable layout – rows with the same key always land together.
- Local aggregation & bucket‑shuffle joins – identical hash layout across partitions enables local aggregation and reduces data shuffle costs for large join