Skip to content

Commit

Permalink
feat: run dist planner after simplify expression rule (#2723)
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored Nov 9, 2023
1 parent b53537e commit f02dc0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/query/src/dist_plan/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use datafusion_common::tree_node::{RewriteRecursion, Transformed, TreeNode, Tree
use datafusion_expr::expr::{Exists, InSubquery};
use datafusion_expr::{col, Expr, LogicalPlan, LogicalPlanBuilder, Subquery};
use datafusion_optimizer::analyzer::AnalyzerRule;
use datafusion_optimizer::simplify_expressions::SimplifyExpressions;
use datafusion_optimizer::{OptimizerContext, OptimizerRule};
use substrait::{DFLogicalSubstraitConvertor, SubstraitPlan};
use table::metadata::TableType;
use table::table::adapter::DfTableProviderAdapter;
Expand All @@ -42,6 +44,12 @@ impl AnalyzerRule for DistPlannerAnalyzer {
plan: LogicalPlan,
_config: &ConfigOptions,
) -> datafusion_common::Result<LogicalPlan> {
// preprocess the input plan
let optimizer_context = OptimizerContext::new();
let plan = SimplifyExpressions::new()
.try_optimize(&plan, &optimizer_context)?
.unwrap_or(plan);

let plan = plan.transform(&Self::inspect_plan_with_subquery)?;
let mut rewriter = PlanRewriter::default();
let result = plan.rewrite(&mut rewriter)?;
Expand Down
6 changes: 3 additions & 3 deletions src/query/src/query_engine/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ impl QueryEngineState {
let session_config = SessionConfig::new().with_create_default_catalog_and_schema(false);
// Apply the type conversion rule first.
let mut analyzer = Analyzer::new();
if with_dist_planner {
analyzer.rules.insert(0, Arc::new(DistPlannerAnalyzer));
}
analyzer.rules.insert(0, Arc::new(TypeConversionRule));
analyzer.rules.insert(0, Arc::new(StringNormalizationRule));
Self::remove_analyzer_rule(&mut analyzer.rules, CountWildcardRule {}.name());
analyzer.rules.insert(0, Arc::new(CountWildcardRule {}));
if with_dist_planner {
analyzer.rules.push(Arc::new(DistPlannerAnalyzer));
}
let mut optimizer = Optimizer::new();
optimizer.rules.push(Arc::new(OrderHintRule));

Expand Down

0 comments on commit f02dc0e

Please sign in to comment.