Skip to content

Commit

Permalink
Merge #26286
Browse files Browse the repository at this point in the history
26286: opt: distsql planner fix for index-join r=RaduBerinde a=RaduBerinde

In the heuristic planner, scanNodes always output all columns of the
table (even if some values are missing). This means that an index join
node and both child scanNodes all have the same schema.

With the optimizer, the scanNodes only output the columns that are
needed. The index join node now has its own set of output columns
(added in PR #25292).

This change makes the distsql planner work in both cases; it is
similar to the fix that was necessary for scan nodes.

Also reenabling `distsql-opt` config on the `select_index` logictest.

Release note: None

Co-authored-by: Radu Berinde <[email protected]>
  • Loading branch information
craig[bot] and RaduBerinde committed May 31, 2018
2 parents 09ccc71 + 0261992 commit f0c9f99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions pkg/sql/distsql_physical_planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1687,17 +1687,19 @@ func (dsp *DistSQLPlanner) createPlanForIndexJoin(
post := distsqlrun.PostProcessSpec{
Filter: distsqlplan.MakeExpression(
n.table.filter, planCtx.EvalContext(), nil /* indexVarMap */),
Projection: true,
OutputColumns: getOutputColumnsFromScanNode(n.table, getScanNodeToTableOrdinalMap(n.table)),
Projection: true,
}

// Recalculate planToStreamColMap: it now maps to columns in the JoinReader's
// output stream.
for i := range plan.planToStreamColMap {
plan.planToStreamColMap[i] = -1
}
for i, col := range post.OutputColumns {
plan.planToStreamColMap[col] = i
// Calculate the output columns from n.cols.
post.OutputColumns = make([]uint32, 0, len(n.cols))
plan.planToStreamColMap = makePlanToStreamColMap(len(n.cols))

for i := range n.cols {
if !n.resultColumns[i].Omitted {
plan.planToStreamColMap[i] = len(post.OutputColumns)
ord := tableOrdinal(n.table.desc, n.cols[i].ID)
post.OutputColumns = append(post.OutputColumns, uint32(ord))
}
}

types, err := getTypesForPlanResult(n, plan.planToStreamColMap)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/select_index
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# LogicTest: default opt parallel-stmts distsql distsql-metadata
# LogicTest: default opt parallel-stmts distsql distsql-opt distsql-metadata

statement ok
CREATE TABLE t (
Expand Down

0 comments on commit f0c9f99

Please sign in to comment.