<@U0A71G31CDV> is it advised to not have one parti...
# questions-and-troubleshooting
d
@Rocky is it advised to not have one partition per tenant? The docs don’t recommend it but don’t warn against it either. Specifically, we’re seeking to partition by
integration_id
, of which currently we have about 700 unique values in gold-level tables. The largest bucket in one table is 17GB at the moment.
r
Short answer: 700 partitions is not a red flag in itself — but "one partition per tenant" is a design the docs deliberately steer you away from as a default, and the reasons apply to your case. Here's what the docs actually quantify: Where 700 lands on the documented scale • Typical partition count per table is quoted as 10²–10⁴ (days, weeks, tenants). 700 is comfortably inside that. • Hard limits:
max_partition_number_per_table
defaults to 100 000;
max_partitions_in_one_batch
defaults to 4096 for bulk partition creation. The stated red flag is
100k partitions per table
(FE memory) and
200k tablets per BE
. • Size-wise you're fine: the rule of thumb is ≤100 GB per partition, and 17 GB is well under it. (Tablet sizing: ~10 GB raw per tablet on shared-nothing; 10–50 GB, max 100 GB, on shared-data v4.1+.) So what's the actual risk? Two things, neither of which is the partition count: 1. Tablets = partitions × buckets × replicas. 700 partitions is only cheap if each partition is small in bucket terms. Each new tenant partition also multiplies. The docs' FE heap guidance is keyed on tablet count, not partition count (<1M tablets → 16 GB FE heap, 1–2M → 32 GB, etc.). If you have many gold tables each carrying 700 tenant partitions, that aggregate is what you need to sanity-check. 2. You lose time pruning. Partitioning by
integration_id
alone means a query without an
integration_id
predicate scans all 700 partitions. The docs' SaaS recipe (pattern A) is the inverse of yours: partition by
date_trunc('day', dt)
, and put
tenant_id
in the hash distribution (
DISTRIBUTED BY HASH(tenant_id)
). Their "whale tenant" pattern B (
PARTITION BY tenant_id, date_trunc('MONTH', dt)
) is exactly for when per-tenant DDL/DML is genuinely required — and it's explicitly flagged as risking partition explosion because of the multiplicative count. When per-tenant partitioning is the right call: the docs list tenant isolation and
DROP PARTITION
(metadata-only, ideal for GDPR deletes / offboarding a tenant) as legitimate reasons to put
tenant_id
in the key. If your queries and lifecycle ops are mostly per-integration, that's a real win. If your queries are mostly time-range and cross-integration, it's a cost. Two things worth checking before you decide: •
SHOW PARTITIONS FROM <table>
gives per-partition bucket count and data size — do this on your real tables; the average bucket will be far below 17 GB, and small/empty tenant partitions are a documented source of near-empty tablets (and, on shared-data, extra tablet metadata files in object storage that slow table creation). • Whether the bulk of your queries carry an
integration_id
predicate or a time predicate. Want to share your table count and typical bucket-per-partition setting? I can help you estimate the total tablet count against the FE heap guidance. References • best_practices/partitioning.md • table_design/data_distribution/Data_distribution.md • knowledge/usage/best-practice.md (StarRocks knowledge base) • faq/operation_maintenance_faq.md • best_practices/query_tuning/schema_tuning.md • faq/Deploy_faq.md
d
@Rocky thanks. Here’s our setup, so you can be concrete: • StarRocks 4.1.3, shared-data, Primary Key tables with persistent index on, replication 2 • 28 gold tables, each to be partitioned by
integration_id
(a VARCHAR UUID, already in every primary key), with
BUCKETS 1
per partition • About 700 integrations, so at most about 20k partitions (about 39k tablet replicas) across the cluster. Data is very skewed - the largest partition is about 17 GB, and most are a few MB. • Every query filters on
integration_id
. Nothing is time-partitioned today, so there’s no time pruning to lose (but potentially to gain?) • On prod, one integration’s scan went from 32.9s to 0.8s with a cold cache when testing this partition by integration ID approach Questions: 1. Many small tablets in shared-data. Is there a known cost at around 20k single-tablet partitions? For example, compaction scheduling across that many tablets, FE metadata, or tablet metadata files in S3. Is there a size below which a partition is wasteful enough that we should group small integrations together? 2. Write cost per partition. A load into a Primary Key table costs us about 45ms for each partition it touches. A one-minute batch touching 27 integrations went from 0.3s to 1.2s. Is that publish cost linear in partitions touched, and is there a config that reduces it? 3. Growing a large partition. Is
ALTER TABLE t PARTITIONS (p) DISTRIBUTED BY HASH (...) BUCKETS n
supported on a Primary Key table in shared-data for a partition of tens of GB? Does it run online while loads continue? Alternatively, does 4.1’s range distribution with automatic tablet splitting work on Primary Key tables? 4. Persistent index memory. With one tablet per partition, does
l0_max_mem_usage × tablet count
matter in practice at this scale, or does
update_memory_limit_percent
cap it well before then? 5. Migration. To move existing tables onto this layout we plan to copy into a new partitioned table and run
ALTER TABLE ... SWAP WITH
. Is that safe for Primary Key tables in shared-data, and does the swapped-in table keep its
SELECT ON ALL TABLES IN DATABASE
grants?
r
Answers below, with what's documented vs. what I can't confirm. One version note up front: you're on 4.1.3, and two of the costs you're already measuring have documented fixes in 4.1.6 — see Q1/Q2. 1. Cost of ~20k single-tablet partitions in shared-data What the docs do say: • Tablet metadata in object storage is the explicit shared-data cost. "The system needs to write a tablet metadata file for each tablet in the object storage, whose high latency can drastically increase total creation time" — and too many buckets is listed as a cause of excessive small files in object storage, degrading performance until compaction merges them. • Compaction in shared-data is scheduled by the FE per partition, and each compaction "generates a new version and follows the complete process of data writing, committing, and publishing the version, similar to data ingestions." So 20k partitions is 20k scheduling/scoring units, each with a full commit cycle when it fires. The docs give no per-partition cost figure for this — I can't quantify it. • Health checks: Max Compaction Score per partition should stay under
lake_compaction_score_selector_min_score
(10); >100 slows commit; >2000 rejects. Watch
SHOW PROC '/compactions'
and
information_schema.be_cloud_native_compactions
. There is no documented minimum partition size. The only size floors given are bucket-level: 1–5 GB per bucket in the shared-data bucketing formula, ~10 GB raw per tablet, 10–50 GB (max 100 GB) per tablet on 4.1 shared-data. Your few-MB partitions are ~3 orders of magnitude below that — but the docs never say "don't create small partitions", because for tenant partitioning the win is pruning, not bucket fill. So I can't give you a defensible "group them below X MB" threshold; that's a measurement, not a documented rule. A 4.1.3-specific cost you should know about: with
file_bundling
enabled, releases before 4.1.6 probe a per-tablet object that never exists on a partition's first publish — reported at 117 wasted 404 requests per 120 tablets over OSS. At 20k partitions each published for the first time, that's a direct, per-tablet, avoidable cost. Fixed in 4.1.6 (PR 78731), no backport to 4.0/3.5. If you do want to group the tail: the mechanism is a coarser partition key (e.g. a bucketing/grouping column) rather than
integration_id
— but then you lose the 32.9s→0.8s pruning win for those tenants, and you'd want the whales on their own partitions. That's the "whale tenant" pattern, and the docs warn the composite key raises partition count multiplicatively. 2. Publish cost per partition touched Consistent with linear-in-partitions, though the docs don't state a linearity claim: • Per-partition publish writes that partition's tablet metadata once per batch, not once per transaction (
lake_enable_batch_publish_version
, default on,
lake_batch_publish_max_version_num
= 10). So cost scales with partitions touched, and batching only helps when consecutive versions hit the same partition. • Your 27 integrations → 1.2s is ~45ms/partition, which fits one metadata write + txn-log apply per partition. Knobs: •
transaction_publish_version_worker_count
(BE, default 0 = CPU cores) — publish threads. •
lake_publish_version_max_threads
(FE, default 512). •
enable_sync_publish
(FE, default true) — setting
false
makes apply async, trading query stability/freshness for load latency. Per docs it "may affect query performance and stability" under frequent loads; I wouldn't start here. •
lake_batch_publish_max_version_num
— only helps consecutive versions on the same partitions. • Upgrade to 4.1.6: it also fixes a failing batch publish being retried on every daemon tick, which "doubled FE leader CPU and flooded the log with `Fail to publish partition`". With 20k partitions, failed-batch amplification is exactly your failure mode.
publish_version_interval_ms
(default 10) is the daemon tick, static, requires restart — it bounds the floor on publish latency, not the per-partition work. 3. Growing a large partition
ALTER TABLE t PARTITIONS (p) DISTRIBUTED BY HASH(...) BUCKETS n
— documented syntax from 3.2. Important limits: • Per-partition form works for bucket count only. The doc's NOTICE: changing the bucketing method "is applied to all partitions in the table and cannot be applied to specific partitions only". Per-partition,
HASH
columns must stay the same. • It's an async rewrite job (
SHOW ALTER TABLE
): the partition is rewritten into a temp partition and swapped in. • Not online in a safe sense. The docs'
enable_online_optimize_table
path (default false) is shared-nothing replicated storage only; shared-data always uses the offline job. And there's a known issue: a load concurrent with
ALTER ... DISTRIBUTED BY
can report FINISHED but lose rows (PR 77754, merged on branch-4.1, not yet released). Pause loads during the job. • PK support: the doc example is a Duplicate Key table and I found no explicit statement that this ALTER is or isn't supported on Primary Key tables in shared-data. I'd test it on one partition in staging rather than assume. Range distribution + auto split on PK tables — yes, documented and explicitly shown with a
PRIMARY KEY (tenant_id, ...)
example; FE
enable_range_distribution
(default false in 4.1, mutable). It's arguably a better fit for your skew: "Data from a small tenant can be located on a single BE/CN for optimal locality; data from a large tenant can be distributed across multiple BEs/CNs", tablets auto split and merge, and "no dependency on time-based partitioning". Two 4.1.3 caveats if you go that way: • Fixed in 4.1.2: oversized tablet never shrinks when auto-split fires on a range-distribution colocate table with an implicit sort key (a PRIMARY KEY table). You're past that. • Not fixed on 4.1.3 — fixed in 4.1.4: continuous batched loads on a shared-data
file_bundling
range-distribution table can wedge publish forever when a tablet reshard overlaps a publish (PR 76368). That's your workload shape. Upgrade before adopting range distribution. 4. Persistent index memory with one tablet per partition
l0_max_mem_usage
(default 100 MB) is a per-tablet memtable flush threshold, not a reservation — it does not multiply into a hard 700 × 100 MB tally. The aggregate is bounded by the
update
mem tracker, sized as
process_mem_limit × update_memory_limit_percent / 100
(default 60, mutable, clamped 0–100), and the PK index cache capacity equals that same limit. Idle indexes are evicted (LRU,
primary_key_index_memory_high_percent
75 /
primary_key_index_memory_urgent_percent
85 on 4.1;
update_cache_expire_sec
360s). So yes,
update_memory_limit_percent
caps it well before 700 × 100 MB matters. The real risk at your shape is different: with 700 mostly-cold tenants you get index cache churn — indexes evicted between writes and reloaded on the next publish (
get_pindex_worker_count
sizes that pool). Lowering
l0_max_mem_usage
reduces peak but the docs warn it "may increase I/O pressure". Watch
/mem_tracker?type=update&upper_level=3
and
update_mem_bytes
. No doc quantifies per-tablet index overhead — I can't give you a per-tablet byte figure. 5. Migration via SWAP WITH Documented: atomic exchange of two tables, requires ALTER privilege, and materialized views depending on the swapped tables go inactive with their Unique/FK constraints removed. It's the documented recipe for exactly this (create new table → load →
SWAP WITH
). Two things to know: • Same database only. SWAP WITH cannot cross databases (error: "Table X does not exist or is not OLAP/LAKE table").
• Grants: not documented. I could not find anything stating whether privileges follow. My inference (not doc-backed): StarRocks grants are keyed by
catalog.db.table
name, so a
SELECT ON ALL TABLES IN DATABASE
grant is a database-level grant and applies to whatever table currently holds the name — unaffected by the swap. A table-level grant on the old name would likewise stay on the name, which is what you want after the swap. Verify with
SHOW GRANTS
before and after on a test table, since I can't confirm it from the docs. Also worth checking before you migrate: whether any MVs are built over the 28 gold tables — those go inactive and must be rebuilt. My one concrete recommendation: get onto 4.1.6 before this rollout. Both the first-publish per-tablet 404 waste (Q1/Q2) and the publish-retry FE CPU amplification scale with partition count, and the 4.1.4 fix matters if you evaluate range distribution. Would it help to work through the "group the tail + solo partitions for whales" layout, or the range-distribution alternative as a direct comparison? References • knowledge/qa/bucket_number_and_small_tablets.md (StarRocks knowledge base) • faq/shared_data_faq.md • knowledge/known_issues/shared_data.md (StarRocks knowledge base) • best_practices/primarykey_table.md • administration/configuration/BE_parameters/stats_storage.md • knowledge/qa/lake_batch_publish_version.md (StarRocks knowledge base)