Repository navigation
Fix NOT_FOUND_COLUMN_IN_BLOCK when an extract alias with several trailing .*$ is reused by GROUP BY - #124482
Conversation
With `enable_identifier_resolve_cache` the GROUP BY key and its ORDER BY, HAVING and WHERE references are one shared node, while the projection keeps its own copy. `RegexpFunctionRewritePass` enters the shared node once per reference, and `handleExtract` removed one trailing `.*$` per visit, so for a pattern such as `(1).*$.*$` the shared node ended with `(1)` and the projection with `(1).*$`. The GROUP BY key then no longer matched the projection and the query failed with NOT_FOUND_COLUMN_IN_BLOCK. Remove all trailing unescaped `.*$` in a single visit, so a repeated visit is a no-op. The escape check is evaluated for each tail; `disablesDotAll` and `endsInsideQuotedLiteral` are evaluated once on the original pattern, which is equivalent because removing a trailing `.*$` adds or removes no `(` and no `\E`. This is the per-pass shape of ClickHouse#108553; cloning at the cache was refused there. Related: ClickHouse#122404 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The result-only arms also pass for an implementation that leaves a pattern with several trailing `.*$` unrewritten. Two `EXPLAIN QUERY TREE` lines, in the style of 03538, now show that `(abc).*$.*$` becomes `(abc)` and that an escaped tail in `(abc)\.*$.*$` is kept. 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; 2 rounds, 1 finding) plus my own cold review (0 findings in both rounds).
Round 2 (delta Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261007-202100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261007-195800 |
|
Workflow [PR], commit [eb119c9] Summary: ✅
AI ReviewSummaryThis PR makes Final Verdict
LLVM Coverage ReportMeasured on commit eb119c9.
Changed lines: Changed C/C++ lines covered: 7/7 (100.00%) · Uncovered code |
0957684
Backport #124482 to 26.10: Fix `NOT_FOUND_COLUMN_IN_BLOCK` when an `extract` alias with several trailing `.*$` is reused by `GROUP BY`
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
NOT_FOUND_COLUMN_IN_BLOCKfor a query whoseSELECTalias is anextractcall with a pattern ending in more than one.*$and is reused byGROUP BYtogether withORDER BY,HAVING,WHEREor another alias, for exampleSELECT extract(s, '(1).*$.*$') AS r FROM t GROUP BY r ORDER BY r.Description
On 26.8.18.2,
SELECT extract(s, '(1).*$.*$') AS r FROM t GROUP BY r ORDER BY rfails withCode: 10 NOT_FOUND_COLUMN_IN_BLOCKon default settings. It returns the expected rows withenable_identifier_resolve_cache = 0oroptimize_rewrite_regexp_functions = 0.With
enable_identifier_resolve_cache(default since 26.6) theGROUP BYkey and itsORDER BY/HAVING/WHEREreferences are one shared node, while the projection keeps its own copy.RegexpFunctionRewritePassvisits the shared node once per reference, andhandleExtractremoved one trailing.*$per visit, so the shared node ended with'(1)'and the projection with'(1).*$', and the key names no longer match (EXPLAIN QUERY TREEshows it).The change removes every trailing unescaped
.*$in one visit, so a second visit changes nothing (the per-pass shape of #108553). Each removed tail is the transformation the pass already applies; the escape check runs for each tail, and the(?-s)and\Qguards are unchanged.The new test covers
GROUP BY+ORDER BY,WHERE, three tails withHAVING, an alias of an alias, aNullablecolumn and an escaped second tail (the first five fail on master), and pins the rewritten patterns withEXPLAIN QUERY TREE. 50 randomized runs pass, and 158 existingextract/ regexp-rewrite tests give the same result on master and with the fix.Related: #122404. The same class in other passes is handled separately (#123925, #122512, #122726).
Workflow [PR]
Sync PR [sync-upstream/pr/124482]
Version info
26.11.1.2451-master(included in26.11and later)26.10.5.41