From 74e7777cbb414444e6eda803fc31aa2a4efe71ad Mon Sep 17 00:00:00 2001 From: Andrei Stefan Date: Wed, 12 Feb 2020 06:57:43 +0200 Subject: [PATCH] Hook in the optimizer rules (#52172) (cherry picked from commit 1f90d8cc56052fbf2af604e72f9f5ca73f5e75d5) --- .../xpack/eql/optimizer/Optimizer.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/optimizer/Optimizer.java b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/optimizer/Optimizer.java index c9d5986b5ec..f802fa79d12 100644 --- a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/optimizer/Optimizer.java +++ b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/optimizer/Optimizer.java @@ -6,10 +6,18 @@ package org.elasticsearch.xpack.eql.optimizer; +import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.BooleanLiteralsOnTheRight; +import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.BooleanSimplification; +import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.CombineBinaryComparisons; +import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.ConstantFolding; +import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.PropagateEquals; +import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.PruneFilters; +import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.PruneLiteralsInOrderBy; +import org.elasticsearch.xpack.ql.optimizer.OptimizerRules.SetAsOptimized; import org.elasticsearch.xpack.ql.plan.logical.LogicalPlan; import org.elasticsearch.xpack.ql.rule.RuleExecutor; -import static java.util.Collections.emptyList; +import java.util.Arrays; public class Optimizer extends RuleExecutor { @@ -19,6 +27,22 @@ public class Optimizer extends RuleExecutor { @Override protected Iterable.Batch> batches() { - return emptyList(); + Batch operators = new Batch("Operator Optimization", + new ConstantFolding(), + // boolean + new BooleanSimplification(), + new BooleanLiteralsOnTheRight(), + // needs to occur before BinaryComparison combinations + new PropagateEquals(), + new CombineBinaryComparisons(), + // prune/elimination + new PruneFilters(), + new PruneLiteralsInOrderBy() + ); + + Batch label = new Batch("Set as Optimized", Limiter.ONCE, + new SetAsOptimized()); + + return Arrays.asList(operators, label); } }