You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/07/20 20:33:17 UTC

[GitHub] [arrow-datafusion] NGA-TRAN commented on a change in pull request #759: Show the result of all optimizer passes in EXPLAIN VERBOSE

NGA-TRAN commented on a change in pull request #759:
URL: https://github.com/apache/arrow-datafusion/pull/759#discussion_r673470819



##########
File path: datafusion/src/physical_plan/explain.rs
##########
@@ -115,9 +115,20 @@ impl ExecutionPlan for ExplainExec {
             .iter()
             .filter(|s| s.should_display(self.verbose));
 
+        // Identify plans that are not changed
+        let mut prev: Option<&StringifiedPlan> = None;
+
         for p in plans_to_print {
             type_builder.append_value(p.plan_type.to_string())?;
-            plan_builder.append_value(&*p.plan)?;
+            match prev {
+                Some(prev) if !should_show(prev, p) => {
+                    plan_builder.append_value("SAME TEXT AS ABOVE")?;

Review comment:
       +1

##########
File path: datafusion/src/execution/context.rs
##########
@@ -446,19 +447,31 @@ impl ExecutionContext {
 
     /// Optimizes the logical plan by applying optimizer rules.
     pub fn optimize(&self, plan: &LogicalPlan) -> Result<LogicalPlan> {
-        let state = &mut self.state.lock().unwrap();
-        let execution_props = &mut state.execution_props.clone();
-        let optimizers = &state.config.optimizers;
-
-        let execution_props = execution_props.start_execution();
-
-        let mut new_plan = plan.clone();
-        debug!("Logical plan:\n {:?}", plan);
-        for optimizer in optimizers {
-            new_plan = optimizer.optimize(&new_plan, execution_props)?;
+        if let LogicalPlan::Explain {
+            verbose,
+            plan,
+            stringified_plans,
+            schema,
+        } = plan
+        {
+            let mut stringified_plans = stringified_plans.clone();
+
+            // optimize the child plan, capturing the output of each optimizer
+            let plan = self.optimize_internal(plan, |optimized_plan, optimizer| {
+                let optimizer_name = optimizer.name().to_string();
+                let plan_type = PlanType::OptimizedLogicalPlan { optimizer_name };
+                stringified_plans.push(optimized_plan.to_stringified(plan_type));
+            })?;
+
+            Ok(LogicalPlan::Explain {
+                verbose: *verbose,
+                plan: Arc::new(plan),
+                stringified_plans,
+                schema: schema.clone(),
+            })
+        } else {
+            self.optimize_internal(plan, |_, _| {})

Review comment:
       Nice. Now we have the optimized plan displayed 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org