Skip to content

Commit

Permalink
Avoid re-analyzing SymbolReferences
Browse files Browse the repository at this point in the history
Optimizers such as DesugaringOptimizer and SimplifyExpressions
need access to expression types, which is currently re-computed
every time. This change improves the process by short-circuiting
the analysis for SymbolReferences.
  • Loading branch information
geraint0923 authored and martint committed Jun 20, 2016
1 parent d1b0bce commit 911f2b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.facebook.presto.sql.planner.plan.TableScanNode;
import com.facebook.presto.sql.tree.Expression;
import com.facebook.presto.sql.tree.ExpressionTreeRewriter;
import com.facebook.presto.sql.tree.SymbolReference;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

Expand Down Expand Up @@ -110,6 +111,9 @@ public PlanNode visitTableScan(TableScanNode node, RewriteContext<Void> context)

private Expression desugar(Expression expression)
{
if (expression instanceof SymbolReference) {
return expression;
}
IdentityHashMap<Expression, Type> expressionTypes = getExpressionTypes(session, metadata, sqlParser, types, expression);
return ExpressionTreeRewriter.rewriteWith(new DesugaringRewriter(expressionTypes), expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.facebook.presto.sql.tree.LogicalBinaryExpression;
import com.facebook.presto.sql.tree.NotExpression;
import com.facebook.presto.sql.tree.NullLiteral;
import com.facebook.presto.sql.tree.SymbolReference;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -146,6 +147,9 @@ public PlanNode visitTableScan(TableScanNode node, RewriteContext<Void> context)

private Expression simplifyExpression(Expression expression)
{
if (expression instanceof SymbolReference) {
return expression;
}
expression = ExpressionTreeRewriter.rewriteWith(new PushDownNegationsExpressionRewriter(), expression);
expression = ExpressionTreeRewriter.rewriteWith(new ExtractCommonPredicatesExpressionRewriter(), expression, NodeContext.ROOT_NODE);
IdentityHashMap<Expression, Type> expressionTypes = getExpressionTypes(session, metadata, sqlParser, types, expression);
Expand Down

0 comments on commit 911f2b9

Please sign in to comment.