Repository navigation
Cherry pick #130143 to 26.10: Fix LOGICAL_ERROR on INSERT into a table whose projection has a subquery in its SELECT list or GROUP BY - #132990
Conversation
… name A subquery is named by the hash of its AST (`__subquery_<hash>`). The projection metadata is named from the stored projection query, analysed in place, while `calculateByQuery` (since #118375) renames the columns of the Analyzer pipeline to names built by converting the query tree back to AST. That conversion does not reproduce the subquery (a subquery without `FROM` gets `FROM system.one`, other shapes hash differently too), so a projection column like `b IN (SELECT ...)` was calculated as `in(b, __subquery_X)` while the metadata describes `in(b, __subquery_Y)`, and every INSERT, MATERIALIZE PROJECTION or merge rebuilding a projection with `WHERE` or an aggregate projection failed with LOGICAL_ERROR (found by the AST fuzzer on the `05515_global_subquery_projection_where` seed). On 26.9 the same INSERT silently stored 0 in such a column. The unresolved names of the functions are now taken from the AST each query tree node was built from, which is the very AST the metadata was named from; `toAST` stays the fallback for a node without one (the `tuple` wrapper added around a tuple `GROUP BY` key). The names are keyed by node, so a resolution that replaces the `IN` node loses them: `rewrite_in_to_join` does, so `calculateByQuery` pins it to 0 next to the other settings it pins. Creating the table under `rewrite_in_to_join = 1` gives the same metadata names (they come from `InterpreterSelectQuery`, which does not read it), so `fillProjectionDescriptionByQuery` needs no pin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ubquery-names Fix `LOGICAL_ERROR` on `INSERT` into a table whose projection has a subquery in its `SELECT` list or `GROUP BY`
The only conflict is in `ProjectionDescription::calculateByQuery`: master also has the `enable_parallel_replicas` line of #129863 and the positional arguments change of #126185 there, neither of which is on 26.10. Keep the 26.10 code and add only the `rewrite_in_to_join` line of #130143. Also take the three lines of #129006 that materialize constant columns of the calculated projection block. On 26.10 a projection column such as `exists(SELECT ...)` is calculated as a `ColumnConst`, and once #130143 gives it the right name, writing the projection part fails with `Bad cast from type DB::ColumnConst to DB::ColumnVector<char8_t>` (the `t_subquery_normal` case of 05569). The rest of #129006 is not needed on 26.10: its trigger, `optimize_constant_columns_after_filter`, does not exist there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The only conflict is in The resolution also takes the three lines of #129006 that materialize constant columns of the calculated projection block ( On a 26.10 debug build, I cannot push to |
|
🕵 Applied the resolution from the comment above: I reviewed it before pushing. The diff against |
Original pull-request #130143
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