Repository navigation
Fix PREWHERE throwing when a predicate pushed into the scan by apply_string_filters_during_scan is read elsewhere - #128734
Conversation
…ere in PREWHERE
`StringValueFilter` requires all conditions of a column. With conditions from two
or more predicates on one column, a value that matches one predicate but not
another is replaced by an empty string during the scan, so the first predicate is
false for it although it is true on the original value. The row is rejected by
the conjunction anyway, but any other PREWHERE expression that consumes that
predicate's result observes the flipped value:
PREWHERE throwIf(NOT (s LIKE '%1%')) = 0 AND s LIKE '%1%' AND s LIKE '%2%'
throws `FUNCTION_THROW_IF_VALUE_IS_NON_ZERO` although every value contains '1'
(also via an alias, a shared `position` node, or a nested `and` read elsewhere),
in MergeTree and in Parquet, with default settings.
The existing guard only rejects nodes that read the column directly. For a column
whose conditions come from two or more readers, also require every node that
depends on the column (transitively, aliases transparent) to be part of the
conjunction: a top-level `and`, an extracted conjunct, or a reader. Otherwise the
filter is not applied to that column. With a single reader nothing can flip (a
value failing the filter fails that reader's own conditions), so such columns
keep the old behaviour, e.g. `position(s, 'x') > 0 AND position(s, 'x') < 100`.
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; 0 findings on this head).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261102-182900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261102-175800 |
|
cc @alexey-milovidov @CurtizJ, could you review this and add the |
|
Workflow [PR], commit [95c155f] Summary: ✅
AI ReviewSummaryThis PR prevents spurious exceptions in Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; functional CI should complete before merge. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
c1740f0
Backport #128734 to 26.10: Fix `PREWHERE` throwing when a predicate pushed into the scan by `apply_string_filters_during_scan` is read elsewhere
Related: #115848
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an exception (for example from
throwIf) in a query whosePREWHEREhad several substring conditions on oneStringcolumn, pushed into the scan byapply_string_filters_during_scan, when the result of one of them was also used elsewhere inPREWHERE.Description
On
26.10.2.103with default settings, this valid query throwsFUNCTION_THROW_IF_VALUE_IS_NON_ZEROalthough every value contains'1'(it returns 6878 withapply_string_filters_during_scan = 0); aParquetfile behaves the same:The scan filter of a column requires all its conditions, so a value that matches
'%1%'but not'%2%'is read as an empty string, ands LIKE '%1%'becomes false for it. The conjunction rejects that row anyway, butNOT (s LIKE '%1%')sees the flipped value. The existing guard inextractStringValueFilters(added in #115848 forPREWHERE throwIf(empty(s)) = 0 AND s LIKE ...) only rejects nodes that read the column directly.Now, for a column whose conditions come from two or more predicates, every node that depends on the column, also through other nodes, must be a part of the conjunction (a top-level
and, an extracted conjunct, or the predicate itself); otherwise the filter is not applied to that column. With a single predicate nothing can flip, so such columns keep the old behaviour (including every query ofstring_filters_during_scan.xml).The new test covers a shared predicate, an alias, a shared
position, a nestedandand aParquetfile. Each of the five fails on master with code 395 and passes with the fix. Three controls check that the filter is still applied. Thestring_filterstests pass.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128734]
Version info
26.11.1.1247-master(included in26.11and later)26.10.8.13