Skip to content

docs: Explain SortKeyWalk with worked examples - #27266

Merged
alamb merged 6 commits into
apache:mainfrom
alamb:alamb/sortkeywalk-docs
Nov 12, 2026
Merged

alamb merged 6 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.

@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

@jayzhan211 jayzhan211 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@alamb thanks for writing this up. I ran each worked example through ordering_satisfy and all of them match the code. The inline suggestions are optional doc fixes.

Optional cleanup in walk.rs around line 542: splitting the paragraph left a short line (/// Pinning kleavesx``), so the paragraph could be rewrapped.

@github-actions github-actions Bot removed the documentation Improvements or additions to documentation label Nov 12, 2026
@alamb
alamb added this pull request to the merge queue Nov 12, 2026
Merged via the queue into apache:main with commit 2bdd6f4 Nov 12, 2026
44 checks passed
@alamb
alamb deleted the alamb/sortkeywalk-docs branch November 12, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates v57.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants