Repository navigation
Cherry pick #129184 to 26.10: Hash each node of an ActionsDAG once, fixing a planning hang in the hash table statistics key - #129668
Conversation
`ActionsDAG::Node::updateHash` mixed in the node's own fields and then
recursed into every child with no memo, so a node shared by two parents
was hashed once per path. A chain of `a_{i+1} = a_i + a_i` folded into
one DAG has O(depth) nodes but 2^depth paths, so hashing it was
exponential. `ActionsDAG::updateHash` was worse: it walked every edge
and called the recursive node hash at each visit.
Since `FilterStep::serialize` puts `getOutputIdentity` of the filter into
the hash table statistics key, planning a filter over 30+ nested
`x + x` aliases below a `JOIN` or a keyed `GROUP BY` never finished at
default settings, and the walk does not react to `KILL QUERY`.
Now a node's digest is SipHash128 of its own fields (`updateOwnHash`),
its number of children and its children's digests, computed once per
node by an iterative post-order walk with a per-call memo.
`Node::updateHash` mixes in the digest of the node, and
`ActionsDAG::updateHash` the number of outputs and the digest of each
output, sharing one memo. Both are O(nodes + edges).
Hash values change, equality does not: two subtrees hash equal iff their
own fields and ordered children are equal, whether a child is shared or
duplicated. Every consumer is an in-memory, per-process key (hash table
statistics, query condition cache, prewhere and top-K keys), and nothing
persists these hashes.
The `collect_hash_table_stats_during_joins = 0` pin in 05359 was the
workaround for this bug and is removed, so that test now covers the join
statistics key at depth 36. The new 05359 test covers the aggregation
statistics key, both SQL tests check in `system.text_log` that their
query reached the statistics cache, and the gtest covers
`ActionsDAG::updateHash`, which neither SQL test reaches, and that
different DAGs still hash differently.
Closes #126250
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…filter safe under concurrent runs The hash table statistics cache is process-wide, and every run of the test builds the same keys. A run that misses the cache and then finds an equal entry stored by a concurrent run in the meantime logs nothing under its own query_id: `HashJoin` updates the entry without a lookup and skips an equal one. In the flaky check 7 of 300 runs printed 0 for the oracle this way. Run the first query once more after it has finished, when its entry is cached, and count the log rows of both runs. Locally, 64 or 96 concurrent runs on a fresh server: 16 of 160 runs failed before, 0 of 288 after (14 of them logged nothing for the first query and were covered by the second). With `collect_hash_table_stats_during_joins = 0` the oracle still prints 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hash each node of an ActionsDAG once, fixing a planning hang in the hash table statistics key
|
The only conflict is in The child recursion at the end of the old body merges without a conflict marker and has to be removed by hand. On the 26.10 tree (debug, clang-22) the gtest passes and both I cannot push to |
|
@copilot resolve the merge conflicts in this pull request |
…rypick/26.10/129184 # Conflicts: # src/Interpreters/ActionsDAG.cpp Co-authored-by: murphy-4o <[email protected]>
|
|
🕵 Resolved the conflict and pushed merge commit |
003304c
into
backport/26.10/129184
…ild loop The conflict resolution of the cherry-pick (#129668) kept the old body of Node::updateHash as the new updateOwnHash, so: - updateOwnHash is defined in ActionsDAG.cpp but not declared in ActionsDAG.h (the declaration came with #126148, which is not on 26.10), and the build fails with "no member named 'updateOwnHash'". - updateOwnHash still ends with the recursion over the children, so each per-node digest re-hashes the whole subtree and the planning hang of #126250 stays. Add the declaration as on master and remove the loop. The tree now equals 26.10 + #129184 with only the #126148 updateOwnHash split, as on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ild loop The conflict resolution of the cherry-pick (#129668) kept the old body of Node::updateHash as the new updateOwnHash, so: - updateOwnHash is defined in ActionsDAG.cpp but not declared in ActionsDAG.h (the declaration came with #126148, which is not on 26.10), and the build fails with "no member named 'updateOwnHash'". - updateOwnHash still ends with the recursion over the children, so each per-node digest re-hashes the whole subtree and the planning hang of #126250 stays. Add the declaration as on master and remove the loop. The tree now equals 26.10 + #129184 with only the #126148 updateOwnHash split, as on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Original pull-request #129184
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job