Skip to content

docs: Improve optimizer rule reference by consolidating into rustdocs - #26899

Merged
alamb merged 12 commits into
apache:mainfrom
alamb:alamb/inline-optimizer-rule-reference
Nov 7, 2026
Merged

alamb merged 12 commits into
apache:mainfrom
alamb:alamb/inline-optimizer-rule-reference

Conversation

@alamb

@alamb alamb commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

datafusion/core/src/optimizer_rule_reference.md documents the optimizer and rules

It was added in this PR from @kumarUjjawal

While it is spliced into the datafusion crate docs via include_str!, keeping the refernece a separate markdown file means

  1. it lives far from the rule lists it describes, so can drifts (for example, the eliminate_join summary no longer matched the rule's behavior)
  2. needed a dedicated test to keep the order in sync.

What changes are included in this PR?

This PR moves the content next to the code so the rule list and its documentation

What is the testing strategy for this PR?

CI

Are there any user-facing changes?

No API changes. The rule reference moves from the datafusion crate root docs to the three constructor docs.

…own file

Move the built-in analyzer, logical optimizer, and physical optimizer rule
tables from `optimizer_rule_reference.md` into the doc comments on
`Analyzer::new`, `Optimizer::new`, and `PhysicalOptimizer::new`, next to the
rule lists they describe. Link to those from the `datafusion` crate docs.

Add struct-level docs to `UnionsToFilter` and `EliminateCrossJoin`, which had
none, and remove the markdown file along with the test module that parsed it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
alamb and others added 5 commits November 4, 2026 13:00
…r-rule-reference

# Conflicts:
#	datafusion/core/src/optimizer_rule_reference.md
Drop the `order` and `phase` columns (row position gives the order, and the
phase now sits in the summary), tighten the preambles, and shorten each
rule summary.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Define the `Analyzer`, `Optimizer` and `PhysicalOptimizer` intra-doc links
used by the crate overview, tidy the wording, and point the `Analyzer` and
`Optimizer` struct docs at `new` where the built-in rules are listed.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alamb alamb added the documentation Improvements or additions to documentation label Nov 4, 2026
@alamb
alamb marked this pull request as ready for review November 4, 2026 19:41
//!
//! 1. The [`LogicalPlan`] is checked and rewritten to enforce
//! semantic rules, such as type coercion, by [`AnalyzerRule`]s
//! 1. The [`LogicalPlan`] is checked and rewritten by the [`Analyzer`], using

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 tried to make this introduction clear and provide links to the structures with more detailed documentation for each feature

@@ -1,72 +0,0 @@
// SPDX-License-Identifier: Apache-2.0

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 test existed to ensure the order matches the documentation, but I think now that the list of rules is in the same file as the actual lists it will be much easier (and obvious) that we need to update the docs when we update the actual list

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.

if this isn't adequate, we can perhaps make individual unit tests in each module that verify the order is correct, rather than something that does it across multiple modules

@alamb alamb changed the title docs: move optimizer rule reference into rustdoc and remove the markdown file docs: Improve optimizer rule reference by consolidating into rustdocs Nov 4, 2026
@alamb

alamb commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@jayzhan211 and @2010YOUY01 and @zhuqi-lucas I wonder what you think about this PR?

@zhuqi-lucas zhuqi-lucas 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.

Checked the three tables against Analyzer::new(), Optimizer::new() and PhysicalOptimizer::new() on this branch: the order and the EXPLAIN names all match (including LimitAggregation for TopKAggregation and FilterPushdown(Post)). Looks good.

/// Applies rules in order for up to `datafusion.optimizer.max_passes` passes,
/// stopping early if the plan repeats.
///
/// # Built-in Optimizer Rules

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.

The deleted optimizer_rule_reference.rs was what failed CI when a rule was added or reordered without updating the docs. A small test could keep that guard here, e.g. include_str!("optimizer.rs"), parse the rows under this heading and compare them with Optimizer::new().rules names (same for the analyzer and physical optimizer). Fine as a follow-up.

/// The rules are applied in the following order. Note: the list may change
/// between releases.
///
/// | rule | summary |

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.

Nit: unlike the other two tables, this one has no "name in EXPLAIN plan" column (resolve_grouping_function, type_coercion).

@alamb

alamb commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @zhuqi-lucas -- I have made the changes you suggested

@github-actions github-actions Bot added the common Related to common crate label Nov 7, 2026
@alamb
alamb enabled auto-merge November 7, 2026 12:10
@alamb
alamb added this pull request to the merge queue Nov 7, 2026
Merged via the queue into apache:main with commit 306dbf5 Nov 7, 2026
44 of 45 checks passed
@alamb
alamb deleted the alamb/inline-optimizer-rule-reference branch November 7, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate core Core DataFusion crate documentation Improvements or additions to documentation optimizer Optimizer rules v57.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants