Skip to content

Commit

Permalink
physicalplan: preevaluate subqueries on LocalExprs
Browse files Browse the repository at this point in the history
When the plan is local, we do not serialize expressions. Previously, in
such a case we would also not preevaluate the subqueries in the
expressions which made `EXPLAIN (VEC)` return unexpected plan (there
would `tree.Subquery` in the expression which we don't support in the
vectorized, so we would wrap the plan). Now we will preevalute the
subqueries before storing in the processor spec. AFAICT it affects only
this explain variant and nothing else.

Release note: None
  • Loading branch information
yuzefovich committed Jun 10, 2020
1 parent 3b116e9 commit 096265d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
33 changes: 22 additions & 11 deletions pkg/sql/logictest/testdata/logic_test/tpch_vec
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,15 @@ EXPLAIN (VEC) SELECT ps_partkey, sum(ps_supplycost * ps_availqty::float) AS valu
└ Node 1
└ *colexec.sortOp
└ *rowexec.noopProcessor
└ *colexec.hashAggregator
└ *rowexec.joinReader
└ *rowexec.joinReader
└ *colexec.selGTFloat64Float64Op
└ *colexec.castOpNullAny
└ *colexec.constNullOp
└ *colexec.hashAggregator
└ *rowexec.joinReader
└ *colexec.selEQBytesBytesConstOp
└ *colexec.colBatchScan
└ *rowexec.joinReader
└ *rowexec.joinReader
└ *colexec.selEQBytesBytesConstOp
└ *colexec.colBatchScan

# Query 12
query T
Expand Down Expand Up @@ -826,10 +828,12 @@ EXPLAIN (VEC) SELECT s_suppkey, s_name, s_address, s_phone, total_revenue FROM s
└ *colexec.mergeJoinInnerOp
├ *colexec.colBatchScan
└ *colexec.sortOp
└ *rowexec.noopProcessor
└ *colexec.hashAggregator
└ *rowexec.indexJoiner
└ *colexec.colBatchScan
└ *colexec.selEQFloat64Float64Op
└ *colexec.castOpNullAny
└ *colexec.constNullOp
└ *colexec.hashAggregator
└ *rowexec.indexJoiner
└ *colexec.colBatchScan

statement ok
DROP VIEW revenue0
Expand Down Expand Up @@ -1002,4 +1006,11 @@ EXPLAIN (VEC) SELECT cntrycode, count(*) AS numcust, sum(c_acctbal) AS totacctba
└ *colexec.sortOp
└ *colexec.hashAggregator
└ *rowexec.joinReader
└ *rowexec.tableReader
└ *colexec.selGTFloat64Float64Op
└ *colexec.castOpNullAny
└ *colexec.constNullOp
└ *colexec.selectInOpBytes
└ *colexec.substringInt64Int64Operator
└ *colexec.constInt64Op
└ *colexec.constInt64Op
└ *colexec.colBatchScan
18 changes: 10 additions & 8 deletions pkg/sql/physicalplan/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ func MakeExpression(
ctx = &fakeExprContext{}
}

if ctx.IsLocal() {
if indexVarMap != nil {
// Remap our indexed vars.
expr = sqlbase.RemapIVarsInTypedExpr(expr, indexVarMap)
}
return execinfrapb.Expression{LocalExpr: expr}, nil
}

evalCtx := ctx.EvalContext()
subqueryVisitor := &evalAndReplaceSubqueryVisitor{
evalCtx: evalCtx,
Expand All @@ -94,7 +86,17 @@ func MakeExpression(
if subqueryVisitor.err != nil {
return execinfrapb.Expression{}, subqueryVisitor.err
}
expr = outExpr.(tree.TypedExpr)
}

if ctx.IsLocal() {
if indexVarMap != nil {
// Remap our indexed vars.
expr = sqlbase.RemapIVarsInTypedExpr(expr, indexVarMap)
}
return execinfrapb.Expression{LocalExpr: expr}, nil
}

// We format the expression using the IndexedVar and Placeholder formatting interceptors.
fmtCtx := execinfrapb.ExprFmtCtxBase(evalCtx)
if indexVarMap != nil {
Expand Down

0 comments on commit 096265d

Please sign in to comment.