Skip to content

Commit

Permalink
Merge #82043 #82256
Browse files Browse the repository at this point in the history
82043: storage: fix incorrect condition in `mvccPutInternal` intent check r=jbowens a=erikgrinaker

Introduced in a3e608d.

Release note: None

82256: sql/schemachanger/scplan/internal/rules: rework dep rules r=ajwerner a=ajwerner

The dep rules helpers were brittle. Instead, make it easier to construct rel
queries directly.

Release note: None

Co-authored-by: Erik Grinaker <[email protected]>
Co-authored-by: Andrew Werner <[email protected]>
  • Loading branch information
3 people committed Jun 6, 2022
3 parents ea499a5 + f18adb3 + e5ee890 commit 1860eaa
Show file tree
Hide file tree
Showing 13 changed files with 1,659 additions and 1,521 deletions.
3 changes: 2 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/new_schema_changer
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ EXPLAIN (DDL, VERBOSE) ALTER TABLE foo ADD COLUMN j INT
│ │ │ │ ABSENT → PUBLIC
│ │ │ │
│ │ │ └── • SameStagePrecedence dependency from PUBLIC ColumnName:{DescID: 106, Name: j, ColumnID: 2}
│ │ │ rule: "column named right before column becomes public"
│ │ │ rule: "column named right before column type becomes public"
│ │ │
│ │ └── • PrimaryIndex:{DescID: 106, IndexID: 2, ConstraintID: 1, TemporaryIndexID: 3}
│ │ │ ABSENT → BACKFILL_ONLY
Expand Down Expand Up @@ -429,6 +429,7 @@ EXPLAIN (DDL, VERBOSE) ALTER TABLE foo ADD COLUMN j INT




statement ok
ALTER TABLE foo ADD COLUMN j INT

Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/schemachanger/rel/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ func (t *Database) chooseIndex(
if best >= 0 && overlap.len() <= bestOverlap.len() {
continue
}
// Only allow queries to proceed with no index overlap if this is the
// zero-attribute index, which implies the database creator accepts bad
// query plans.
if overlap == 0 && len(dims[i].attrs) > 0 {
continue
}
if !dims[i].exists.isContainedIn(m.union(hasAttrs)) {
continue
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/schemachanger/rel/internal/cyclegraphtest/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var (
{container1, message1},
{container2, message2},
},
UnsatisfiableIndexes: []int{1},
},
{
Name: "oneOf member",
Expand Down
43 changes: 24 additions & 19 deletions pkg/sql/schemachanger/rel/internal/entitynodetest/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var (
{
Name: "a fields",
Query: rel.Clauses{
v("a").Type((*entity)(nil)),
v("a").AttrEq(i16, int16(1)),
v("a").AttrEqVar(i8, "ai8"),
v("a").AttrEqVar(pi8, "api8"),
Expand All @@ -109,7 +110,7 @@ var (
Results: [][]interface{}{
{a, int8(1), int8(1)},
},
UnsatisfiableIndexes: []int{2},
UnsatisfiableIndexes: []int{1, 2, 3, 5, 6},
},
{
Name: "a-c-b join",
Expand All @@ -125,7 +126,7 @@ var (
Results: [][]interface{}{
{a, b, c},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{2, 3, 4, 5, 6},
},
{
Name: "nil values don't show up",
Expand All @@ -137,7 +138,7 @@ var (
Results: [][]interface{}{
{a},
},
UnsatisfiableIndexes: []int{2},
UnsatisfiableIndexes: []int{2, 4, 5, 6},
},
{
Name: "nil values don't show up, scalar pointers same as pointers",
Expand All @@ -149,7 +150,7 @@ var (
Results: [][]interface{}{
{a},
},
UnsatisfiableIndexes: []int{2},
UnsatisfiableIndexes: []int{2, 4, 5, 6},
},
{
Name: "list all the values",
Expand All @@ -163,7 +164,7 @@ var (
{b, int8(2)},
{c, int8(2)},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6},
},
{
Name: "list all the values with type constraint",
Expand All @@ -178,6 +179,7 @@ var (
{b, int8(2)},
{c, int8(2)},
},
UnsatisfiableIndexes: []int{1, 2, 3, 5, 6},
},
{
Name: "nodes with elements where i8=2",
Expand All @@ -192,7 +194,7 @@ var (
{nb, b},
{nc, c},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{2, 3, 4, 5, 6},
},
{
Name: "list all the i8 values",
Expand All @@ -209,6 +211,7 @@ var (
{int8(2)},
{int8(2)},
},
UnsatisfiableIndexes: []int{1, 2, 3, 5, 6},
},
{
Name: "use a filter",
Expand All @@ -223,7 +226,7 @@ var (
Results: [][]interface{}{
{a},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6},
},
{
Name: "types of all the entities",
Expand All @@ -240,7 +243,7 @@ var (
{nb, reflect.TypeOf((*node)(nil))},
{nc, reflect.TypeOf((*node)(nil))},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6},
},
{
Name: "nodes by type",
Expand All @@ -255,7 +258,7 @@ var (
Results: [][]interface{}{
{na, nb, nc, a},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6},
},
{
Name: "list nodes",
Expand All @@ -269,6 +272,7 @@ var (
{nb},
{nc},
},
UnsatisfiableIndexes: []int{1, 2, 3, 5, 6},
},
{
Name: "basic any",
Expand All @@ -285,6 +289,7 @@ var (
{nb},
{nc},
},
UnsatisfiableIndexes: []int{1, 2, 3, 5, 6},
},
{
Name: "self eq value",
Expand All @@ -296,7 +301,7 @@ var (
Results: [][]interface{}{
{c},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3},
},
{
Name: "contradiction due to missing attribute",
Expand All @@ -307,7 +312,7 @@ var (
Entities: []v{"entity"},
ResVars: []v{"entity", "pi8"},
Results: [][]interface{}{},
UnsatisfiableIndexes: []int{2},
UnsatisfiableIndexes: []int{1, 2, 3},
},
{
Name: "self eq self",
Expand All @@ -319,7 +324,7 @@ var (
Results: [][]interface{}{
{a}, {b}, {c}, {na}, {nb}, {nc},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6},
},
{
Name: "variable type mismatch",
Expand All @@ -345,7 +350,7 @@ var (
{na, a, na, a},
{na, a, nc, c},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6},
},
{
Name: "entity bound via variable with ne filter",
Expand All @@ -365,7 +370,7 @@ var (
Results: [][]interface{}{
{na, a, nc, c},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6},
},
{
Name: "any value type mismatch",
Expand All @@ -385,7 +390,7 @@ var (
Entities: []v{"e"},
ResVars: []v{"e", "i8"},
Results: [][]interface{}{},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6},
},
{
Name: "pointer scalar values any",
Expand All @@ -397,7 +402,7 @@ var (
Results: [][]interface{}{
{a}, {b}, {c},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{2, 3, 4, 5, 6},
},
{
Name: "pointer scalar values",
Expand All @@ -409,7 +414,7 @@ var (
Results: [][]interface{}{
{a},
},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{2, 3, 4, 5, 6},
},
{
Name: "nil pointer scalar values any",
Expand All @@ -433,7 +438,7 @@ var (
Entities: []v{"e"},
ResVars: []v{"e"},
Results: [][]interface{}{},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{2, 3, 4, 5, 6},
},
{
Name: "any clause no match on variable eq",
Expand All @@ -444,7 +449,7 @@ var (
Entities: []v{"e"},
ResVars: []v{"e", "i8"},
Results: [][]interface{}{},
UnsatisfiableIndexes: []int{2, 3},
UnsatisfiableIndexes: []int{1, 2, 3, 4, 5, 6},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/schemachanger/rel/reltest/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type QueryTest struct {

func (tc DatabaseTest) run(t *testing.T, s Suite) {
for i, databaseIndexes := range tc.databaseIndexes() {
t.Run(fmt.Sprintf("%v", databaseIndexes), func(t *testing.T) {
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
db, err := rel.NewDatabase(s.Schema, databaseIndexes...)
require.NoError(t, err)
for _, k := range tc.Data {
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/schemachanger/rel/testdata/cyclegraph
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ queries:
results:
- [container1, message1]
- [container2, message2]
unsatisfiableIndexes: [1]
oneOf member:
query:
- $c[s] = struct1(message1)
Expand Down
Loading

0 comments on commit 1860eaa

Please sign in to comment.