Repository navigation
Conversation
… them Since ClickHouse#111954 the PREWHERE read step splitter gives a condition its own step, and makes the step before it filter, whenever any of its functions reports `isSuitableForShortCircuitArgumentsExecution` (or `isExpensive`), so that a condition that may throw never runs on the rows a preceding guard rejects. `startsWith`/`endsWith` and `like`/`ilike` answer `true` there unconditionally ("worth evaluating lazily"), although they cannot throw on a `String` with a constant needle. `m['a1'] = 'v1' AND startsWith(m['a2'], 'p-')` was therefore split into two steps, with a forced filter copying the whole `Map` between them (ClickHouse#131717: 1.17x on a synthetic query, 2.03x on the original one). A flagged condition now shares the step when the sound oracle `IFunctionBase::canThrow` proves that no function in it can throw and none is expensive (`prewhereConditionCannotThrow`, used by `tryBuildPrewhereSteps` and by the guard grouping of `MergeTreeWhereOptimizer`). The whole condition is checked, not only its root, so a cheap throwing descendant still keeps the split. The functions of the reported condition describe `canThrowIfKnown`: - `startsWith`/`endsWith` family: cannot throw when both arguments are `String`/`FixedString` (the `Array` form converts to a common type). - `[not]like`/`[not]ilike`: cannot throw for a `String`/`FixedString` haystack and a constant pattern that builds; an `Enum` haystack, an ESCAPE argument, a non-constant or an invalid pattern may throw. - `arrayElement` on a `Map`: a lookup returns the default value for a missing key; it may throw only for `Enum` keys (a string key is converted to them). This only removes splits. `NOT startsWith(...)` keeps its split, `not` does not describe `canThrowIfKnown`. Closes ClickHouse#131717 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…throw A condition on a sibling subcolumn that cannot throw is no longer grouped with its guard by physical column, so cost order moves it first, while a throwing one keeps the written order. EXPLAIN with pretty = 0, because the pretty form does not print the conjuncts in the order of the steps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fold the Enum haystack note into the LIKE canThrowIfKnown comment, keep master's getArgumentTypesWithConstInfo doc without the stale ExpressionActions line, and shorten the fillRequiredColumns pointer and the prewhereConditionCannotThrow doc to one line each. 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 in round 1, 0 in round 2) plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261116-190333 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261116-182900 |
|
Workflow [PR], commit [3d81527] Summary: ✅
AI ReviewSummaryRestores shared Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units59 translation units recompiled, 386 s compile time in total, 59 of them have a recent master baseline. |
7c15c7e
`05343_lazy_materialization_for_join_padded_side_can_throw` used a comparison of decimals of different scales as the one that can throw. It cannot: an overflowing rescale is compared exactly, or ignored without `decimal_check_overflow`, so it is now computed above the LIMIT. A `UInt64` compared with a `Decimal64` is the comparison that can throw (`DECIMAL_OVERFLOW` for a value above `Int64`), so it takes its place. The read-ahead case of `04631_prewhere_subcolumn_guard_read_steps` needs conditions that may throw. `NOT startsWith(...)` no longer is one once both `not` and `startsWith` (ClickHouse#132112) are known not to throw, so on a merge with master the four conditions shared one PREWHERE step. `toUInt64` of a `String` can throw and passes every row there. The comments of `04893_comparison_can_throw_replicated_columns` said the same about decimals of different scales. With those classified as safe, no case there could catch a comparison wrongly classified as safe: the values of its unreferenced row are valid. A `Decimal128` compared with a `UInt128` that does not fit into `Int128` is added. Lazy replication needs values wider than 8 bytes and a row joined more than once, and the hash join is pinned so that the unreferenced row reaches it; with the unsigned case of `comparisonCanThrow` widened to equal sizes, the case fails 30 of 30 randomized runs with `DECIMAL_OVERFLOW`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Apply the upstream effective exception check in `appendGroups` for both initial grouping and alias refinement. Preserve constant argument metadata, dynamic-filter separation, cache attribution, and shared reads. Related: ClickHouse#129445 Related: ClickHouse#132112
…rewhere-attribution Conflict in MergeTreeSplitPrewhereIntoReadSteps.cpp with ClickHouse#132112: keep its `may_throw` / `prewhereConditionCannotThrow` split rule, drop only `is_first_unattributed` added by ClickHouse#122380. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #131717
Related: #111954
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A PREWHERE condition with
startsWithorendsWithover aString, or withLIKEorILIKEwith a constant pattern, such asm['a'] = 'x' AND startsWith(m['b'], 'p-'), is evaluated in the same read step as the condition before it again, instead of in a separate step that filters the whole block in between. Such queries over aMapcolumn are about 1.2 times faster.Description
This fixes a regression from my own #111954. To keep a condition that may throw from running on rows a preceding guard rejects, the PREWHERE step splitter gives it its own step and makes the step before it filter. It decides "may throw" with
isSuitableForShortCircuitArgumentsExecution, whichstartsWithandLIKEanswertruefor because they are worth evaluating lazily, although they cannot throw on aStringwith a constant needle. Som1['a1'] = 'v1' AND startsWith(m1['a2'], 'p-')got two steps with a filter of the wholeMapbetween them.A flagged condition now joins the previous step when
IFunctionBase::canThrowproves that none of its functions can throw and none is expensive. The whole condition is checked, not only its root, sostartsWith(lower(m['k']), 'x')keeps its split. The guard grouping ofMergeTreeWhereOptimizeruses the same check. Three functions describecanThrowIfKnownnow: thestartsWith/endsWithfamily onString/FixedString;[not]like/[not]ilikeon aStringhaystack with a constant pattern that builds (anEnumhaystack,ESCAPE, a non-constant or invalid pattern still count as throwing);arrayElementon aMapwithoutEnumkeys. AMaplookup compared with a constant andstartsWiththerefore also qualify for the existing reorderings of non-throwing conditions.NOT startsWith(...)keeps its split,notdescribes nothing.match,positionand the rest ofFunctionsStringSearchare not described: the reported queries need only these.Validation: the issue's query goes from 3 steps to 2 with the same result.
04631gets cases in both directions: the new grouped ones fail on master, and 8 mutations of the change each turn it red. RelWithDebInfo, 4M rows of the issue's table, n=20:startsWith568 -> 463 ms,LIKE575 -> 468 ms, the comparison form unchanged (n=30: 454.5 vs 454.5 ms).Workflow [PR]
Sync PR [sync-upstream/pr/132112]
Version info
26.11.1.2664-master(included in26.11and later)