Repository navigation
Fix NOT_FOUND_COLUMN_IN_BLOCK and wrong results when a GROUP BY key LIKE is a branch of an OR chain - #125894
Fix NOT_FOUND_COLUMN_IN_BLOCK and wrong results when a GROUP BY key LIKE is a branch of an OR chain#125894groeneai wants to merge 5 commits into
NOT_FOUND_COLUMN_IN_BLOCK and wrong results when a GROUP BY key LIKE is a branch of an OR chain#125894Conversation
`ConvertOrLikeChainPass` groups the `like`/`ilike`/`match` branches of an `or` by their left-hand side and merges a large enough group into `multiSearchAny` / `multiSearchAnyCaseInsensitiveUTF8` / `multiMatchAny`. It did so also for branches that are `GROUP BY` keys. After aggregation such a branch is read from the key column, so the merged call asks for the key's argument, which either does not exist (`NOT_FOUND_COLUMN_IN_BLOCK`) or is another key with a different rollup (wrong results under `ROLLUP`, `CUBE`, `GROUPING SETS`, and `group_by_use_nulls`). Each query level now collects, before any rewrite, the `like`/`ilike`/ `match` nodes equal to one of its keys (or to its `Nullable` copy under `group_by_use_nulls` with a modifier), by pointer, and the collection loop keeps such a branch as written. Pointers keep identifying a key after the pass rewrites a chain nested in the key's own argument in place. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… rewrite When every branch of an `or` is a pattern branch and a group is rewritten, the pass replaces the chain by `and(<clone of the rewritten or>, indexHint(<original branches>))`, and the visitor continues into the clone. A `GROUP BY` key nested in a left-hand side of that chain (for example `toString(<OR of key LIKEs>) LIKE ...`) is then reached only as a copy that is not in the per-query set of key nodes, so it was merged again and read `s` after aggregation (`NOT_FOUND_COLUMN_IN_BLOCK`, or a wrong result under `ROLLUP`). Right after the clone, a lockstep walk of the original and the copy (`clone()` keeps the children layout) adds the copy of every key node to the set; a chain nested deeper is mapped again at its own clone site. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The two new statements cover the ListNode flattening of the key collection and its Nullable shape under group_by_use_nulls. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review over 2 rounds: an independent model (engine: codex; 0 findings in both rounds) plus my own cold review (4 findings in round 0, none in round 1).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261014-220600 |
|
Workflow [PR], commit [97a6886] Summary: ✅
AI ReviewSummaryReviewed #125894 at Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261014-194500 |
|
cc @vdimir @yakov-olkhovskiy, could you review this and add the |
CI finish ledger - 3725870Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261015-230015 |
…roup-by-key Resolve the conflict with ClickHouse#129177 in ConvertOrLikeChainPass.cpp. Master now collects the rewrites in leaveImpl and applies them in applyRewrites after the whole visit, so: - the GROUP BY key set is still pushed in enterImpl of each QueryNode and popped in its leaveImpl, and the OR collection loop in leaveImpl keeps a key branch as written; - addCopiesOfNodes is dropped: it tracked the copies made by the indexHint wrap's node->clone(), which the visitor used to descend into. The clone now happens in applyRewrites, after the visit, so the visitor only ever sees the original nodes, which collectGroupByKeyPatternNodes records. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every chain of GROUP BY key branches in the test was exactly at the default rewrite threshold (4 substrings, 10 patterns), so a fix that kept only one key branch out of the rewrite left the others below the threshold and the test still passed. With both thresholds at 1, a key branch that is not kept out is rewritten and the statement fails. Measured with a build that keeps only the first GROUP BY key out: the old test caught it in 3 statements (the group_by_use_nulls ones), the new one in 15. The fix and master give the same output as before, so the reference is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes3 object files changed (+28.56 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
NOT_FOUND_COLUMN_IN_BLOCK, and wrong results withROLLUP, for anORofLIKE/ILIKEconditions that are themselvesGROUP BYkeys:optimize_or_like_chainno longer merges such a condition intomultiSearchAny/multiMatchAny, which needs the condition's argument after aggregation.Description
On 26.8.21.12,
SELECT (s LIKE '%1%') OR (s LIKE '%2%') OR (s LIKE '%3%') OR (s LIKE '%4%') AS e, count() FROM (SELECT toString(number % 6) AS s FROM numbers(12)) GROUP BY s LIKE '%1%', s LIKE '%2%', s LIKE '%3%', s LIKE '%4%'throwsNOT_FOUND_COLUMN_IN_BLOCK, and withGROUP BY ROLLUP(s, s LIKE '%1%')such anORreturns a wrong value on the rows wheres LIKE '%1%'is rolled up.The
s LIKE '%1%'in the projection is theGROUP BYkey and is read from the aggregation result.ConvertOrLikeChainPassruns later, groups it with the other branches bysand rewrites them intomultiSearchAny(s, [...]), which needssafter aggregation.Each query level now records, before any rewrite and by pointer, its
like/ilike/matchnodes equal to a key (or to itsNullablecopy undergroup_by_use_nulls), and the pass keeps those branches as written. Other branches are still merged; aLIKEthat is itself a key is no longer merged anywhere in its query level.The new test fails on master (15 statements
NOT_FOUND_COLUMN_IN_BLOCK, 6 wrong values) and passes 50/50 with randomized settings; 33 of the 34 tests that mentionoptimize_or_like_chainpass (the other needs thes3_cachestorage policy, absent in my local setup).EXPLAIN QUERY TREEof a 255-branchORwith 101 keys: 0.082 s before, 0.091 s after.Same class, with the same per-query collection of key nodes, in other passes: #125828, #125846. Not #124480 (one
ORalias reused by several clauses): this reproduces withenable_identifier_resolve_cache = 0.Workflow [PR]
Sync PR [sync-upstream/pr/125894]