-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
colexec: implement vectorized index join
This patch provides a vectorized implementation of the index join operator. Span generation is accomplished using two utility operators. `spanEncoder` operates on a single index key column and fills a `Bytes` column with the encoding of that column for each row. `spanAssembler` takes the output of each `spanEncoder` and generates spans, accounting for table/index prefixes and possibly splitting the spans over column families. Finally, the `ColIndexJoin` operator uses the generated spans to perform a lookup on the table's primary index, returns all batches resulting from the lookup, and repeats until the input is fully consumed. The `ColIndexJoin` operator queues up input rows until the memory footprint of the rows reaches a preset limit (default 4MB for parity with the row engine). This allows the cost of starting a scan to be amortized. Addresses #65905 Release note (sql change): The vectorized execution engine can now perform a scan over an index, and then join on the primary index to retrieve the required columns.
- Loading branch information
1 parent
679ee6e
commit 5a6f53b
Showing
28 changed files
with
4,217 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
load("//pkg/sql/colexecop:EXECGEN.bzl", "eg_go_filegroup", "gen_eg_go_rules") | ||
|
||
go_library( | ||
name = "colexecspan", | ||
srcs = [ | ||
":gen-exec", # keep | ||
], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecspan", # keep | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/col/coldata", # keep | ||
"//pkg/col/coldataext", # keep | ||
"//pkg/col/typeconv", # keep | ||
"//pkg/keys", # keep | ||
"//pkg/roachpb:with-mocks", # keep | ||
"//pkg/sql/catalog", # keep | ||
"//pkg/sql/catalog/descpb", # keep | ||
"//pkg/sql/colexecerror", # keep | ||
"//pkg/sql/colmem", # keep | ||
"//pkg/sql/execinfra", # keep | ||
"//pkg/sql/rowenc", # keep | ||
"//pkg/sql/sem/tree", # keep | ||
"//pkg/sql/types", # keep | ||
"//pkg/util", # keep | ||
"//pkg/util/duration", # keep | ||
"//pkg/util/encoding", # keep | ||
"@com_github_cockroachdb_apd_v2//:apd", # keep | ||
"@com_github_cockroachdb_errors//:errors", # keep | ||
], | ||
) | ||
|
||
go_test( | ||
name = "colexecspan_test", | ||
srcs = [ | ||
"dep_test.go", | ||
"main_test.go", | ||
"span_assembler_test.go", | ||
], | ||
embed = [":colexecspan"], # keep | ||
deps = [ | ||
"//pkg/col/coldata", | ||
"//pkg/col/coldataext", | ||
"//pkg/col/coldatatestutils", | ||
"//pkg/keys", | ||
"//pkg/roachpb:with-mocks", | ||
"//pkg/security", | ||
"//pkg/settings/cluster", | ||
"//pkg/sql/catalog", | ||
"//pkg/sql/catalog/descpb", | ||
"//pkg/sql/catalog/tabledesc", | ||
"//pkg/sql/colconv", | ||
"//pkg/sql/colexec/colexectestutils", | ||
"//pkg/sql/colexecerror", | ||
"//pkg/sql/colmem", | ||
"//pkg/sql/execinfra", | ||
"//pkg/sql/rowenc", | ||
"//pkg/sql/sem/tree", | ||
"//pkg/sql/span", | ||
"//pkg/sql/types", | ||
"//pkg/testutils/buildutil", | ||
"//pkg/testutils/skip", | ||
"//pkg/util", | ||
"//pkg/util/leaktest", | ||
"//pkg/util/log", | ||
"//pkg/util/randutil", | ||
], | ||
) | ||
|
||
# Map between target name and relevant template. | ||
targets = [ | ||
("span_assembler.eg.go", "span_assembler_tmpl.go"), | ||
("span_encoder.eg.go", "span_encoder_tmpl.go"), | ||
] | ||
|
||
# Define a file group for all the .eg.go targets. | ||
eg_go_filegroup( | ||
name = "gen-exec", | ||
targets = targets, | ||
) | ||
|
||
# Define gen rules for individual eg.go files. | ||
gen_eg_go_rules(targets) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package colexecspan | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/testutils/buildutil" | ||
) | ||
|
||
func TestNoLinkForbidden(t *testing.T) { | ||
buildutil.VerifyNoImports(t, | ||
"github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecspan", true, | ||
[]string{ | ||
"github.com/cockroachdb/cockroach/pkg/sql/colexec", | ||
"github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecagg", | ||
"github.com/cockroachdb/cockroach/pkg/sql/colexec/colexechash", | ||
"github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecjoin", | ||
"github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecproj", | ||
"github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecsel", | ||
}, nil, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package colexecspan | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/col/coldata" | ||
"github.com/cockroachdb/cockroach/pkg/sql/colexec/colexectestutils" | ||
"github.com/cockroachdb/cockroach/pkg/sql/colexecerror" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/skip" | ||
"github.com/cockroachdb/cockroach/pkg/util/randutil" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
randutil.SeedForTests() | ||
os.Exit(func() int { | ||
flag.Parse() | ||
if !skip.UnderBench() { | ||
// (If we're running benchmarks, don't set a random batch size.) | ||
randomBatchSize := colexectestutils.GenerateBatchSize() | ||
fmt.Printf("coldata.BatchSize() is set to %d\n", randomBatchSize) | ||
if err := coldata.SetBatchSizeForTests(randomBatchSize); err != nil { | ||
colexecerror.InternalError(err) | ||
} | ||
} | ||
return m.Run() | ||
}()) | ||
} |
Oops, something went wrong.