Repository navigation
Ignore WITH TOTALS of an IN subquery rewritten by rewrite_in_to_join - #124096
Conversation
…join` The regular `IN` set ignores the totals row of its subquery, but the `rewrite_in_to_join` rewrite into a correlated `EXISTS` kept the `TotalsHaving` step on the right side of the join built by the decorrelation. That leaked the totals row into the outer query and, when the outer query had `WITH TOTALS` as well, failed with the `LOGICAL_ERROR` `Totals having transform was already added to pipeline`. Found by the AST fuzzer in #118315: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118315&sha=eaa8e0b5913bdc2bf50caccbefee4e1589987921&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [86bdaae] Summary: ✅
AI ReviewSummaryThis PR makes the Final Verdict
LLVM Coverage ReportMeasured on commit 86bdaae.
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code |
…subquery rewritten by `rewrite_in_to_join` The regular `IN` ignores the totals of the whole subquery plan, so totals of queries nested in the join tree of the subquery have to be dropped too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e nested cases Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124096&sha=f45b63faee323184e9de7ace4a9b0347e66f2b2c&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 ( |
|
This is the lock holder that #123214 removed, but on the previous release: the stress phase runs the v26.9.11.2 server and tests, and 26.9 does not have #123214. In this job, the The fix is #123841. Its The stress phase stops doing this once a 26.9 release has #123214. I asked for |
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, 15 s compile time in total, 7 of them have a recent master baseline. |
With
rewrite_in_to_join = 1,x IN (subquery)is rewritten into a correlatedEXISTS. The regularINset ignores the totals row of a subquery withWITH TOTALS, but the rewrite kept the subquery'sTotalsHavingstep on the right side of the join built by the decorrelation. As a result:WITH TOTALS(wrong result), e.g.SELECT number FROM numbers(3) WHERE number IN (SELECT number FROM numbers(10) GROUP BY number WITH TOTALS);WITH TOTALSitself (e.g.... GROUP BY number WITH TOTALS HAVING number IN (SELECT ... WITH TOTALS)), it failed with theLOGICAL_ERRORexceptionTotals having transform was already added to pipeline.The fix drops
WITH TOTALSfrom the subquery when the rewrite applies, so the result matchesrewrite_in_to_join = 0.Found by the AST fuzzer in #118315: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118315&sha=eaa8e0b5913bdc2bf50caccbefee4e1589987921&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 (it also reproduces on master).
Related: #118315
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a wrong result (a leaked totals row) and a
LOGICAL_ERRORexception withrewrite_in_to_joinwhen the subquery ofINusesWITH TOTALS.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124096]
Version info
26.10.1.1793-master(included in26.10and later)