-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: Prefer index with zone constraints that most closely match locality
Customers can create multiple indexes that are identical, except that they have different locality constraints. This commit teaches the optimizer to prefer the index that most closely matches the locality of the gateway node that is planning the query. This enables scenarios where reference data like a zip code table can be replicated to different regions, and queries will use the copy in the same region. Release note: None
- Loading branch information
1 parent
0468b72
commit 621fa6d
Showing
17 changed files
with
652 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# LogicTest: 5node-dist-opt | ||
|
||
# Ensure that cost-based-optimizer uses an index with zone constraints that most | ||
# closely matches the gateway's locality. | ||
|
||
statement ok | ||
CREATE TABLE t ( | ||
k INT PRIMARY KEY, | ||
v STRING, | ||
INDEX secondary (k) STORING (v) | ||
); | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Put table in dc2 and secondary index in dc1 so that the gateway matches the | ||
# secondary index rather the primary index. | ||
# ------------------------------------------------------------------------------ | ||
|
||
statement ok | ||
ALTER TABLE t CONFIGURE ZONE USING constraints='[+region=test,+dc=dc2]' | ||
|
||
statement ok | ||
ALTER INDEX t@secondary CONFIGURE ZONE USING constraints='[+region=test,+dc=dc1]' | ||
|
||
query TTT | ||
EXPLAIN SELECT * FROM t WHERE k=10 | ||
---- | ||
scan · · | ||
· table t@secondary | ||
· spans /10-/11 | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Swap location of primary and secondary indexes and ensure that primary index | ||
# is used instead. | ||
# ------------------------------------------------------------------------------ | ||
|
||
statement ok | ||
ALTER TABLE t CONFIGURE ZONE USING constraints='[+region=test,+dc=dc1]' | ||
|
||
statement ok | ||
ALTER INDEX t@secondary CONFIGURE ZONE USING constraints='[+region=test,+dc=dc2]' | ||
|
||
query TTT | ||
EXPLAIN SELECT * FROM t WHERE k=10 | ||
---- | ||
scan · · | ||
· table t@primary | ||
· spans /10-/10/# | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Use PREPARE to make sure that the prepared plan is invalidated when the | ||
# secondary index's constraints change. | ||
# ------------------------------------------------------------------------------ | ||
|
||
statement | ||
PREPARE p AS SELECT tree, field, description FROM [EXPLAIN SELECT k, v FROM t WHERE k=10] | ||
|
||
query TTT | ||
EXECUTE p | ||
---- | ||
scan · · | ||
· table t@primary | ||
· spans /10-/10/# | ||
|
||
statement ok | ||
ALTER TABLE t CONFIGURE ZONE USING constraints='[+region=test,+dc=dc2]' | ||
|
||
statement ok | ||
ALTER INDEX t@secondary CONFIGURE ZONE USING constraints='[+region=test,+dc=dc1]' | ||
|
||
query TTT | ||
EXECUTE p | ||
---- | ||
scan · · | ||
· table t@secondary | ||
· spans /10-/11 |
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
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
Oops, something went wrong.