Skip to content

Commit 4cab6da

Browse files
antiguruclaude
andcommitted
catalog: key mz_cluster_replica_frontiers_ind on (object_id, replica_id)
The `(object_id, replica_id)` join in `mz_hydration_statuses` was building its own full-relation arrangement of `mz_cluster_replica_frontiers` because the index was keyed on `object_id` only. That arrangement grows very large under replica churn (observed ~47 GB on a production mz_catalog_server). Widening the index key lets the join reuse the index; the remaining `object_id`-only consumers all filter to `write_frontier IS NULL`, so their arrangements stay small. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3b10a79 commit 4cab6da

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎src/catalog/src/builtin/mz_catalog.rs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,14 +2465,22 @@ pub static MZ_CLUSTER_REPLICA_FRONTIERS: LazyLock<BuiltinSource> =
24652465
ontology: None,
24662466
});
24672467

2468-
pub static MZ_CLUSTER_REPLICA_FRONTIERS_IND: LazyLock<BuiltinIndex> =
2469-
LazyLock::new(|| BuiltinIndex {
2468+
// Keyed on `(object_id, replica_id)` rather than just `object_id` so that the
2469+
// `(object_id, replica_id)` join in `mz_hydration_statuses` reuses this index
2470+
// instead of building its own full-relation arrangement of
2471+
// `mz_cluster_replica_frontiers` (which grows very large under replica churn;
2472+
// see CLU-112). The remaining `object_id`-only consumers all filter to
2473+
// `write_frontier IS NULL`, so their own arrangements stay small. Do not narrow
2474+
// this key back to `object_id` without re-checking that join.
2475+
pub static MZ_CLUSTER_REPLICA_FRONTIERS_IND: LazyLock<BuiltinIndex> = LazyLock::new(|| {
2476+
BuiltinIndex {
24702477
name: "mz_cluster_replica_frontiers_ind",
24712478
schema: MZ_CATALOG_SCHEMA,
24722479
oid: oid::INDEX_MZ_CLUSTER_REPLICA_FRONTIERS_IND_OID,
2473-
sql: "IN CLUSTER mz_catalog_server ON mz_catalog.mz_cluster_replica_frontiers (object_id)",
2480+
sql: "IN CLUSTER mz_catalog_server ON mz_catalog.mz_cluster_replica_frontiers (object_id, replica_id)",
24742481
is_retained_metrics_object: false,
2475-
});
2482+
}
2483+
});
24762484

24772485
pub static MZ_DEFAULT_PRIVILEGES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
24782486
name: "mz_default_privileges",

‎test/sqllogictest/mz_catalog_server_index_accounting.slt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mz_arrangement_records_raw_s2_primary_idx CREATE␠INDEX␠"mz_arrangement_reco
3939
mz_arrangement_sharing_raw_s2_primary_idx CREATE␠INDEX␠"mz_arrangement_sharing_raw_s2_primary_idx"␠IN␠CLUSTER␠[s2]␠ON␠"mz_introspection"."mz_arrangement_sharing_raw"␠("operator_id",␠"worker_id")
4040
mz_cluster_deployment_lineage_ind CREATE␠INDEX␠"mz_cluster_deployment_lineage_ind"␠IN␠CLUSTER␠[s2]␠ON␠[s747␠AS␠"mz_internal"."mz_cluster_deployment_lineage"]␠("cluster_id")
4141
mz_cluster_prometheus_metrics_s2_primary_idx CREATE␠INDEX␠"mz_cluster_prometheus_metrics_s2_primary_idx"␠IN␠CLUSTER␠[s2]␠ON␠"mz_introspection"."mz_cluster_prometheus_metrics"␠("process_id",␠"metric_name",␠"labels")
42-
mz_cluster_replica_frontiers_ind CREATE␠INDEX␠"mz_cluster_replica_frontiers_ind"␠IN␠CLUSTER␠[s2]␠ON␠[s741␠AS␠"mz_catalog"."mz_cluster_replica_frontiers"]␠("object_id")
42+
mz_cluster_replica_frontiers_ind CREATE␠INDEX␠"mz_cluster_replica_frontiers_ind"␠IN␠CLUSTER␠[s2]␠ON␠[s741␠AS␠"mz_catalog"."mz_cluster_replica_frontiers"]␠("object_id",␠"replica_id")
4343
mz_cluster_replica_history_ind CREATE␠INDEX␠"mz_cluster_replica_history_ind"␠IN␠CLUSTER␠[s2]␠ON␠[s599␠AS␠"mz_internal"."mz_cluster_replica_history"]␠("dropped_at")
4444
mz_cluster_replica_metrics_history_ind CREATE␠INDEX␠"mz_cluster_replica_metrics_history_ind"␠IN␠CLUSTER␠[s2]␠ON␠[s509␠AS␠"mz_internal"."mz_cluster_replica_metrics_history"]␠("replica_id")
4545
mz_cluster_replica_metrics_ind CREATE␠INDEX␠"mz_cluster_replica_metrics_ind"␠IN␠CLUSTER␠[s2]␠ON␠[s510␠AS␠"mz_internal"."mz_cluster_replica_metrics"]␠("replica_id")

‎test/testdrive/indexes.td‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ mz_arrangement_batcher_capacity_raw_s2_primary_idx mz_arrangement_batch
296296
mz_arrangement_batcher_records_raw_s2_primary_idx mz_arrangement_batcher_records_raw mz_catalog_server {operator_id,worker_id} ""
297297
mz_arrangement_batcher_size_raw_s2_primary_idx mz_arrangement_batcher_size_raw mz_catalog_server {operator_id,worker_id} ""
298298
mz_cluster_deployment_lineage_ind mz_cluster_deployment_lineage mz_catalog_server {cluster_id} ""
299-
mz_cluster_replica_frontiers_ind mz_cluster_replica_frontiers mz_catalog_server {object_id} ""
299+
mz_cluster_replica_frontiers_ind mz_cluster_replica_frontiers mz_catalog_server {object_id,replica_id} ""
300300
mz_cluster_replica_history_ind mz_cluster_replica_history mz_catalog_server {dropped_at} ""
301301
mz_cluster_replica_name_history_ind mz_cluster_replica_name_history mz_catalog_server {id} ""
302302
mz_cluster_replica_metrics_ind mz_cluster_replica_metrics mz_catalog_server {replica_id} ""

0 commit comments

Comments
 (0)