From 2a40a946b55a3f184521e8b8a422cb1a1af1fd13 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Wed, 4 Dec 2024 15:26:56 +0800 Subject: [PATCH] fix: put PipelineChecker in the end Signed-off-by: Ruihang Xia --- src/query/src/query_engine/state.rs | 15 +++++++++++++++ .../common/tql-explain-analyze/explain.result | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/query/src/query_engine/state.rs b/src/query/src/query_engine/state.rs index edc10e076a73..74db773031d0 100644 --- a/src/query/src/query_engine/state.rs +++ b/src/query/src/query_engine/state.rs @@ -32,6 +32,8 @@ use datafusion::error::Result as DfResult; use datafusion::execution::context::{QueryPlanner, SessionConfig, SessionContext, SessionState}; use datafusion::execution::runtime_env::RuntimeEnv; use datafusion::physical_optimizer::optimizer::PhysicalOptimizer; +use datafusion::physical_optimizer::pipeline_checker::PipelineChecker; +use datafusion::physical_optimizer::PhysicalOptimizerRule; use datafusion::physical_plan::ExecutionPlan; use datafusion::physical_planner::{DefaultPhysicalPlanner, ExtensionPlanner, PhysicalPlanner}; use datafusion_expr::LogicalPlan as DfLogicalPlan; @@ -127,6 +129,12 @@ impl QueryEngineState { .push(Arc::new(WindowedSortPhysicalRule)); // Add rule to remove duplicate nodes generated by other rules. Run this in the last. physical_optimizer.rules.push(Arc::new(RemoveDuplicate)); + // Place PipelineChecker at the end of the list to ensure that it runs after all other rules. + Self::remove_physical_optimizer_rule( + &mut physical_optimizer.rules, + PipelineChecker {}.name(), + ); + physical_optimizer.rules.push(Arc::new(PipelineChecker {})); let session_state = SessionState::new_with_config_rt(session_config, runtime_env) .with_analyzer_rules(analyzer.rules) @@ -159,6 +167,13 @@ impl QueryEngineState { rules.retain(|rule| rule.name() != name); } + fn remove_physical_optimizer_rule( + rules: &mut Vec>, + name: &str, + ) { + rules.retain(|rule| rule.name() != name); + } + /// Optimize the logical plan by the extension anayzer rules. pub fn optimize_by_extension_rules( &self, diff --git a/tests/cases/standalone/common/tql-explain-analyze/explain.result b/tests/cases/standalone/common/tql-explain-analyze/explain.result index 4cdb5a879007..ddfcc97ed1a4 100644 --- a/tests/cases/standalone/common/tql-explain-analyze/explain.result +++ b/tests/cases/standalone/common/tql-explain-analyze/explain.result @@ -182,9 +182,9 @@ TQL EXPLAIN VERBOSE (0, 10, '5s') test; |_|_| | physical_plan after LimitAggregation_| SAME TEXT AS ABOVE_| | physical_plan after ProjectionPushdown_| SAME TEXT AS ABOVE_| -| physical_plan after PipelineChecker_| SAME TEXT AS ABOVE_| | physical_plan after WindowedSortRule_| SAME TEXT AS ABOVE_| | physical_plan after RemoveDuplicateRule_| SAME TEXT AS ABOVE_| +| physical_plan after PipelineChecker_| SAME TEXT AS ABOVE_| | physical_plan_| PromInstantManipulateExec: range=[0..0], lookback=[300000], interval=[300000], time index=[j]_| |_|_PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false]_| |_|_PromSeriesDivideExec: tags=["k"]_|