Repository navigation
Keep a PREWHERE guard on a subcolumn ahead of a throwing condition on its sibling - #131054
Conversation
… its sibling Since #124553, `MergeTreeWhereOptimizer` groups conditions by the exact columns they read, so in `t.safe != '' AND toUInt64(t.val) > 50` the two conditions on subcolumns of one `Tuple` (or `JSON`, or bucketed `Map`) became separate groups and were reordered by size, and `toUInt64` ran on the rows the guard rejects. When a condition that may throw follows a condition over the same physical columns, group all conditions over these physical columns by them again, as before that PR. `tryBuildPrewhereSteps` still splits the group into exact-column steps and filters before the throwing one. Closes: #130086
|
Workflow [PR], commit [644fd94] Summary: ❌
AI ReviewSummaryRestores physical-column grouping when a potentially throwing Final Verdict✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
Backport #131054 to 26.8: Keep a PREWHERE guard on a subcolumn ahead of a throwing condition on its sibling
Backport #131054 to 26.10: Keep a PREWHERE guard on a subcolumn ahead of a throwing condition on its sibling
…umn ahead of a throwing condition on its sibling
…lumn ahead of a throwing condition on its sibling
…of a throwing condition on its sibling
… of a throwing condition on its sibling
|
@fm4v, the 26.8 backport of this PR (#131109) makes the server crash with SIGSEGV in CREATE TABLE t (a UInt64, b String) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO t VALUES (1, 'x');
EXPLAIN AST optimize = 1 SELECT a, b FROM t WHERE a = 1 SETTINGS query_plan_optimize_prewhere = 0;
On 26.8 a plain Cause: on 26.3, 26.8 and 26.9, Which do you prefer for 26.8, 26.9 and 26.3:
Also on 26.8, the backport does not fix |
Closes: #130086
Caused by: #124553
Related: #111954
Related: #129178
Since #124553,
MergeTreeWhereOptimizer::analyzeImplgroups conditions by the exact columns they read instead of by the physical column. InWHERE t.safe != '' AND toUInt64(t.val) > 50, the two conditions on subcolumns of oneTuple(alsoJSONpaths and keys of awith_bucketsMap) became separateConditions, were ordered by size, and the smallertoUInt64(t.val)ran first on the rows the guard rejects, throwingCANNOT_PARSE_TEXT. Before that PR they were one group in the written order, and themay_throwsplit from #111954 intryBuildPrewhereStepsfiltered before the conversion.This PR restores the grouping by physical columns only where it matters: when a condition that may throw (the same
isSuitableForShortCircuitArgumentsExecutionpredicate astryBuildPrewhereSteps) follows a condition over the same physical columns, all conditions over those physical columns are grouped by them. All other conditions keep the exact-column grouping, so the gain of #124553 for #124535 is kept.tryBuildPrewhereStepsstill builds exact-column steps from the group.This is a narrow fix of the regression only. A throwing condition on a different column than its guard (
a != '' AND toUInt64(b) > 50) can still be reordered ahead of it, as before #124553; that general case is addressed by #129178.The new test
05627_prewhere_guard_sibling_subcolumnfails on master (7b5f2bf328f9) for all three cases and passes on the parent of the merge of #124553 (c606f2c4c6f6). #124553 was backported to 26.10, 26.9, 26.8 and 26.3, so this needs the same backports.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a query like
WHERE t.safe != '' AND toUInt64(t.val) > 50throwing an exception such asCANNOT_PARSE_TEXTwhen the condition on one subcolumn of aTuple,JSONor bucketedMapcolumn guards a conversion on another subcolumn of the same column: moving the conditions toPREWHEREno longer evaluates the conversion before the guard.Workflow [PR]
Sync PR [sync-upstream/pr/131054]
Version info
26.11.1.2122-master(included in26.11and later)