diff --git a/datafusion/core/src/physical_planner.rs b/datafusion/core/src/physical_planner.rs index 1650d187805c..78c70606bf68 100644 --- a/datafusion/core/src/physical_planner.rs +++ b/datafusion/core/src/physical_planner.rs @@ -2558,7 +2558,7 @@ mod tests { unimplemented!("NoOp"); } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } } diff --git a/datafusion/core/tests/user_defined/user_defined_plan.rs b/datafusion/core/tests/user_defined/user_defined_plan.rs index baf14d4c06f2..2b45d0ed600b 100644 --- a/datafusion/core/tests/user_defined/user_defined_plan.rs +++ b/datafusion/core/tests/user_defined/user_defined_plan.rs @@ -444,7 +444,7 @@ impl UserDefinedLogicalNodeCore for TopKPlanNode { }) } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } } diff --git a/datafusion/expr/src/logical_plan/extension.rs b/datafusion/expr/src/logical_plan/extension.rs index d0b05cfd590a..19d4cb3db9ce 100644 --- a/datafusion/expr/src/logical_plan/extension.rs +++ b/datafusion/expr/src/logical_plan/extension.rs @@ -196,9 +196,15 @@ pub trait UserDefinedLogicalNode: fmt::Debug + Send + Sync { fn dyn_eq(&self, other: &dyn UserDefinedLogicalNode) -> bool; fn dyn_ord(&self, other: &dyn UserDefinedLogicalNode) -> Option; - /// Indicates to the optimizer if its safe to push a limit down past - /// this extension node - fn allows_limit_to_inputs(&self) -> bool; + /// Returns `true` if a limit can be safely pushed down through this + /// `UserDefinedLogicalNode` node. + /// + /// If this method returns `true`, and the query plan contains a limit at + /// the output of this node, DataFusion will push the limit to the input + /// of this node. + fn supports_limit_pushdown(&self) -> bool { + false + } } impl Hash for dyn UserDefinedLogicalNode { @@ -300,9 +306,15 @@ pub trait UserDefinedLogicalNodeCore: None } - /// Indicates to the optimizer if its safe to push a limit down past - /// this extension node - fn allows_limit_to_inputs(&self) -> bool; + /// Returns `true` if a limit can be safely pushed down through this + /// `UserDefinedLogicalNode` node. + /// + /// If this method returns `true`, and the query plan contains a limit at + /// the output of this node, DataFusion will push the limit to the input + /// of this node. + fn supports_limit_pushdown(&self) -> bool { + false // Disallow limit push-down by default + } } /// Automatically derive UserDefinedLogicalNode to `UserDefinedLogicalNode` @@ -370,8 +382,8 @@ impl UserDefinedLogicalNode for T { .and_then(|other| self.partial_cmp(other)) } - fn allows_limit_to_inputs(&self) -> bool { - self.allows_limit_to_inputs() + fn supports_limit_pushdown(&self) -> bool { + self.supports_limit_pushdown() } } diff --git a/datafusion/optimizer/src/analyzer/subquery.rs b/datafusion/optimizer/src/analyzer/subquery.rs index 68af00e01f25..aabc549de583 100644 --- a/datafusion/optimizer/src/analyzer/subquery.rs +++ b/datafusion/optimizer/src/analyzer/subquery.rs @@ -386,7 +386,7 @@ mod test { }) } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } } diff --git a/datafusion/optimizer/src/optimize_projections/mod.rs b/datafusion/optimizer/src/optimize_projections/mod.rs index 36d205eb219d..b5d581f3919f 100644 --- a/datafusion/optimizer/src/optimize_projections/mod.rs +++ b/datafusion/optimizer/src/optimize_projections/mod.rs @@ -896,7 +896,7 @@ mod tests { Some(vec![output_columns.to_vec()]) } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } } @@ -996,7 +996,7 @@ mod tests { Some(vec![left_reqs, right_reqs]) } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } } diff --git a/datafusion/optimizer/src/push_down_filter.rs b/datafusion/optimizer/src/push_down_filter.rs index 0ecf48028519..6e2cc0cbdbcb 100644 --- a/datafusion/optimizer/src/push_down_filter.rs +++ b/datafusion/optimizer/src/push_down_filter.rs @@ -1500,7 +1500,7 @@ mod tests { }) } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } } diff --git a/datafusion/optimizer/src/push_down_limit.rs b/datafusion/optimizer/src/push_down_limit.rs index cc322d8d1c0d..8b5e483001b3 100644 --- a/datafusion/optimizer/src/push_down_limit.rs +++ b/datafusion/optimizer/src/push_down_limit.rs @@ -154,13 +154,7 @@ impl OptimizerRule for PushDownLimit { Ok(Transformed::yes(LogicalPlan::SubqueryAlias(subquery_alias))) } LogicalPlan::Extension(extension_plan) - if !extension_plan.node.allows_limit_to_inputs() => - { - // If push down is not allowed, keep the original limit - original_limit(skip, fetch, LogicalPlan::Extension(extension_plan)) - } - LogicalPlan::Extension(extension_plan) - if extension_plan.node.allows_limit_to_inputs() => + if extension_plan.node.supports_limit_pushdown() => { let new_children = extension_plan .node @@ -353,7 +347,7 @@ mod test { }) } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { true // Allow limit push-down } } @@ -406,7 +400,7 @@ mod test { }) } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } } diff --git a/datafusion/optimizer/src/test/user_defined.rs b/datafusion/optimizer/src/test/user_defined.rs index fb51ae042a82..a39f90b5da5d 100644 --- a/datafusion/optimizer/src/test/user_defined.rs +++ b/datafusion/optimizer/src/test/user_defined.rs @@ -77,7 +77,7 @@ impl UserDefinedLogicalNodeCore for TestUserDefinedPlanNode { }) } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } } diff --git a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs index e53775c16336..cd789e06dc3b 100644 --- a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs +++ b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs @@ -1061,7 +1061,7 @@ impl UserDefinedLogicalNodeCore for TopKPlanNode { }) } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } } diff --git a/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs b/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs index 93569bbb123e..3b7d0fd29610 100644 --- a/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs +++ b/datafusion/substrait/tests/cases/roundtrip_logical_plan.rs @@ -150,7 +150,7 @@ impl UserDefinedLogicalNode for MockUserDefinedLogicalPlan { unimplemented!() } - fn allows_limit_to_inputs(&self) -> bool { + fn supports_limit_pushdown(&self) -> bool { false // Disallow limit push-down by default } }