Skip to content

fix: in PQ post processing, revert sort columns just before propagating down pipeline#5098

Merged
kgutwin merged 4 commits intoPRQL:mainfrom
bioteam:kg/sort-pushdown-fix
Jan 23, 2025
Merged

fix: in PQ post processing, revert sort columns just before propagating down pipeline#5098
kgutwin merged 4 commits intoPRQL:mainfrom
bioteam:kg/sort-pushdown-fix

Conversation

@kgutwin
Copy link
Copy Markdown
Collaborator

@kgutwin kgutwin commented Jan 19, 2025

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.

@kgutwin kgutwin requested a review from aljazerzen January 19, 2025 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Input containing rename, sort, filter, join results in output ORDER BY referring to wrong table

1 participant