Repository navigation
Carry the packed String join key settings in the serialized query plan - #130750
harikrishnan94 merged 2 commits into
Conversation
A node that runs a deserialized query plan (`serialize_query_plan`, distributed plans) built its `JoinSettings` from the plan settings with `enable_packed_string_keys_in_hash_join = false` and `min_rows_for_packed_string_keys_in_hash_join = 0` hard coded, because ClickHouse#128972 left both out of `QueryPlanSerializationSettings`. Its hash joins on a single `String` key therefore compared the keys exactly whatever the initiator set: correct results, but no speedup on the remote nodes. Add both to `QueryPlanSerializationSettings` with defaults `false` and `0`, write them in `JoinSettings::updatePlanSettings` and read them in the constructor that takes plan settings. A plan without the names keeps exact keys. No version gate, as asked in ClickHouse#128972 (comment): plan settings are written by name with flags, and `BaseSettings::read` skips an unknown name that is not declared `IMPORTANT`, so an older reader logs `Unknown settings` and keeps its exact keys. Measured with a server built from the previous master as the only shard (and as the initiator): the join succeeds and the old node records no packed keys. The row estimate is not serialized, and `Join` tables and `joinGet` stay exact. The gtest round trips both values and reads plan settings without the names back as `false` and `0`. The stateless test runs a `cluster()` join with `serialize_query_plan = 1` and checks the remote queries' packed-key profile events; on the previous master they are 0 with the setting on, while the same join over the query text path counts them, so the test checks the plan path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261111-102300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261111-095300 |
|
Workflow [PR], commit [77fcd03] Summary: ✅
AI ReviewSummaryReviewed #130750 at Missing context / blind spots
Final Verdict✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units10 translation units recompiled, 42 s compile time in total, 10 of them have a recent master baseline. |
harikrishnan94
left a comment
There was a problem hiding this comment.
@groeneai not sure about a plan that's already optimized.
…ed plan The tasks of a distributed query plan (`make_distributed_plan`) receive a join that the initiator already optimized, and they do not optimize the join order again, so the right side has no row estimate there. `min_rows_for_packed_string_keys_in_hash_join` then never applied: a join whose right side is estimated below the minimum compared its keys exactly on a single node but used packed keys in the tasks. The initiator has the estimate, so it takes the decision: a `JoinStepLogical` whose right side is estimated below the minimum sets a fourth bit in the byte that already carries the join decisions taken from a row estimate, and the receiver then compares the keys exactly. A reader that does not know the bit ignores it and never reads the packed key settings either, so it keeps exact keys. The row estimate itself is still not serialized. Plan-based parallel replicas are not affected: they ship the logical plan before join order optimization, the replicas optimize it themselves and have the estimate (measured: a 1000-row right side stays exact on the replicas with the default minimum, and is packed with a minimum of 0). Measured with `distributed_plan_execute_locally = 1`, a 1000-row right side and the default minimum: the tasks inserted 500 inline + 500 hashed keys before, 0 after; a single-node run inserts 0 either way. A 200000-row right side is still packed in the tasks (100000 + 100000), as on a single node. The stateless test gets the two cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #128972
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Follow-up to #128972, as asked in #128972 (comment). A node that runs a deserialized query plan (
serialize_query_plan, distributed plans) built itsJoinSettingswithenable_packed_string_keys_in_hash_join = falseandmin_rows_for_packed_string_keys_in_hash_join = 0hard coded, so its hash joins on a singleStringkey compared the keys exactly. Results were correct; the remote joins only missed the speedup.Both settings are now plan settings with defaults
falseand0, written byJoinSettings::updatePlanSettingsand read by the constructor that takes plan settings. There is no version gate: a reader skips a plan setting name it does not know unless it isIMPORTANT(BaseSettings::read), so a node without this change compares exactly.Jointables andjoinGetstay exact.The tasks of a distributed query plan (
make_distributed_plan) get an already optimized join without a row estimate, somin_rows_for_packed_string_keys_in_hash_joinnever applied there. The initiator applies it and sends the decision in the join's flags byte (the row estimate itself is not serialized), so a small right side stays exact in the tasks, as on a single node. Plan-based parallel replicas ship the join already optimized too, so the same decision covers them.#128972 is only on master, hence
Not for changelog.Validation: the gtest
JoinPackedStringKeysPlanSetting.RoundTripfails on master and passes with the change. In05620_join_packed_string_keys_serialized_plan, the remote queries of thecluster()join withserialize_query_plan = 1give1 0 0before the change and1 1 1after, and the tasks of themake_distributed_planjoin with a 1000-row right side give1 1 1without the decision and1 0 0with it; 40 randomized runs pass. Mixed versions work in both directions, with exact keys on the old node.Workflow [PR]
Sync PR [sync-upstream/pr/130750]
Version info
26.11.1.1992-master(included in26.11and later)