Skip to content

docs: Explain SortKeyWalk with worked examples - #27266

Open
alamb wants to merge 3 commits into
apache:mainfrom
alamb:alamb/sortkeywalk-docs
Open

alamb wants to merge 3 commits into
apache:mainfrom
alamb:alamb/sortkeywalk-docs

Conversation

@alamb

@alamb alamb commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

While reviewing #27191 I was very confused about how SortKeyWalk (added in #26853) decides whether known orderings satisfy a sort requirement, and wanted to write down what I learned so others do not have to repeat it.

Specifically the existing docs stated the rules but did not define the terms clearly, and had no example a reader could trace step by step.

What changes are included in this PR?

Rustdoc only, in datafusion/physical-expr/src/equivalence/properties/walk.rs:

What is the testing strategy for this PR?

CI

Are there any user-facing changes?

No.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added the physical-expr Changes to the physical-expr crates label Nov 9, 2026
@alamb alamb added the documentation Improvements or additions to documentation label Nov 9, 2026
/// rows: they are sorted by `x`; among rows with equal `x`, sorted by `y`;
/// among rows with equal `x` and `y`, sorted by `z`.
///
/// ## Pinning and Fixed Expressions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once I went through this logic, I found the algorithm quite clever and the refactoring well done. Thank you for working on this @jayzhan211

@alamb
alamb requested a review from jayzhan211 November 11, 2026 14:48
@alamb

alamb commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

I am sorry to ask you for another review @jayzhan211 but I think this is related to your attempt to try and clean up SortKeyWalk, etc

cc @ozankabak and @berkaysynnada @buraksenn who may also have worked on this code and be available for a review

@alamb alamb added the documentation Improvements or additions to documentation label Nov 11, 2026
/// For each ordering (the normal orderings of `props`, then `implied`),
/// the index of its head. Empty until the first pin, so that a walk with
/// nothing pinned allocates nothing; until then every head is at index 0.
/// The position of the head of each ordering. Empty until the first pin.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the "heads" notion quite confusing at first, but I think this captures it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant