Skip to content

Fix query condition cache hash collision for CTE folded constants - #96172

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-query-condition-cache-cte-constant-hash
Feb 7, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-query-condition-cache-cte-constant-hash

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 6, 2026 •

Copy link
Copy Markdown
Member

ActionsDAG::Node::updateHash did not hash actual constant values — only column->getName() which returns the type family name (e.g. Const(Nullable(UInt16))) regardless of the value. When constants are folded from CTE expressions, the result_name retains the expression-based name rather than the value, so two queries with different constant values but the same expression structure produced identical hashes, causing query condition cache collisions and incorrect results.

Fix by also calling column->updateHashWithValue for ColumnConst nodes so the actual constant value is included in the hash.

Closes #96060

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC) or LOGICAL_ERROR

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix query condition cache hash collision for CTE folded constants, which could lead to a wrong query result. Closes #96060.

Version info

  • Merged into: 26.2.1.364
  • Backported to: 26.1.3.22, 25.8.22.5

`ActionsDAG::Node::updateHash` did not hash actual constant values —
only `column->getName()` which returns the type family name (e.g.
`Const(Nullable(UInt16))`) regardless of the value. When constants are
folded from CTE expressions, the `result_name` retains the
expression-based name rather than the value, so two queries with
different constant values but the same expression structure produced
identical hashes, causing query condition cache collisions and
incorrect results.

Fix by also calling `column->updateHashWithValue` for `ColumnConst`
nodes so the actual constant value is included in the hash.

Closes #96060

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6010c57]

Summary: ❌

job_name test_name status info comment
Stress test (amd_ubsan) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6) FAIL cidb, issue
AST fuzzer (amd_tsan) failure
Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-41a5) FAIL cidb

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Feb 6, 2026
…r `ColumnFunction`

`ColumnFunction` previously threw `NOT_IMPLEMENTED` for all hash methods.
When `ActionsDAG::Node::updateHash` calls `column->updateHashWithValue`
on a `ColumnConst` wrapping a `ColumnFunction` (e.g. lambda expressions
in prewhere), this caused an exception.

Implement proper hashing by including the function name and delegating
to the captured columns.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Feb 7, 2026
@alexey-milovidov
alexey-milovidov merged commit 0cf36ce into master Feb 7, 2026
127 of 129 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-query-condition-cache-cte-constant-hash branch February 7, 2026 03:50
robot-clickhouse added a commit that referenced this pull request Feb 7, 2026
robot-clickhouse added a commit that referenced this pull request Feb 7, 2026
robot-clickhouse added a commit that referenced this pull request Feb 7, 2026
robot-clickhouse added a commit that referenced this pull request Feb 7, 2026
robot-clickhouse added a commit that referenced this pull request Feb 7, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 7, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Feb 7, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Feb 7, 2026
clickhouse-gh Bot added a commit that referenced this pull request Feb 7, 2026
Backport #96172 to 26.1: Fix query condition cache hash collision for CTE folded constants
@rschu1ze rschu1ze added the post-approved Approved, but after the PR is merged. label Mar 18, 2026
clickhouse-gh Bot added a commit that referenced this pull request Mar 29, 2026
Backport #96172 to 25.8: Fix query condition cache hash collision for CTE folded constants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-approved Approved, but after the PR is merged. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken use_query_condition_cache=true behavior

5 participants