Skip to content

Commit

Permalink
Specify if a query is of Explain/Explain Analyze during Analysis
Browse files Browse the repository at this point in the history
This would remove the Analysis#resetUpdateType as the update type should never even be
set to Update/delete for explain analyze queries
  • Loading branch information
Praveen2112 committed Oct 8, 2021
1 parent abb23d6 commit 45eb247
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static io.trino.sql.analyzer.QueryType.DESCRIBE;
import static io.trino.sql.analyzer.QueryType.EXPLAIN;
import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableMap;
Expand Down Expand Up @@ -240,14 +241,10 @@ public Optional<Output> getTarget()

public void setUpdateType(String updateType, QualifiedObjectName targetName, Optional<Table> targetTable, Optional<List<OutputColumn>> targetColumns)
{
this.updateType = updateType;
this.target = Optional.of(new UpdateTarget(targetName, targetTable, targetColumns));
}

public void resetUpdateType()
{
this.updateType = null;
this.target = Optional.empty();
if (queryType != EXPLAIN) {
this.updateType = updateType;
this.target = Optional.of(new UpdateTarget(targetName, targetTable, targetColumns));
}
}

public boolean isUpdateTarget(Table table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static io.trino.sql.ParameterUtils.parameterExtractor;
import static io.trino.sql.analyzer.QueryType.EXPLAIN;
import static io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED;
import static io.trino.sql.planner.planprinter.IoPlanPrinter.textIoPlan;
import static java.lang.String.format;
Expand Down Expand Up @@ -118,7 +119,7 @@ public QueryExplainer(
public Analysis analyze(Session session, Statement statement, List<Expression> parameters, WarningCollector warningCollector)
{
Analyzer analyzer = new Analyzer(session, metadata, sqlParser, groupProvider, accessControl, Optional.of(this), parameters, parameterExtractor(statement, parameters), warningCollector, statsCalculator);
return analyzer.analyze(statement);
return analyzer.analyze(statement, EXPLAIN);
}

public String getPlan(Session session, Statement statement, Type planType, List<Expression> parameters, WarningCollector warningCollector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public enum QueryType
{
DESCRIBE,
EXPLAIN,
OTHERS,
/**/;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1157,15 +1157,13 @@ private void validateColumnAliasesCount(List<Identifier> columnAliases, int sour
protected Scope visitExplain(Explain node, Optional<Scope> scope)
{
process(node.getStatement(), scope);
analysis.resetUpdateType();
return createAndAssignScope(node, scope, Field.newUnqualified("Query Plan", VARCHAR));
}

@Override
protected Scope visitExplainAnalyze(ExplainAnalyze node, Optional<Scope> scope)
{
process(node.getStatement(), scope);
analysis.resetUpdateType();
return createAndAssignScope(node, scope, Field.newUnqualified("Query Plan", VARCHAR));
}

Expand Down

0 comments on commit 45eb247

Please sign in to comment.