Skip to content

Commit 1a002bc

Browse files
authored
Minor: Improve documentation about optimizer (#9967)
* Minor: Improve documentation about optimizer * fix unused commit
1 parent f7b4ed0 commit 1a002bc

27 files changed

Lines changed: 79 additions & 48 deletions

datafusion/optimizer/src/analyzer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
//! [`Analyzer`] and [`AnalyzerRule`]
1819
use std::sync::Arc;
1920

2021
use log::debug;

datafusion/optimizer/src/decorrelate.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
//! [`PullUpCorrelatedExpr`] converts correlated subqueries to `Joins`
19+
1820
use std::collections::{BTreeSet, HashMap};
1921
use std::ops::Deref;
2022

@@ -31,8 +33,11 @@ use datafusion_expr::utils::{conjunction, find_join_exprs, split_conjunction};
3133
use datafusion_expr::{expr, EmptyRelation, Expr, LogicalPlan, LogicalPlanBuilder};
3234
use datafusion_physical_expr::execution_props::ExecutionProps;
3335

34-
/// This struct rewrite the sub query plan by pull up the correlated expressions(contains outer reference columns) from the inner subquery's 'Filter'.
35-
/// It adds the inner reference columns to the 'Projection' or 'Aggregate' of the subquery if they are missing, so that they can be evaluated by the parent operator as the join condition.
36+
/// This struct rewrite the sub query plan by pull up the correlated
37+
/// expressions(contains outer reference columns) from the inner subquery's
38+
/// 'Filter'. It adds the inner reference columns to the 'Projection' or
39+
/// 'Aggregate' of the subquery if they are missing, so that they can be
40+
/// evaluated by the parent operator as the join condition.
3641
pub struct PullUpCorrelatedExpr {
3742
pub join_filters: Vec<Expr>,
3843
// mapping from the plan to its holding correlated columns
@@ -54,7 +59,9 @@ pub struct PullUpCorrelatedExpr {
5459
/// This is used to handle the Count bug
5560
pub const UN_MATCHED_ROW_INDICATOR: &str = "__always_true";
5661

57-
/// Mapping from expr display name to its evaluation result on empty record batch (for example: 'count(*)' is 'ScalarValue(0)', 'count(*) + 2' is 'ScalarValue(2)')
62+
/// Mapping from expr display name to its evaluation result on empty record
63+
/// batch (for example: 'count(*)' is 'ScalarValue(0)', 'count(*) + 2' is
64+
/// 'ScalarValue(2)')
5865
pub type ExprResultMap = HashMap<String, Expr>;
5966

6067
impl TreeNodeRewriter for PullUpCorrelatedExpr {

datafusion/optimizer/src/decorrelate_predicate_subquery.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
//! [`DecorrelatePredicateSubquery`] converts `IN`/`EXISTS` subquery predicates to `SEMI`/`ANTI` joins
1819
use std::collections::BTreeSet;
1920
use std::ops::Deref;
2021
use std::sync::Arc;

datafusion/optimizer/src/eliminate_cross_join.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Optimizer rule to eliminate cross join to inner join if join predicates are available in filters.
18+
//! [`EliminateCrossJoin`] converts `CROSS JOIN` to `INNER JOIN` if join predicates are available.
1919
use std::collections::HashSet;
2020
use std::sync::Arc;
2121

datafusion/optimizer/src/eliminate_duplicated_expr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
//! [`EliminateDuplicatedExpr`] Removes redundant expressions
19+
1820
use crate::optimizer::ApplyOrder;
1921
use crate::{OptimizerConfig, OptimizerRule};
2022
use datafusion_common::Result;

datafusion/optimizer/src/eliminate_filter.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Optimizer rule to replace `where false or null` on a plan with an empty relation.
19-
//! This saves time in planning and executing the query.
20-
//! Note that this rule should be applied after simplify expressions optimizer rule.
18+
//! [`EliminateFilter`] replaces `where false` or `where null` with an empty relation.
19+
2120
use crate::optimizer::ApplyOrder;
2221
use datafusion_common::{Result, ScalarValue};
2322
use datafusion_expr::{
@@ -27,7 +26,11 @@ use datafusion_expr::{
2726

2827
use crate::{OptimizerConfig, OptimizerRule};
2928

30-
/// Optimization rule that eliminate the scalar value (true/false/null) filter with an [LogicalPlan::EmptyRelation]
29+
/// Optimization rule that eliminate the scalar value (true/false/null) filter
30+
/// with an [LogicalPlan::EmptyRelation]
31+
///
32+
/// This saves time in planning and executing the query.
33+
/// Note that this rule should be applied after simplify expressions optimizer rule.
3134
#[derive(Default)]
3235
pub struct EliminateFilter;
3336

datafusion/optimizer/src/eliminate_join.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
//! [`EliminateJoin`] rewrites `INNER JOIN` with `true`/`null`
1819
use crate::optimizer::ApplyOrder;
1920
use crate::{OptimizerConfig, OptimizerRule};
2021
use datafusion_common::{Result, ScalarValue};
@@ -24,7 +25,7 @@ use datafusion_expr::{
2425
CrossJoin, Expr,
2526
};
2627

27-
/// Eliminates joins when inner join condition is false.
28+
/// Eliminates joins when join condition is false.
2829
/// Replaces joins when inner join condition is true with a cross join.
2930
#[derive(Default)]
3031
pub struct EliminateJoin;

datafusion/optimizer/src/eliminate_limit.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Optimizer rule to replace `LIMIT 0` or
19-
//! `LIMIT whose ancestor LIMIT's skip is greater than or equal to current's fetch`
20-
//! on a plan with an empty relation.
21-
//! This rule also removes OFFSET 0 from the [LogicalPlan]
22-
//! This saves time in planning and executing the query.
18+
//! [`EliminateLimit`] eliminates `LIMIT` when possible
2319
use crate::optimizer::ApplyOrder;
2420
use crate::{OptimizerConfig, OptimizerRule};
2521
use datafusion_common::Result;
2622
use datafusion_expr::logical_plan::{EmptyRelation, LogicalPlan};
2723

28-
/// Optimization rule that eliminate LIMIT 0 or useless LIMIT(skip:0, fetch:None).
29-
/// It can cooperate with `propagate_empty_relation` and `limit_push_down`.
24+
/// Optimizer rule to replace `LIMIT 0` or `LIMIT` whose ancestor LIMIT's skip is
25+
/// greater than or equal to current's fetch
26+
///
27+
/// It can cooperate with `propagate_empty_relation` and `limit_push_down`. on a
28+
/// plan with an empty relation.
29+
///
30+
/// This rule also removes OFFSET 0 from the [LogicalPlan]
3031
#[derive(Default)]
3132
pub struct EliminateLimit;
3233

datafusion/optimizer/src/eliminate_nested_union.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Optimizer rule to replace nested unions to single union.
18+
//! [`EliminateNestedUnion`]: flattens nested `Union` to a single `Union`
1919
use crate::optimizer::ApplyOrder;
2020
use crate::{OptimizerConfig, OptimizerRule};
2121
use datafusion_common::Result;

datafusion/optimizer/src/eliminate_one_union.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
//! Optimizer rule to eliminate one union.
18+
//! [`EliminateOneUnion`] eliminates single element `Union`
1919
use crate::{OptimizerConfig, OptimizerRule};
2020
use datafusion_common::Result;
2121
use datafusion_expr::logical_plan::{LogicalPlan, Union};

0 commit comments

Comments
 (0)