Skip to content

Commit

Permalink
Merge #49475 #49662
Browse files Browse the repository at this point in the history
49475: opt: create library that determines how joins affect input rows r=andy-kimball a=DrewKimball

Previously, there was no simple way to determine whether all rows from
a join input will be included in its output, nor whether input rows will
be duplicated by the join.

This patch adds a library that constructs a Multiplicity struct for join
operators. The Multiplicity can be queried for information about how a
join will affect its input rows (e.g. duplicated, filtered and/or
null-extended). The existing SimplifyLeftJoinWithFilters rule has been
refactored to use this library. The Multiplicity library will also be
useful for future join elimination and limit pushdown rules.

Release note: None

49662: roachtest: don't run schema change workload on 19.2 releases r=spaskob a=spaskob

Fixes #47024.

Release note (bug fix):
The schema change workload is meant for testing the behavior of schema
changes on clusters with nodes with min version 19.2. It will deadlock
on earlier versions.

Co-authored-by: Drew Kimball <andrewekimball@gmail.com>
Co-authored-by: Spas Bojanov <spas@cockroachlabs.com>
  • Loading branch information
3 people committed May 28, 2020
3 parents 3f08089 + e039beb + 21d66b4 commit 9e1666b
Show file tree
Hide file tree
Showing 27 changed files with 1,499 additions and 308 deletions.
6 changes: 1 addition & 5 deletions pkg/cmd/roachtest/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ func registerAcceptance(r *testRegistry) {
{
name: "version-upgrade",
fn: func(ctx context.Context, t *test, c *cluster) {
predV, err := PredecessorVersion(r.buildVersion)
if err != nil {
t.Fatal(err)
}
runVersionUpgrade(ctx, t, c, predV)
runVersionUpgrade(ctx, t, c, r.buildVersion)
},
// This test doesn't like running on old versions because it upgrades to
// the latest released version and then it tries to "head", where head is
Expand Down
21 changes: 15 additions & 6 deletions pkg/cmd/roachtest/mixed_version_schemachange.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ package main
import (
"context"
"fmt"

"github.com/cockroachdb/cockroach/pkg/util/version"
)

func registerSchemaChangeMixedVersions(r *testRegistry) {
Expand All @@ -25,15 +27,11 @@ func registerSchemaChangeMixedVersions(r *testRegistry) {
MinVersion: "v20.1.0",
Cluster: makeClusterSpec(4),
Run: func(ctx context.Context, t *test, c *cluster) {
predV, err := PredecessorVersion(r.buildVersion)
if err != nil {
t.Fatal(err)
}
maxOps := 100
if local {
maxOps = 10
}
runSchemaChangeMixedVersions(ctx, t, c, maxOps, predV)
runSchemaChangeMixedVersions(ctx, t, c, maxOps, r.buildVersion)
},
})
}
Expand Down Expand Up @@ -63,12 +61,23 @@ func runSchemaChangeWorkloadStep(maxOps int) versionStep {
}

func runSchemaChangeMixedVersions(
ctx context.Context, t *test, c *cluster, maxOps int, predecessorVersion string,
ctx context.Context, t *test, c *cluster, maxOps int, buildVersion version.Version,
) {
predecessorVersion, err := PredecessorVersion(buildVersion)
if err != nil {
t.Fatal(err)
}

// An empty string will lead to the cockroach binary specified by flag
// `cockroach` to be used.
const mainVersion = ""
schemaChangeStep := runSchemaChangeWorkloadStep(maxOps)
if buildVersion.Major() < 20 {
// Schema change workload is meant to run only on versions 19.2 or higher.
// If the main version is below 20.1 then then predecessor version will be
// below 19.2.
schemaChangeStep = nil
}

u := newVersionUpgradeTest(c,
uploadAndStartFromCheckpointFixture(c.All(), predecessorVersion),
Expand Down
11 changes: 8 additions & 3 deletions pkg/cmd/roachtest/versionupgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ DROP TABLE test.t;
`),
}

func runVersionUpgrade(ctx context.Context, t *test, c *cluster, predecessorVersion string) {
func runVersionUpgrade(ctx context.Context, t *test, c *cluster, buildVersion version.Version) {
predecessorVersion, err := PredecessorVersion(buildVersion)
if err != nil {
t.Fatal(err)
}
// This test uses fixtures and we do not have encrypted fixtures right now.
c.encryptDefault = false

Expand Down Expand Up @@ -159,8 +163,9 @@ func (u *versionUpgradeTest) run(ctx context.Context, t *test) {
}()

for _, step := range u.steps {
step(ctx, t, u)

if step != nil {
step(ctx, t, u)
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/fk
Original file line number Diff line number Diff line change
Expand Up @@ -3198,3 +3198,24 @@ ALTER TABLE t2 DROP CONSTRAINT fk1; ALTER TABLE t2 DROP CONSTRAINT fk2; TRUNCATE

statement ok
DROP TABLE t2 CASCADE; DROP TABLE t1 CASCADE

# Regression test for #49628.
statement ok
CREATE TABLE xyz (x INT, y INT, z INT, PRIMARY KEY (x, y, z));
CREATE TABLE fk_ref
(
a INT NOT NULL,
b INT,
c INT NOT NULL,
FOREIGN KEY (a, b, c) REFERENCES xyz (x, y, z)
);
INSERT INTO fk_ref (VALUES (1, NULL, 1));

query IIIIII
SELECT * FROM fk_ref LEFT JOIN xyz ON a = x
----
1 NULL 1 NULL NULL NULL

statement ok
DROP TABLE fk_ref;
DROP TABLE xyz;
19 changes: 19 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/join
Original file line number Diff line number Diff line change
Expand Up @@ -1093,3 +1093,22 @@ CREATE TABLE t44746_1(c1 INT)
# Note: an "error parsing regexp" would also be acceptable here.
statement ok
SELECT * FROM t44746_0 FULL JOIN t44746_1 ON (SUBSTRING('', ')') = '') = (c1 > 0)

# Regression test for #49630.
statement ok
DROP TABLE empty;
CREATE TABLE xy (x INT PRIMARY KEY, y INT);
CREATE TABLE fk_ref (r INT NOT NULL REFERENCES xy (x));
CREATE TABLE empty (v INT);
INSERT INTO xy (VALUES (1, 1));
INSERT INTO fk_ref (VALUES (1));

query IIII
SELECT * FROM fk_ref LEFT JOIN (SELECT * FROM xy INNER JOIN empty ON True) ON r = x
----
1 NULL NULL NULL

statement ok
DROP TABLE empty;
DROP TABLE fk_ref;
DROP TABLE xy;
1 change: 0 additions & 1 deletion pkg/sql/opt/exec/execbuilder/testdata/enums
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ scan t
└── constraint: /1
├── [/'hello' - /'hello']
└── [/'hi' - /'hi']

6 changes: 6 additions & 0 deletions pkg/sql/opt/memo/expr_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,12 @@ func (f *ExprFmtCtx) formatRelational(e RelExpr, tp treeprinter.Node) {
if r.JoinSize > 1 {
tp.Childf("join-size: %d", r.JoinSize)
}
switch e.Op() {
case opt.InnerJoinOp, opt.LeftJoinOp, opt.FullJoinOp:
if s := r.MultiplicityProps.String(); (r.Available&props.MultiplicityProps) != 0 && s != "" {
tp.Childf("multiplicity: %s", s)
}
}
if withUses := relational.Shared.Rule.WithUses; len(withUses) > 0 {
n := tp.Childf("cte-uses")
ids := make([]opt.WithID, 0, len(withUses))
Expand Down
Loading

0 comments on commit 9e1666b

Please sign in to comment.