Skip to content

docs: Explain the concepts behind EquivalenceProperties - #27250

Merged
alamb merged 14 commits into
apache:mainfrom
alamb:alamb/equivalence-properties-docs
Nov 11, 2026
Merged

alamb merged 14 commits into
apache:mainfrom
alamb:alamb/equivalence-properties-docs

Conversation

@alamb

@alamb alamb commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

While reviewing #27191 I was researching how EquivalenceProperties tracks orderings, equal expressions, constants and groupings, and wanted to write down what I learned so others do not have to repeat it.

The concepts were documented in pieces across several structs, with no single place that explained them together.

What changes are included in this PR?

Rustdoc only. The EquivalenceProperties doc in datafusion/physical-expr/src/equivalence/properties/mod.rs becomes the hub that the other struct docs link to. It keeps the existing examples and adds:

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 physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate labels Nov 8, 2026
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Nov 8, 2026

@mhilton mhilton 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.

LGTM thanks. I expect I will be referring to this in the future.

/// the partition requirement is `Hash(a)` and output partitioning is
/// `Hash(b)`, then DataFusion avoids repartitioning the data as the existing
/// partitioning satisfies the requirement.
/// In this case, columns `a` and `b` always have the same value. DataFusion

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 spent quite a while working through these examples and text, trying to make it easer to understand (aka this is not LLM spew)

@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 this write-up! Two of the examples describe derivations the code doesn't do today (the CAST example and the Groupings row), details and suggestions inline. The set-monotonic NULL note is non-blocking.

/// raise its value or leave it unchanged (see [`SetMonotonicity`]).
///
/// Given those observations, `m` never decreases as `ts` increases, so the
/// output sorting is described by both `[ts ASC]` and `[m ASC NULLS LAST]`.

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.

While checking this section I found that the NULL placement it describes gives wrong results on main when x has NULLs: MAX(x) OVER (ORDER BY ts) is NULL until the first non-NULL value, so the output is ASC NULLS FIRST, not NULLS LAST, yet the sort is removed and the NULL row comes out first. MIN and the shrinking-frame case are wrong the same way. Fine to keep this PR as is; could the text say "when x has no NULLs" until the code is fixed?

Repro (sort removed, NULL row returned first)
set datafusion.execution.target_partitions = 1;
CREATE TABLE t(ts INT, x INT) AS VALUES (1, NULL), (2, 3), (3, 1), (4, 5);
SELECT ts, m FROM (SELECT ts, MAX(x) OVER (ORDER BY ts) AS m FROM (SELECT * FROM t ORDER BY ts))
ORDER BY m ASC NULLS LAST;
-- actual: (1,NULL),(2,3),(3,3),(4,5); expected: NULL row last

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.

This is a great find -- I filed a ticket to track:

Fine to keep this PR as is; could the text say "when x has no NULLs" until the code is fixed?

I think that would be sort of confusing as it would be without context. Instead I removed the description of nulls first / nulls last.

alamb and others added 10 commits November 9, 2026 10:08
Co-authored-by: Jay Zhan <jayzhan211@gmail.com>
Co-authored-by: Jay Zhan <jayzhan211@gmail.com>
…datafusion into alamb/equivalence-properties-docs
Co-authored-by: Jay Zhan <jayzhan211@gmail.com>
…datafusion into alamb/equivalence-properties-docs
Co-authored-by: Jay Zhan <jayzhan211@gmail.com>
@alamb
alamb requested a review from jayzhan211 November 9, 2026 15:48
@alamb
alamb dismissed jayzhan211’s stale review November 9, 2026 15:49

Changes addressed. Waiting on next review

@alamb

alamb commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @jayzhan211 for the review. I think I have addressed all your comments

/// [`Self::ordering_satisfy_requirement`] checks whether a requirement is
/// satisfied by an ordering, and is quite complex.
///
/// # Discovering orderings

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After working on #27113 I wonder if functional deps shouldn't be added to EquivalenceProperties, at the end they influence properties like ordering too. WDYT?

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.

It sounds like a great thing to add as a follow up PR. Thank you

@jayzhan211

Copy link
Copy Markdown
Contributor

Thanks @alamb !

@alamb
alamb added this pull request to the merge queue Nov 11, 2026
Merged via the queue into apache:main with commit 6dc8d41 Nov 11, 2026
45 checks passed
@alamb
alamb deleted the alamb/equivalence-properties-docs branch November 11, 2026 01:28
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 physical-plan Changes to the physical-plan crate v57.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants