Repository navigation
Fix wrong results of query_plan_convert_join_to_in with the query condition cache - #126072
Conversation
With `query_plan_convert_join_to_in = 1`, `buildInConversion` adds the right side's `FutureSetFromSubquery` to the left read's filter as a constant column with the default `is_deterministic_constant = true`. Every query condition cache writer and reader trusts that flag, while the exact-mode DAG hash covers only the fixed name "set column" and not the set's contents. So two queries with the same static conjuncts but different sets (or the same query after the right table changed) share one cache entry, and the second query is served the first one's granule mask: rows are silently dropped. ClickHouse#90692 moved set determinism from `FutureSetFromSubquery::isDeterministic` onto the DAG node flag and set it to false for the analyzer's `IN (subquery|table)` sets only; this optimization was not updated, so the regression is present since 25.12. Mark the converted set non-deterministic, like the analyzer does, so these filters are neither written to nor read from the cache. 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; 1 finding), plus my own cold review of the diff (0 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261015-163000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261015-155400 |
|
Workflow [PR], commit [2da8f4f] Summary: ✅
AI ReviewSummaryThe PR fixes missing rows when Final VerdictStatus: ✅ Approve |
|
cc @KochetovNicolai @nickitat, could you review this and add the |
64ec938
Backport #126072 to 26.10: Fix wrong results of `query_plan_convert_join_to_in` with the query condition cache
…oin_to_in` with the query condition cache
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed missing rows in a
JOINconverted toINbyquery_plan_convert_join_to_in = 1when the query condition cache is enabled: the cache could serve the filter result of one query to another query with a different right side, or to the same query after the right table changed.Description
Related: #90692 (regression source).
On 26.3.42.3, 26.8.18.2 and 26.9.16.11, with
query_plan_convert_join_to_in = 1,SELECT count() FROM l ANY INNER JOIN r ON l.k = r.k WHERE r.c = 2 AND l.v >= 5returns 0 instead of 1 when the same query withr.c = 1ran before (use_query_condition_cache = 0returns 1).buildInConversionadds the right side's set to the left read's filter as a constant column namedset columnwith the defaultis_deterministic_constant = true. The query condition cache trusts that flag, and its key does not cover the set's contents, so every convertedINwith the same remaining conjuncts shares one cache entry. #90692 moved set determinism fromFutureSetFromSubqueryonto this node flag and set it to false only for the analyzer'sIN (subquery)sets; this optimization was not updated.The fix marks the converted set non-deterministic, as the analyzer does. The conversion and its PREWHERE placement are unchanged; these filters are just no longer cached, like analyzer
IN (subquery)filters.Validation: the new test returns
1 0 0 0instead of1 1 1 2on the unfixed build (20/20 randomized runs) and passes 50/50 randomized runs with the fix; the existing query condition cache andconvert_join_to_intests pass.Workflow [PR]
Sync PR [sync-upstream/pr/126072]
Version info
26.11.1.33-master(included in26.11and later)