fix: in PQ post processing, revert sort columns just before propagating down pipeline #5098
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.
Resolves #5097 by adding logic to revert sort columns within CTEs back to their original column identifiers in the context of the main pipeline. This is necessary for proper dereferencing of sort columns in the main pipeline.
The logic around "make sure that SELECT statements in CTEs include columns present in the SORT" was moved just prior to the new "revert sort columns" logic, in order to avoid bugs caused by the change in context of the sort columns. The previous logic tried to only apply this to columns that appear in the main pipeline; because it needed to move earlier in the sequence, this optimization needed to be removed. I believe this is not very significant, because the eventual SQL query planner will ignore extra columns defined in CTEs anyway. Also, this change did not affect any of the existing test case snapshots.