Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distsqlrun: make indexJoiner and joinReader show up in EXPLAIN (VEC) #40560

Merged
merged 1 commit into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pkg/sql/distsqlrun/columnarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package distsqlrun

import (
"context"
"fmt"

"github.com/cockroachdb/cockroach/pkg/col/coldata"
"github.com/cockroachdb/cockroach/pkg/col/coltypes"
Expand All @@ -26,7 +27,6 @@ import (
// chunk into a coldata.Batch column by column.
type columnarizer struct {
ProcessorBase
exec.ZeroInputNode
exec.NonExplainable

input RowSource
Expand Down Expand Up @@ -130,3 +130,22 @@ func (c *columnarizer) DrainMeta(ctx context.Context) []distsqlpb.ProducerMetada
}
return c.accumulatedMeta
}

// ChildCount is part of the exec.Operator interface.
func (c *columnarizer) ChildCount() int {
if _, ok := c.input.(exec.OpNode); ok {
return 1
}
return 0
}

// ChildCount is part of the exec.Operator interface.
func (c *columnarizer) Child(nth int) exec.OpNode {
if nth == 0 {
if n, ok := c.input.(exec.OpNode); ok {
return n
}
panic("input to columnarizer is not an exec.OpNode")
}
panic(fmt.Sprintf("invalid index %d", nth))
}
19 changes: 19 additions & 0 deletions pkg/sql/distsqlrun/indexjoiner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ package distsqlrun

import (
"context"
"fmt"

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/distsqlpb"
"github.com/cockroachdb/cockroach/pkg/sql/exec"
"github.com/cockroachdb/cockroach/pkg/sql/row"
"github.com/cockroachdb/cockroach/pkg/sql/scrub"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
Expand Down Expand Up @@ -58,6 +60,7 @@ type indexJoiner struct {
var _ Processor = &indexJoiner{}
var _ RowSource = &indexJoiner{}
var _ distsqlpb.MetadataSource = &indexJoiner{}
var _ exec.OpNode = &indexJoiner{}

const indexJoinerProcName = "index joiner"

Expand Down Expand Up @@ -254,3 +257,19 @@ func (ij *indexJoiner) generateMeta(ctx context.Context) []distsqlpb.ProducerMet
func (ij *indexJoiner) DrainMeta(ctx context.Context) []distsqlpb.ProducerMetadata {
return ij.generateMeta(ctx)
}

// ChildCount is part of the exec.OpNode interface.
func (ij *indexJoiner) ChildCount() int {
return 1
}

// Child is part of the exec.OpNode interface.
func (ij *indexJoiner) Child(nth int) exec.OpNode {
if nth == 0 {
if n, ok := ij.input.(exec.OpNode); ok {
return n
}
panic("input to indexJoiner is not an exec.OpNode")
}
panic(fmt.Sprintf("invalid index %d", nth))
}
19 changes: 19 additions & 0 deletions pkg/sql/distsqlrun/joinreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ package distsqlrun

import (
"context"
"fmt"
"sort"

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/distsqlpb"
"github.com/cockroachdb/cockroach/pkg/sql/exec"
"github.com/cockroachdb/cockroach/pkg/sql/row"
"github.com/cockroachdb/cockroach/pkg/sql/rowcontainer"
"github.com/cockroachdb/cockroach/pkg/sql/scrub"
Expand Down Expand Up @@ -129,6 +131,7 @@ type joinReader struct {
var _ Processor = &joinReader{}
var _ RowSource = &joinReader{}
var _ distsqlpb.MetadataSource = &joinReader{}
var _ exec.OpNode = &joinReader{}

const joinReaderProcName = "join reader"

Expand Down Expand Up @@ -703,3 +706,19 @@ func (jr *joinReader) generateMeta(ctx context.Context) []distsqlpb.ProducerMeta
func (jr *joinReader) DrainMeta(ctx context.Context) []distsqlpb.ProducerMetadata {
return jr.generateMeta(ctx)
}

// ChildCount is part of the exec.OpNode interface.
func (jr *joinReader) ChildCount() int {
return 1
}

// Child is part of the exec.OpNode interface.
func (jr *joinReader) Child(nth int) exec.OpNode {
if nth == 0 {
if n, ok := jr.input.(exec.OpNode); ok {
return n
}
panic("input to joinReader is not an exec.OpNode")
}
panic(fmt.Sprintf("invalid index %d", nth))
}
91 changes: 88 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/tpch_vec
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,11 @@ EXPLAIN (VEC) SELECT s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_
└── *exec.hashGrouper
└── *exec.hashJoinEqOp
├── *exec.hashJoinEqOp
│ └── *distsqlrun.colBatchScan
│ ├── *distsqlrun.colBatchScan
│ └── *distsqlrun.joinReader
│ └── *distsqlrun.joinReader
│ └── *exec.selEQBytesBytesConstOp
│ └── *distsqlrun.colBatchScan
└── *exec.hashJoinEqOp
├── *exec.hashJoinEqOp
│ ├── *distsqlrun.colBatchScan
Expand All @@ -581,6 +585,12 @@ EXPLAIN (VEC) SELECT l_orderkey, sum(l_extendedprice * (1 - l_discount)) AS reve
└── *exec.topKSorter
└── *exec.orderedAggregator
└── *exec.hashGrouper
└── *distsqlrun.joinReader
└── *exec.hashJoinEqOp
├── *exec.selLTInt64Int64ConstOp
│ └── *distsqlrun.colBatchScan
└── *exec.selEQBytesBytesConstOp
└── *distsqlrun.colBatchScan

# Query 4
query T
Expand All @@ -592,6 +602,8 @@ EXPLAIN (VEC) SELECT o_orderpriority, count(*) AS order_count FROM orders WHERE
└── *exec.orderedAggregator
└── *exec.hashGrouper
└── *exec.hashJoinEqOp
├── *distsqlrun.indexJoiner
│ └── *distsqlrun.colBatchScan
└── *exec.selLTInt64Int64Op
└── *distsqlrun.colBatchScan

Expand All @@ -608,7 +620,14 @@ EXPLAIN (VEC) SELECT n_name, sum(l_extendedprice * (1 - l_discount)) AS revenue
└── *exec.projMinusFloat64ConstFloat64Op
└── *exec.hashJoinEqOp
├── *exec.hashJoinEqOp
│ └── *exec.hashJoinEqOp
│ ├── *exec.hashJoinEqOp
│ │ ├── *distsqlrun.colBatchScan
│ │ └── *distsqlrun.joinReader
│ │ └── *exec.hashJoinEqOp
│ │ ├── *distsqlrun.colBatchScan
│ │ └── *exec.selEQBytesBytesConstOp
│ │ └── *distsqlrun.colBatchScan
│ └── *distsqlrun.indexJoiner
│ └── *distsqlrun.colBatchScan
└── *distsqlrun.colBatchScan

Expand All @@ -621,6 +640,8 @@ EXPLAIN (VEC) SELECT sum(l_extendedprice * l_discount) AS revenue FROM lineitem
└── *exec.orderedAggregator
└── *exec.oneShotOp
└── *exec.distinctChainOps
└── *distsqlrun.indexJoiner
└── *distsqlrun.colBatchScan

# Query 7
query T
Expand All @@ -636,6 +657,13 @@ EXPLAIN (VEC) SELECT supp_nation, cust_nation, l_year, sum(volume) AS revenue FR
└── *exec.defaultBuiltinFuncOperator
└── *exec.constBytesOp
└── *exec.hashJoinEqOp
├── *distsqlrun.joinReader
│ └── *distsqlrun.joinReader
│ └── *distsqlrun.joinReader
│ └── *exec.caseOp
│ └── *exec.hashJoinEqOp
│ ├── *distsqlrun.colBatchScan
│ └── *distsqlrun.colBatchScan
└── *distsqlrun.colBatchScan

# Query 8
Expand All @@ -659,6 +687,10 @@ EXPLAIN (VEC) SELECT o_year, sum(CASE WHEN nation = 'BRAZIL' THEN volume ELSE 0
│ │ ├── *distsqlrun.colBatchScan
│ │ └── *exec.hashJoinEqOp
│ │ ├── *exec.hashJoinEqOp
│ │ │ ├── *distsqlrun.joinReader
│ │ │ │ └── *distsqlrun.joinReader
│ │ │ │ └── *exec.selEQBytesBytesConstOp
│ │ │ │ └── *distsqlrun.colBatchScan
│ │ │ └── *distsqlrun.colBatchScan
│ │ └── *exec.selLEInt64Int64ConstOp
│ │ └── *exec.selGEInt64Int64ConstOp
Expand All @@ -676,6 +708,15 @@ EXPLAIN (VEC) SELECT nation, o_year, sum(amount) AS sum_profit FROM ( SELECT n_n
└── *exec.sortOp
└── *exec.orderedAggregator
└── *exec.hashGrouper
└── *distsqlrun.joinReader
└── *exec.hashJoinEqOp
├── *exec.hashJoinEqOp
│ ├── *distsqlrun.joinReader
│ │ └── *distsqlrun.joinReader
│ │ └── *distsqlrun.joinReader
│ │ └── *distsqlrun.colBatchScan
│ └── *distsqlrun.colBatchScan
└── *distsqlrun.colBatchScan

# Query 10
query T
Expand All @@ -687,6 +728,13 @@ EXPLAIN (VEC) SELECT c_custkey, c_name, sum(l_extendedprice * (1 - l_discount))
└── *exec.topKSorter
└── *exec.orderedAggregator
└── *exec.hashGrouper
└── *distsqlrun.joinReader
└── *exec.hashJoinEqOp
├── *exec.hashJoinEqOp
│ ├── *distsqlrun.colBatchScan
│ └── *distsqlrun.indexJoiner
│ └── *distsqlrun.colBatchScan
└── *distsqlrun.colBatchScan

# Query 11
query T
Expand All @@ -700,6 +748,11 @@ EXPLAIN (VEC) SELECT ps_partkey, sum(ps_supplycost * ps_availqty::float) AS valu
└── *exec.constNullOp
└── *exec.orderedAggregator
└── *exec.hashGrouper
└── *distsqlrun.joinReader
└── *distsqlrun.joinReader
└── *distsqlrun.joinReader
└── *exec.selEQBytesBytesConstOp
└── *distsqlrun.colBatchScan

# Query 12
query error unable to vectorize execution plan: sum on int cols not supported
Expand Down Expand Up @@ -736,7 +789,9 @@ EXPLAIN (VEC) SELECT 100.00 * sum(CASE WHEN p_type LIKE 'PROMO%' THEN l_extended
└── *exec.projMinusFloat64ConstFloat64Op
└── *exec.caseOp
└── *exec.hashJoinEqOp
└── *distsqlrun.colBatchScan
├── *distsqlrun.colBatchScan
└── *distsqlrun.indexJoiner
└── *distsqlrun.colBatchScan

# Query 15
#-- TODO(yuzefovich): figure out how to execute this query consisting of three
Expand All @@ -757,6 +812,16 @@ EXPLAIN (VEC) SELECT sum(l_extendedprice) / 7.0 AS avg_yearly FROM lineitem, par
└── *exec.orderedAggregator
└── *exec.oneShotOp
└── *exec.distinctChainOps
└── *distsqlrun.joinReader
└── *distsqlrun.joinReader
└── *exec.projMultFloat64Float64ConstOp
└── *exec.orderedAggregator
└── *exec.distinctChainOps
└── *distsqlrun.joinReader
└── *distsqlrun.joinReader
└── *exec.selEQBytesBytesConstOp
└── *exec.selEQBytesBytesConstOp
└── *distsqlrun.colBatchScan

# Query 18
query T
Expand All @@ -768,6 +833,15 @@ EXPLAIN (VEC) SELECT c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, s
└── *exec.topKSorter
└── *exec.orderedAggregator
└── *exec.hashGrouper
└── *distsqlrun.joinReader
└── *exec.hashJoinEqOp
├── *exec.mergeJoinLeftSemiOp
│ ├── *distsqlrun.colBatchScan
│ └── *exec.selGTFloat64Float64ConstOp
│ └── *exec.orderedAggregator
│ └── *exec.distinctChainOps
│ └── *distsqlrun.colBatchScan
└── *distsqlrun.colBatchScan

# Query 19
query T
Expand Down Expand Up @@ -804,6 +878,8 @@ EXPLAIN (VEC) SELECT s_name, s_address FROM supplier, nation WHERE s_suppkey IN
│ │ └── *exec.orderedAggregator
│ │ └── *exec.hashGrouper
│ │ └── *exec.hashJoinEqOp
│ │ ├── *distsqlrun.indexJoiner
│ │ │ └── *distsqlrun.colBatchScan
│ │ └── *distsqlrun.colBatchScan
│ └── *exec.selPrefixBytesBytesConstOp
│ └── *distsqlrun.colBatchScan
Expand All @@ -823,3 +899,12 @@ EXPLAIN (VEC) SELECT cntrycode, count(*) AS numcust, sum(c_acctbal) AS totacctba
└── *exec.sortOp
└── *exec.orderedAggregator
└── *exec.hashGrouper
└── *distsqlrun.joinReader
└── *exec.selGTFloat64Float64Op
└── *exec.castOpNullAny
└── *exec.constNullOp
└── *exec.selectInOpBytes
└── *exec.substringFunctionOperator
└── *exec.constInt64Op
└── *exec.constInt64Op
└── *distsqlrun.colBatchScan