Skip to content

Commit

Permalink
sql: add DisableNotVisibleIndex to ScanFlags
Browse files Browse the repository at this point in the history
This commit adds a flag to ScanFlags to indicate when the invisible index
feature should be enabled in buildScan. The invisible index feature should be
enabled by default but temporarily disabled during any unique or foreign key
constraint check. More details on how the decision was made and which flag to
pass in `docs/RFCS/20220628_invisible_index.md`. Note that no logic has been
added to the optimizer yet. This commit just passes the correct flag to
buildScan and shows the effect of the flag in the output of test data.

Assists: cockroachdb#72576

See also: cockroachdb#85354

Release note: none
  • Loading branch information
wenyihu6 committed Jul 30, 2022
1 parent 7bb42dc commit 2784fa1
Show file tree
Hide file tree
Showing 40 changed files with 1,473 additions and 857 deletions.
6 changes: 6 additions & 0 deletions pkg/sql/opt/memo/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ type ScanFlags struct {
Direction tree.Direction
Index int

// When the optimizer is performing unique constraint or foreign key
// constraint check, we will temporarily disable the not visible index feature
// and treat all indexes as they are visible. Default behaviour is to enable
// the not visible feature.
DisableNotVisibleIndex bool

// ZigzagIndexes makes planner prefer a zigzag with particular indexes.
// ForceZigzag must also be true.
ZigzagIndexes util.FastIntSet
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/opt/memo/expr_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ func (f *ExprFmtCtx) formatRelational(e RelExpr, tp treeprinter.Node) {
}
}
}
if private.Flags.DisableNotVisibleIndex {
b.WriteString(" disabled not visible index feature")
}
tp.Child(b.String())
}
f.formatLocking(tp, private.Locking)
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/opt/norm/testdata/rules/decorrelate
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ upsert xy
│ │ │ └── (3, 4)
│ │ ├── scan xy
│ │ │ ├── columns: x:7!null y:8
│ │ │ ├── flags: disabled not visible index feature
│ │ │ ├── key: (7)
│ │ │ └── fd: (7)-->(8)
│ │ └── filters
Expand Down
22 changes: 22 additions & 0 deletions pkg/sql/opt/norm/testdata/rules/groupby
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ upsert nullablecols
│ │ └── k:7 > 0 [outer=(7), constraints=(/7: [/1 - ]; tight)]
│ ├── scan nullablecols
│ │ ├── columns: c1:21 c2:22 c3:23 rowid:24!null
│ │ ├── flags: disabled not visible index feature
│ │ ├── key: (24)
│ │ └── fd: (24)-->(21-23), (21)~~>(22-24), (22,23)~~>(21,24)
│ └── filters
Expand Down Expand Up @@ -973,6 +974,7 @@ insert xy
│ │ └── CAST(NULL AS INT8) [as=y_default:9]
│ ├── scan xy
│ │ ├── columns: x:10!null
│ │ ├── flags: disabled not visible index feature
│ │ └── key: (10)
│ └── filters
│ └── y:6 = x:10 [outer=(6,10), constraints=(/6: (/NULL - ]; /10: (/NULL - ]), fd=(6)==(10), (10)==(6)]
Expand Down Expand Up @@ -1027,6 +1029,7 @@ upsert xy
│ │ └── CAST(NULL AS INT8) [as=y_default:9]
│ ├── scan xy
│ │ ├── columns: x:10!null y:11
│ │ ├── flags: disabled not visible index feature
│ │ ├── key: (10)
│ │ └── fd: (10)-->(11)
│ └── filters
Expand Down Expand Up @@ -1070,6 +1073,7 @@ insert xy
│ │ └── CAST(NULL AS INT8) [as=y_default:9]
│ ├── scan xy
│ │ ├── columns: x:10!null
│ │ ├── flags: disabled not visible index feature
│ │ └── key: (10)
│ └── filters
│ └── y:6 = x:10 [outer=(6,10), constraints=(/6: (/NULL - ]; /10: (/NULL - ]), fd=(6)==(10), (10)==(6)]
Expand Down Expand Up @@ -1127,6 +1131,7 @@ upsert xy
│ │ └── y_default:9
│ ├── scan xy
│ │ ├── columns: x:10!null y:11
│ │ ├── flags: disabled not visible index feature
│ │ ├── key: (10)
│ │ └── fd: (10)-->(11)
│ └── filters
Expand Down Expand Up @@ -1179,6 +1184,7 @@ upsert abc
│ └── "?column?":12
├── scan abc
│ ├── columns: a:13!null b:14!null c:15!null
│ ├── flags: disabled not visible index feature
│ └── key: (13-15)
└── filters
├── "?column?":11 = a:13 [outer=(11,13), constraints=(/11: (/NULL - ]; /13: (/NULL - ]), fd=(11)==(13), (13)==(11)]
Expand Down Expand Up @@ -1236,6 +1242,7 @@ upsert abc
│ │ └── b:7
│ ├── scan abc
│ │ ├── columns: a:12!null b:13!null c:14!null
│ │ ├── flags: disabled not visible index feature
│ │ └── key: (12-14)
│ └── filters
│ ├── "?column?":11 = a:12 [outer=(11,12), constraints=(/11: (/NULL - ]; /12: (/NULL - ]), fd=(11)==(12), (12)==(11)]
Expand Down Expand Up @@ -1704,6 +1711,7 @@ insert a
│ │ ├── fd: ()-->(22)
│ │ ├── scan a
│ │ │ ├── columns: i:20!null s:22!null
│ │ │ ├── flags: disabled not visible index feature
│ │ │ └── key: (20,22)
│ │ └── filters
│ │ └── s:22 = 'foo' [outer=(22), constraints=(/22: [/'foo' - /'foo']; tight), fd=()-->(22)]
Expand Down Expand Up @@ -1809,6 +1817,7 @@ upsert a
│ │ └── 'foo' [as="?column?":16]
│ ├── scan a
│ │ ├── columns: k:19!null i:20!null f:21 s:22!null j:23
│ │ ├── flags: disabled not visible index feature
│ │ ├── key: (19)
│ │ └── fd: (19)-->(20-23), (20,22)-->(19,21,23), (20,21)~~>(19,22,23)
│ └── filters
Expand Down Expand Up @@ -2133,6 +2142,7 @@ insert a
│ └── CAST(NULL AS JSONB) [as=j_default:12]
├── scan a
│ ├── columns: i:14!null s:16!null
│ ├── flags: disabled not visible index feature
│ └── key: (14,16)
└── filters
├── column3:10 = i:14 [outer=(10,14), constraints=(/10: (/NULL - ]; /14: (/NULL - ]), fd=(10)==(14), (14)==(10)]
Expand Down Expand Up @@ -2181,6 +2191,7 @@ upsert a
│ │ └── CAST(NULL AS JSONB) [as=j_default:12]
│ ├── scan a
│ │ ├── columns: k:13!null i:14!null f:15 s:16!null j:17
│ │ ├── flags: disabled not visible index feature
│ │ ├── key: (13)
│ │ └── fd: (13)-->(14-17), (14,16)-->(13,15,17), (14,15)~~>(13,16,17)
│ └── filters
Expand Down Expand Up @@ -2249,6 +2260,7 @@ upsert a
│ │ └── j_default:12
│ ├── scan a
│ │ ├── columns: k:13!null i:14!null f:15 s:16!null j:17
│ │ ├── flags: disabled not visible index feature
│ │ ├── key: (13)
│ │ └── fd: (13)-->(14-17), (14,16)-->(13,15,17), (14,15)~~>(13,16,17)
│ └── filters
Expand Down Expand Up @@ -2299,17 +2311,20 @@ insert a
│ │ │ └── CAST(NULL AS JSONB) [as=j_default:12]
│ │ ├── scan a
│ │ │ ├── columns: k:13!null
│ │ │ ├── flags: disabled not visible index feature
│ │ │ └── key: (13)
│ │ └── filters
│ │ └── column1:8 = k:13 [outer=(8,13), constraints=(/8: (/NULL - ]; /13: (/NULL - ]), fd=(8)==(13), (13)==(8)]
│ ├── scan a
│ │ ├── columns: i:21!null s:23!null
│ │ ├── flags: disabled not visible index feature
│ │ └── key: (21,23)
│ └── filters
│ ├── column3:10 = i:21 [outer=(10,21), constraints=(/10: (/NULL - ]; /21: (/NULL - ]), fd=(10)==(21), (21)==(10)]
│ └── column2:9 = s:23 [outer=(9,23), constraints=(/9: (/NULL - ]; /23: (/NULL - ]), fd=(9)==(23), (23)==(9)]
├── scan a
│ ├── columns: i:28!null f:29
│ ├── flags: disabled not visible index feature
│ └── lax-key: (28,29)
└── filters
├── column3:10 = i:28 [outer=(10,28), constraints=(/10: (/NULL - ]; /28: (/NULL - ]), fd=(10)==(28), (28)==(10)]
Expand Down Expand Up @@ -2371,17 +2386,20 @@ insert a
│ │ │ │ │ └── CAST(NULL AS JSONB) [as=j_default:12]
│ │ │ │ ├── scan a
│ │ │ │ │ ├── columns: k:13!null
│ │ │ │ │ ├── flags: disabled not visible index feature
│ │ │ │ │ └── key: (13)
│ │ │ │ └── filters
│ │ │ │ └── column1:8 = k:13 [outer=(8,13), constraints=(/8: (/NULL - ]; /13: (/NULL - ]), fd=(8)==(13), (13)==(8)]
│ │ │ ├── scan a
│ │ │ │ ├── columns: i:21!null s:23!null
│ │ │ │ ├── flags: disabled not visible index feature
│ │ │ │ └── key: (21,23)
│ │ │ └── filters
│ │ │ ├── i_default:11 = i:21 [outer=(11,21), constraints=(/11: (/NULL - ]; /21: (/NULL - ]), fd=(11)==(21), (21)==(11)]
│ │ │ └── column2:9 = s:23 [outer=(9,23), constraints=(/9: (/NULL - ]; /23: (/NULL - ]), fd=(9)==(23), (23)==(9)]
│ │ ├── scan a
│ │ │ ├── columns: i:28!null f:29
│ │ │ ├── flags: disabled not visible index feature
│ │ │ └── lax-key: (28,29)
│ │ └── filters
│ │ ├── i_default:11 = i:28 [outer=(11,28), constraints=(/11: (/NULL - ]; /28: (/NULL - ]), fd=(11)==(28), (28)==(11)]
Expand Down Expand Up @@ -2456,17 +2474,20 @@ insert a
│ │ │ │ └── CAST(NULL AS JSONB) [as=j_default:12]
│ │ │ ├── scan a
│ │ │ │ ├── columns: k:13!null
│ │ │ │ ├── flags: disabled not visible index feature
│ │ │ │ └── key: (13)
│ │ │ └── filters
│ │ │ └── column1:8 = k:13 [outer=(8,13), constraints=(/8: (/NULL - ]; /13: (/NULL - ]), fd=(8)==(13), (13)==(8)]
│ │ ├── scan a
│ │ │ ├── columns: i:21!null s:23!null
│ │ │ ├── flags: disabled not visible index feature
│ │ │ └── key: (21,23)
│ │ └── filters
│ │ ├── column3:10 = i:21 [outer=(10,21), constraints=(/10: (/NULL - ]; /21: (/NULL - ]), fd=(10)==(21), (21)==(10)]
│ │ └── column2:9 = s:23 [outer=(9,23), constraints=(/9: (/NULL - ]; /23: (/NULL - ]), fd=(9)==(23), (23)==(9)]
│ ├── scan a
│ │ ├── columns: i:28!null f:29
│ │ ├── flags: disabled not visible index feature
│ │ └── lax-key: (28,29)
│ └── filters
│ ├── column3:10 = i:28 [outer=(10,28), constraints=(/10: (/NULL - ]; /28: (/NULL - ]), fd=(10)==(28), (28)==(10)]
Expand Down Expand Up @@ -2521,6 +2542,7 @@ insert a
│ │ ├── fd: ()-->(21)
│ │ ├── scan a
│ │ │ ├── columns: i:19!null s:21!null
│ │ │ ├── flags: disabled not visible index feature
│ │ │ └── key: (19,21)
│ │ └── filters
│ │ └── s:21 = 'foo' [outer=(21), constraints=(/21: [/'foo' - /'foo']; tight), fd=()-->(21)]
Expand Down
Loading

0 comments on commit 2784fa1

Please sign in to comment.