fix: Maintain sort information when swapping projection into MemorySourceConfig #17185
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.
This makes pushing projections down into MemorySourceConfig tables not discard their sort ordering.
This lacks tests. Please tell me where I should put tests. I will add them. (Should they be in memory.rs? In physical planning code?) (As far as I can tell, we can't create a sort order on in-memory tables via SQL, thus SQL test case files wouldn't be the place.) I think a test will want to specifically check that optimizing a plan requiring a sort order consistent with a sorted MemorySourceConfig (and a simple projection on top) produces the correct plan without unnecessary sort nodes, no sanity check failures, or whatnot.
Which issue does this PR close?
Rationale for this change
Without this change, it is impossible in some circumstances for query plans to take advantage of known sort order for in-memory tables. I forget how this bug manifests, but it might be that discarding sort order breaks optimization sanity checks in some way too, or produces an incorrect plan.
Are these changes tested?
Not in the DataFusion repository. (See comment above asking for advice on where to add tests.)
Are there any user-facing changes?
No? (Or yes? I mean, this fixes planning behavior for some users.)