Skip to content

Commit

Permalink
opt: don't add unique constraints with an index to test catalog
Browse files Browse the repository at this point in the history
This commit updates the test catalog so that it is consistent with the
real catalog and doesn't add unique constraints with an index to the
catalog table. This also prevents some tests from failing unnecessarily.

Release note: None
  • Loading branch information
rytaft committed Feb 17, 2021
1 parent 8a92681 commit 1892d2d
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 213 deletions.
24 changes: 12 additions & 12 deletions pkg/ccl/logictestccl/testdata/logic_test/partitioning
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ TABLE ok1
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
├── b int not null
└── partition by list prefixes
Expand Down Expand Up @@ -469,7 +469,7 @@ TABLE ok2
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
├── b int not null
└── partition by list prefixes
Expand Down Expand Up @@ -513,7 +513,7 @@ TABLE ok3
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
├── b int not null
└── partition by list prefixes
Expand Down Expand Up @@ -560,7 +560,7 @@ TABLE ok4
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
├── b int not null
└── partition by list prefixes
Expand Down Expand Up @@ -600,7 +600,7 @@ TABLE ok5
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
├── b int not null
└── partition by list prefixes
Expand Down Expand Up @@ -665,7 +665,7 @@ TABLE ok6
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
└── b int not null
scan ok6
Expand Down Expand Up @@ -702,7 +702,7 @@ TABLE ok7
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
└── b int not null
scan ok7
Expand Down Expand Up @@ -745,7 +745,7 @@ TABLE ok8
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
└── b int not null
scan ok8
Expand Down Expand Up @@ -790,7 +790,7 @@ TABLE ok9
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
└── b int not null
scan ok9
Expand Down Expand Up @@ -837,7 +837,7 @@ TABLE ok10
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
└── b int not null
scan ok10
Expand Down Expand Up @@ -893,7 +893,7 @@ TABLE ok11
├── c int not null
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
├── b int not null
├── c int not null
Expand Down Expand Up @@ -940,7 +940,7 @@ TABLE ok12
├── c int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
├── b int not null
└── partition by list prefixes
Expand Down
12 changes: 6 additions & 6 deletions pkg/ccl/logictestccl/testdata/logic_test/zone
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TABLE t
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_k_v (k, v)
├── INDEX primary
├── PRIMARY INDEX primary
│ ├── k int not null
│ └── ZONE
│ └── constraints: [+region=test,+dc=dc2]
Expand Down Expand Up @@ -91,7 +91,7 @@ TABLE t
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_k_v (k, v)
├── INDEX primary
├── PRIMARY INDEX primary
│ ├── k int not null
│ └── ZONE
│ └── constraints: [+region=test,+dc=dc2]
Expand Down Expand Up @@ -160,7 +160,7 @@ TABLE t
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_k_v (k, v)
├── INDEX primary
├── PRIMARY INDEX primary
│ ├── k int not null
│ └── ZONE
│ └── constraints: [+region=test,+dc=dc1]
Expand Down Expand Up @@ -272,7 +272,7 @@ TABLE t
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_k_v (k, v)
├── INDEX primary
├── PRIMARY INDEX primary
│ ├── k int not null
│ └── ZONE
│ ├── constraints: [+region=test]
Expand Down Expand Up @@ -329,7 +329,7 @@ TABLE t
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_k_v (k, v)
├── INDEX primary
├── PRIMARY INDEX primary
│ ├── k int not null
│ └── ZONE
│ ├── constraints: [+region=test]
Expand Down Expand Up @@ -440,7 +440,7 @@ TABLE t
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_k_v (k, v)
├── INDEX primary
├── PRIMARY INDEX primary
│ ├── k int not null
│ └── ZONE
│ ├── constraints: [+region=test]
Expand Down
12 changes: 8 additions & 4 deletions pkg/sql/opt/cat/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,19 @@ func FormatTable(cat Catalog, tab Table, tp treeprinter.Node) {
// debugging and testing.
func formatCatalogIndex(tab Table, ord int, tp treeprinter.Node) {
idx := tab.Index(ord)
inverted := ""
if idx.IsInverted() {
inverted = "INVERTED "
idxType := ""
if idx.Ordinal() == PrimaryIndex {
idxType = "PRIMARY "
} else if idx.IsUnique() {
idxType = "UNIQUE "
} else if idx.IsInverted() {
idxType = "INVERTED "
}
mutation := ""
if IsMutationIndex(tab, ord) {
mutation = " (mutation)"
}
child := tp.Childf("%sINDEX %s%s", inverted, idx.Name(), mutation)
child := tp.Childf("%sINDEX %s%s", idxType, idx.Name(), mutation)

var buf bytes.Buffer
colCount := idx.ColumnCount()
Expand Down
22 changes: 11 additions & 11 deletions pkg/sql/opt/exec/execbuilder/testdata/catalog
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TABLE xyz
├── z int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── INDEX primary
├── PRIMARY INDEX primary
│ └── x int not null
└── INDEX foo
├── z int
Expand Down Expand Up @@ -53,7 +53,7 @@ TABLE abcdef
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── CHECK (f > 2:::INT8)
└── INDEX primary
└── PRIMARY INDEX primary
└── rowid int not null default (unique_rowid()) [hidden]
scan abcdef
├── check constraint expressions
Expand Down Expand Up @@ -91,7 +91,7 @@ TABLE uvwxy
├── FAMILY fam_0_u_v_w (u, v, w)
├── FAMILY fam_1_x (x)
├── FAMILY fam_2_y (y)
└── INDEX primary
└── PRIMARY INDEX primary
├── u int not null
└── v int not null
scan uvwxy
Expand Down Expand Up @@ -119,7 +119,7 @@ TABLE child
├── r int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── INDEX primary
├── PRIMARY INDEX primary
│ └── c int not null
└── CONSTRAINT fk FOREIGN KEY child (p, q, r) REFERENCES parent (p, q, r)
scan child
Expand All @@ -134,7 +134,7 @@ TABLE parent
├── other int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── INDEX primary
├── PRIMARY INDEX primary
│ ├── p int not null
│ ├── q int not null
│ └── r int not null
Expand All @@ -161,7 +161,7 @@ TABLE child2
├── r int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── INDEX primary
├── PRIMARY INDEX primary
│ └── c int not null
└── CONSTRAINT fk FOREIGN KEY child2 (p, q, r) REFERENCES parent (p, q, r) MATCH FULL ON DELETE SET NULL
scan child2
Expand All @@ -176,7 +176,7 @@ TABLE parent
├── other int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── INDEX primary
├── PRIMARY INDEX primary
│ ├── p int not null
│ ├── q int not null
│ └── r int not null
Expand Down Expand Up @@ -213,7 +213,7 @@ TABLE a
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_a_other (a, other)
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
└── interleaved by
└── table=60 index=1
Expand All @@ -228,7 +228,7 @@ TABLE ab
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_a_b (a, b)
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
├── b int not null
├── interleave ancestors
Expand All @@ -249,7 +249,7 @@ TABLE abc
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_a_b_c_k (a, b, c, k)
├── INDEX primary
├── PRIMARY INDEX primary
│ └── k int not null
└── INDEX abc_idx
├── a int
Expand All @@ -271,7 +271,7 @@ TABLE abx
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_a_b_x (a, b, x)
└── INDEX primary
└── PRIMARY INDEX primary
├── a int not null
├── b int not null
├── x int not null
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/opt/exec/execbuilder/testdata/explain
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ TABLE tc
├── rowid int not null default (unique_rowid()) [hidden]
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── INDEX primary
├── PRIMARY INDEX primary
│ └── rowid int not null default (unique_rowid()) [hidden]
└── INDEX c
├── a int
Expand All @@ -1171,7 +1171,7 @@ TABLE tc
├── rowid int not null default (unique_rowid()) [hidden]
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
├── INDEX primary
├── PRIMARY INDEX primary
│ └── rowid int not null default (unique_rowid()) [hidden]
└── INDEX c
├── a int
Expand All @@ -1181,7 +1181,7 @@ TABLE t
├── v int
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── tableoid oid [hidden] [system]
└── INDEX primary
└── PRIMARY INDEX primary
└── k int not null
inner-join (hash)
├── columns: a:1 b:2 k:6 v:7
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/exec/execbuilder/testdata/virtual_columns
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ TABLE t
├── tableoid oid [hidden] [system]
├── FAMILY fam_0_a (a)
├── FAMILY fam_1_b (b)
└── INDEX primary
└── PRIMARY INDEX primary
└── a int not null
project
├── scan t
Expand Down
9 changes: 4 additions & 5 deletions pkg/sql/opt/optbuilder/testdata/inverted-indexes
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ TABLE kj
├── j jsonb
├── crdb_internal_mvcc_timestamp decimal [hidden] [system]
├── j_inverted_key jsonb not null [virtual-inverted]
├── INDEX primary
├── PRIMARY INDEX primary
│ └── k int not null
├── INVERTED INDEX secondary
│ ├── j_inverted_key jsonb not null [virtual-inverted]
│ └── k int not null
└── UNIQUE (k)
└── INVERTED INDEX secondary
├── j_inverted_key jsonb not null [virtual-inverted]
└── k int not null

build
SELECT j_inverted_key FROM kj
Expand Down
6 changes: 6 additions & 0 deletions pkg/sql/opt/testutils/testcat/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,12 @@ func (tc *Catalog) resolveFK(tab *Table, d *tree.ForeignKeyConstraintTableDef) {
func (tt *Table) addUniqueConstraint(
name tree.Name, columns tree.IndexElemList, predicate tree.Expr, withoutIndex bool,
) {
// We don't currently use unique constraints with an index (those are already
// tracked with unique indexes), so don't bother adding them.
// NB: This should stay consistent with opt_catalog.go.
if !withoutIndex {
return
}
cols := make([]int, len(columns))
for i, c := range columns {
cols[i] = tt.FindOrdinal(string(c.Column))
Expand Down
Loading

0 comments on commit 1892d2d

Please sign in to comment.