Skip to content

Commit

Permalink
Use PushProjectionThrough{Union,Exchange} optimizers
Browse files Browse the repository at this point in the history
  • Loading branch information
losipiuk committed Apr 10, 2017
1 parent 0443518 commit 1f6588a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.facebook.presto.sql.planner.iterative.rule.PushLimitThroughMarkDistinct;
import com.facebook.presto.sql.planner.iterative.rule.PushLimitThroughProject;
import com.facebook.presto.sql.planner.iterative.rule.PushLimitThroughSemiJoin;
import com.facebook.presto.sql.planner.iterative.rule.PushProjectionThroughExchange;
import com.facebook.presto.sql.planner.iterative.rule.PushProjectionThroughUnion;
import com.facebook.presto.sql.planner.iterative.rule.RemoveEmptyDelete;
import com.facebook.presto.sql.planner.iterative.rule.RemoveFullSample;
import com.facebook.presto.sql.planner.iterative.rule.RemoveRedundantIdentityProjections;
Expand Down Expand Up @@ -114,6 +116,13 @@ public PlanOptimizers(Metadata metadata, SqlParser sqlParser, FeaturesConfig fea
Set<Rule> predicatePushDownRules = ImmutableSet.of(
new MergeFilters());

IterativeOptimizer projectionPushDown = new IterativeOptimizer(
stats,
ImmutableList.of(new ProjectionPushDown()),
ImmutableSet.of(
new PushProjectionThroughUnion(),
new PushProjectionThroughExchange()));

builder.add(
new DesugaringOptimizer(metadata, sqlParser), // Clean up all the sugar in expressions, e.g. AtTimeZone, must be run before all the other optimizers
new CanonicalizeExpressions(),
Expand Down Expand Up @@ -165,7 +174,7 @@ public PlanOptimizers(Metadata metadata, SqlParser sqlParser, FeaturesConfig fea
new PredicatePushDown(metadata, sqlParser),
new MergeProjections(),
new SimplifyExpressions(metadata, sqlParser), // Re-run the SimplifyExpressions to simplify any recomposed expressions from other optimizations
new ProjectionPushDown(),
projectionPushDown,
new UnaliasSymbolReferences(), // Run again because predicate pushdown and projection pushdown might add more projections
new PruneUnreferencedOutputs(), // Make sure to run this before index join. Filtered projections may not have all the columns.
new IndexJoinOptimizer(metadata), // Run this after projections and filters have been fully simplified and pushed down
Expand All @@ -184,7 +193,7 @@ public PlanOptimizers(Metadata metadata, SqlParser sqlParser, FeaturesConfig fea
new MetadataQueryOptimizer(metadata),
new EliminateCrossJoins(), // This can pull up Filter and Project nodes from between Joins, so we need to push them down again
new PredicatePushDown(metadata, sqlParser),
new ProjectionPushDown());
projectionPushDown);

if (featuresConfig.isOptimizeSingleDistinct()) {
builder.add(
Expand All @@ -211,7 +220,7 @@ public PlanOptimizers(Metadata metadata, SqlParser sqlParser, FeaturesConfig fea
));

builder.add(new PredicatePushDown(metadata, sqlParser)); // Run predicate push down one more time in case we can leverage new information from layouts' effective predicate
builder.add(new ProjectionPushDown());
builder.add(projectionPushDown);
builder.add(new MergeProjections());
builder.add(new UnaliasSymbolReferences()); // Run unalias after merging projections to simplify projections more efficiently
builder.add(new PruneUnreferencedOutputs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static com.facebook.presto.sql.planner.plan.ChildReplacer.replaceChildren;
import static java.util.Objects.requireNonNull;

@Deprecated
public class ProjectionPushDown
implements PlanOptimizer
{
Expand Down

0 comments on commit 1f6588a

Please sign in to comment.