Skip to content

Cherry pick #129184 to 26.10: Hash each node of an ActionsDAG once, fixing a planning hang in the hash table statistics key - #129668

Merged
robot-clickhouse-ci-1 merged 4 commits into
backport/26.10/129184from
cherrypick/26.10/129184
Nov 6, 2026
Merged

robot-clickhouse-ci-1 merged 4 commits into
backport/26.10/129184from
cherrypick/26.10/129184

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 3 commits November 4, 2026 05:39
`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
@robot-ch-test-poll robot-ch-test-poll added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 6, 2026
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

The only conflict is in Node::updateHash (ActionsDAG.cpp): #129184's per-node digest calls Node::updateOwnHash, which #126148 split out on master, and #126148 is not on 26.10. I ported only that split: the 26.10 body of Node::updateHash becomes updateOwnHash, declared in ActionsDAG.h; the rest of #126148 is left out. Against backport/26.10/129184 the merge changes ActionsDAG.cpp, ActionsDAG.h and #129184's tests.

The child recursion at the end of the old body merges without a conflict marker and has to be removed by hand. git merge -X ours keeps it inside updateOwnHash (and does not compile without the declaration); with it kept, the new gtest does not finish in 120 s.

On the 26.10 tree (debug, clang-22) the gtest passes and both 05359_* tests pass with random settings (76 runs; 24 more died in setup on session_timezone = 'zoneinfo/UTC', which my local tz data lacks). The official 26.10.3.7 times out on both tests, and the two queries keep running after KILL QUERY.

I cannot push to cherrypick/26.10/129184. The merge is on my fork and its first parent is this PR's head b51445ef42f9, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git resolve-26.10-cherrypick-129184
git push origin FETCH_HEAD:cherrypick/26.10/129184

@murphy-4o

Copy link
Copy Markdown
Member

@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]>
@cla-assistant

cla-assistant Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ groeneai
✅ murphy-4o
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

🕵 Resolved the conflict and pushed merge commit 93b16979c.

Copilot AI requested a review from murphy-4o November 6, 2026 05:15
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 merged commit 003304c into backport/26.10/129184 Nov 6, 2026
1 of 2 checks passed
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 deleted the cherrypick/26.10/129184 branch November 6, 2026 05:19
murphy-4o pushed a commit that referenced this pull request Nov 6, 2026
…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]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants