Mark all input columns in LIMIT BY as required output #5407
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
Prevent removal of any columns in LimitBy by marking all input columns as required output.
Category
Bug Fix
Short description
The query analyzer only marks the actual arguments of LIMIT BY as required
output for the LimitBy step in the pipeline. This is fine, unless the query is
distributed, in which case the first stage might remove a column that is used
at the second stage (e.g. for ORDER BY) but is not part of the final select.
Detailed description
If
t
is a distributed table with columnsa
andb
, then a query like this will not work:That happens because on the remote side the pipeline looks like this:
Here the
LimitBy
is the last step in the pipeline, sofinalize()
feels it can remove all columns that are not part of the final projection and not required in LimitBy.But then, on the initial node the pipeline looks like this:
Fix that by marking all inputs of LimitBy as required outputs.