diff --git a/datafusion/expr/src/logical_plan/invariants.rs b/datafusion/expr/src/logical_plan/invariants.rs index 1b214582afc9..92e43577ea46 100644 --- a/datafusion/expr/src/logical_plan/invariants.rs +++ b/datafusion/expr/src/logical_plan/invariants.rs @@ -59,13 +59,7 @@ pub fn assert_executable_invariants(plan: &LogicalPlan) -> Result<()> { /// This invariant is subject to change. /// refer: fn assert_unique_field_names(plan: &LogicalPlan) -> Result<()> { - plan.schema().check_names()?; - - plan.apply_with_subqueries(|plan: &LogicalPlan| { - plan.schema().check_names()?; - Ok(TreeNodeRecursion::Continue) - }) - .map(|_| ()) + plan.schema().check_names() } /// Returns an error if the plan is not sematically valid. diff --git a/datafusion/optimizer/src/optimizer.rs b/datafusion/optimizer/src/optimizer.rs index bed4c3cb844c..e0b32cfbbbe1 100644 --- a/datafusion/optimizer/src/optimizer.rs +++ b/datafusion/optimizer/src/optimizer.rs @@ -386,7 +386,6 @@ impl Optimizer { .skip_failed_rules .then(|| new_plan.clone()); - #[cfg(debug_assertions)] let starting_schema = Arc::clone(new_plan.schema()); let result = match rule.apply_order() { @@ -398,8 +397,7 @@ impl Optimizer { None => optimize_plan_node(new_plan, rule.as_ref(), config), } .and_then(|tnr| { - // in debug mode, run checks are each optimer pass - #[cfg(debug_assertions)] + // run checks optimizer invariant checks, per pass assert_valid_optimization(&tnr.data, &starting_schema) .map_err(|e| { DataFusionError::Context( @@ -407,6 +405,8 @@ impl Optimizer { Box::new(e), ) })?; + + // run LP invariant checks only in debug #[cfg(debug_assertions)] tnr.data.check_invariants(InvariantLevel::Executable) .map_err(|e| {