Skip to content

Keep the identity of a set in the cache key of an expression - #132104

Merged
nickitat merged 1 commit into
masterfrom
autopr-cache-key-set-identity
Nov 17, 2026
Merged

nickitat merged 1 commit into
masterfrom
autopr-cache-key-set-identity

Conversation

@nickitat

@nickitat nickitat commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Related: #125687
Related: #116781
Related: #126148

The statistics of automatic parallel replicas are keyed by the plan, and the key of an expression is written by ActionsDAG::serialize with for_cache_key. That leaves out the names the plan build chose, and isConstantValueInCacheKey leaves out the value of a set. The __set_<hash> name was the only thing telling two sets apart. Without it, v IN (1, 2, 3) and v IN (5, 6, 7) computed in an expression got the same key, so one query was decided from statistics collected for the other.

The fix writes the set into the cache key again. serializeConstant writes only the set's hash, which is the same thing Node::updateHash keeps for this reason. A filter is not affected, because its predicate is keyed through getOutputIdentity.

The new test 05813_autopr_cache_key_set_identity runs IN (1, 2, 3), then IN (5, 6, 7), then IN (1, 2, 3) again. It checks that the second query reports AutoParallelReplicasNoStatistics instead of reusing the first query's statistics. The test fails on current master (10 of 10 runs on a master CI binary) and passes with the fix.

Split out of #125687.


Workflow [PR]
Sync PR [sync-upstream/pr/132104]

Version info

  • Merged into: 26.11.1.2591-master (included in 26.11 and later)
  • Backported to: 26.10.6.10

The cache key of an expression is written by `ActionsDAG::serialize` with
`for_cache_key`, which leaves out the names the plan build chose, and
`isConstantValueInCacheKey` leaves out the value of a set. The set was told apart
only by its `__set_<hash>` name, so `v IN (1, 2, 3)` and `v IN (5, 6, 7)`
computed in an expression got one key, and automatic parallel replicas decided
one query from the statistics collected for the other. Write the set:
`serializeConstant` writes only its hash, as `Node::updateHash` keeps it for the
same reason. A filter was not affected, because its predicate is keyed through
`getOutputIdentity`.

Split out of #125687.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nickitat nickitat added the ci-force-all Do not skip any jobs when running label Nov 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6379111]

Summary: ✅


AI Review

Summary

PR #132104, reviewed at 63791115e053b1db4b483f8ddf4f62fcdbfec379, preserves set identity in expression cache keys so automatic parallel replicas distinguish expressions using different sets. No actionable findings. The focused regression test checks both separation of different sets and reuse of the same set; CI reports show five successful runs each on amd_debug and arm_binary.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 16, 2026
nickitat added a commit that referenced this pull request Nov 16, 2026
The fix and its test `05396_autopr_cache_key_set_identity` are now in
#132104, which fixes it on master
independently of this branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review approves this commit, see the AI Review comment.

@clickhouse-gh clickhouse-gh Bot added the comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). label Nov 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 63791115e with master e4cde4748 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 22 s compile time in total, 7 of them have a recent master baseline.

Job report

@nickitat
nickitat marked this pull request as ready for review November 16, 2026 19:40
@nickitat nickitat removed the ci-force-all Do not skip any jobs when running label Nov 17, 2026
@nickitat
nickitat added this pull request to the merge queue Nov 17, 2026
Merged via the queue into master with commit eabcd07 Nov 17, 2026
621 of 764 checks passed
@nickitat
nickitat deleted the autopr-cache-key-set-identity branch November 17, 2026 16:16
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 17, 2026
nickitat added a commit that referenced this pull request Nov 17, 2026
Cherry pick #132104 to 26.10: Keep the identity of a set in the cache key of an expression
robot-clickhouse added a commit that referenced this pull request Nov 17, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #132104 to 26.10: Keep the identity of a set in the cache key of an expression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants