Repository navigation
Cherry pick #125828 to 26.3: Fix wrong results and NOT_FOUND_COLUMN_IN_BLOCK for a GROUP BY key inside an if chain or an ORDER BY tuple - #133202
Conversation
After `GROUP BY` only the keys and the aggregates exist, and the planner matches a subexpression to a key column by its action name. Two passes dissolved a key node into its arguments in such an expression, so the planner recomputed it from the arguments: those either do not exist after aggregation (`NOT_FOUND_COLUMN_IN_BLOCK`), or, under `group_by_use_nulls`, are not `NULL` on the subtotal rows where the key is `NULL` (wrong results). - `IfChainToMultiIfPass` spliced every nested 3-argument `if` of an else branch into one `multiIf`, also a key or its `group_by_use_nulls` copy. - `OrderByTupleEliminationPass` split every `ORDER BY tuple(...)`, also a tuple key. The analyzer expands top-level tuple keys, so such a key comes from `IfConstantConditionPass` folding `if(1, tuple(a), tuple(0))`. #122512 made `IfConstantConditionPass` also fold the `Nullable` copy of a constant-condition key, so the constant-condition forms of #125803 and #125804 regressed on master; a bare `if` key nested in a chain, and the `group_by_use_nulls = 0` forms, were already broken on 26.3 - 26.9. Both passes now ask `isGroupByKeyAfterAggregation`: the node is a copy on which `convertToNullable` was called (new `FunctionNode::isConvertedToNullable`, which also covers an `Array` copy whose type cannot become `Nullable`), or equal to a key by `compareGroupByKeys`. `IfChainToMultiIfPass` rewrites nodes while it walks the query, and with the identifier resolve cache a key node is shared with its references, so it classifies the query's `if` nodes by pointer when it enters the query, before rewriting it, and only when the setting is on and the query has an `if` key. The check for the copy's own rewrite now uses the same flag instead of comparing result types. Closes #125803 Closes #125804 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the collectGroupByKeyIfNodes and isGroupByKeyAfterAggregation comments to their invariants. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-and-order-by-tuple Fix wrong results and `NOT_FOUND_COLUMN_IN_BLOCK` for a `GROUP BY` key inside an `if` chain or an `ORDER BY` tuple
Resolve the 26.3 conflicts of the cherry-pick of #125828: - IfChainToMultiIfPass.cpp: keep the 26.3 "result type changed" return. The conflicting master hunk changes the `group_by_use_nulls` multiIf rewrite that #122512 added; 26.3 does not have #122512, so there is nothing to change there. All other hunks of #125828 apply as is. - OptimizeKeyExpressionsUtils.{h,cpp}: the files do not exist on 26.3 (master added them in the GROUP BY passes refactor). Add them with only the two helpers #125828 introduces, getGroupByKeys and isGroupByKeyAfterAggregation; compareGroupByKeys already exists in Analyzer/ValidationUtils.h on 26.3. - 05397 test: `SET enable_analyzer = 1` for the 26.3 old analyzer jobs, and drop `enable_identifier_resolve_cache = 1` from one statement (the setting does not exist on 26.3). The reference is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Unlike #132938, this one is worth having on 26.3: #125828 also fixes queries that fail on 26.3 without #122512. On 26.3.67.30, 8 of the 16 statements of I pushed a resolution to my fork:
Validation on a debug build of that tree: 05397 passes, 50/50 with randomized settings. The same tree without the two pass changes fails the same 8 statements as 26.3.67.30. The 37 related To apply it: If 26.3 should not get this fix, this PR can be closed. |
|
🕵 Applied the resolution from Checked before pushing: the diff against |
Original pull-request #125828
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job