Morteza Fathollahi
05/31/2026, 6:13 PMRocky
05/31/2026, 6:13 PMID (e.g., user_id), and you want to partition by created_at, you would be forced to change your Primary Key to (ID, created_at).
* This changes the uniqueness constraint: you could technically have the same ID in two different months. If your business logic expects a truly unique ID across the whole table, partitioning by a time column complicates this.
3. Primary Key Index Memory
One of the main reasons to partition a PK table is to limit the memory/IO needed for the Primary Key Index during ingestion.
* Partitioned: StarRocks only loads the index for the "hot" partition being written to.
* Unpartitioned: It must check the index for the entire 150 million rows to ensure uniqueness.
* Verdict: At 150 million rows, even a single-partition index is relatively small. If you enable the Persistent Index (default in recent versions), StarRocks handles this scale easily on disk with minimal memory impact.
4. When SHOULD you partition?
You should only use monthly partitioning in this case if:
* Data Lifecycle (TTL): You need to drop old data frequently (e.g., "delete everything older than 3 years"). Dropping a partition is a metadata operation and much faster than a DELETE query.
* Storage Tiering: You want to move older months to cheaper storage (S3/HDD) while keeping recent months on SSD.
Summary Recommendation
* Recommendation: Use a single partition (do not use PARTITION BY) and use Hash Distribution on your primary key.
* Bucket Count: For 150 million rows, aim for a total tablet count that keeps each tablet around 1GB–10GB. For example, if you have 3–5 BE nodes, DISTRIBUTED BY HASH(pk) BUCKETS 10-20 is usually sufficient.
* Optimization: Ensure enable_persistent_index is set to true (it is by default since v2.3) to keep memory usage low as you grow toward 150M+ rows.
If you eventually reach billions of rows or find that queries filtering by month are too slow, you can use ALTER TABLE (in newer versions) or a swap-table migration to introduce partitioning later, but at 150M rows, simplicity is better.
References
• table_design/table_types/primary_key_table.md
• best_practices/query_tuning/schema_tuning.md