-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: Add support for a show partitions command.
SHOW PARTITIONS FROM TABLE <table> SHOW PARTITIONS FROM DATABASE <database> SHOW PARTITIONS FROM INDEX <index> Returns a table containing the following columns. * database_name * table_name * partition_name * parent_partition * column_names * index_name * partition_value * zone_constraints (NULL if no constraints were specified) To do this, changes were made to the crdb_internal.partitions table. Release note (sql change): Add support for a SHOW PARTITIONS command.
- Loading branch information
Showing
11 changed files
with
410 additions
and
22 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
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
139 changes: 139 additions & 0 deletions
139
pkg/ccl/logictestccl/testdata/logic_test/distsql_partitioning
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,139 @@ | ||
# LogicTest: 5node-dist | ||
|
||
# Tests for the show partitions command. | ||
|
||
statement ok | ||
CREATE TABLE t1 (x INT PRIMARY KEY) | ||
|
||
statement ok | ||
ALTER TABLE t1 PARTITION BY LIST (x) ( | ||
PARTITION p1 VALUES IN (1), | ||
PARTITION p2 VALUES IN (2), | ||
PARTITION p3 VALUES IN (3) | ||
) | ||
|
||
statement ok | ||
ALTER PARTITION p1 OF TABLE t1 CONFIGURE ZONE USING constraints='[+dc=dc1]'; | ||
ALTER PARTITION p2 OF TABLE t1 CONFIGURE ZONE USING constraints='[+dc=dc2]'; | ||
ALTER PARTITION p3 OF TABLE t1 CONFIGURE ZONE USING constraints='[+dc=dc3]' | ||
|
||
query TTTTTTTT colnames | ||
SHOW PARTITIONS FROM DATABASE test | ||
---- | ||
database_name table_name partition_name parent_partition column_names index_name partition_value zone_constraints | ||
test t1 p1 NULL x t1@primary (1) [+dc=dc1] | ||
test t1 p2 NULL x t1@primary (2) [+dc=dc2] | ||
test t1 p3 NULL x t1@primary (3) [+dc=dc3] | ||
|
||
query TTTTTTTT | ||
SHOW PARTITIONS FROM TABLE t1 | ||
---- | ||
test t1 p1 NULL x t1@primary (1) [+dc=dc1] | ||
test t1 p2 NULL x t1@primary (2) [+dc=dc2] | ||
test t1 p3 NULL x t1@primary (3) [+dc=dc3] | ||
|
||
query TTTTTTTT | ||
SHOW PARTITIONS FROM INDEX t1@primary | ||
---- | ||
test t1 p1 NULL x t1@primary (1) [+dc=dc1] | ||
test t1 p2 NULL x t1@primary (2) [+dc=dc2] | ||
test t1 p3 NULL x t1@primary (3) [+dc=dc3] | ||
|
||
statement ok | ||
CREATE TABLE t2 (x INT PRIMARY KEY) | ||
|
||
statement ok | ||
ALTER TABLE t2 PARTITION BY RANGE (x) ( | ||
PARTITION p1 VALUES FROM (1) TO (2), | ||
PARTITION p2 VALUES FROM (2) TO (3) | ||
) | ||
|
||
statement ok | ||
ALTER PARTITION p1 OF TABLE t2 CONFIGURE ZONE USING constraints='[+dc=dc1]'; | ||
ALTER PARTITION p2 OF TABLE t2 CONFIGURE ZONE USING constraints='[+dc=dc2]' | ||
|
||
query TTTTTTTT | ||
SHOW PARTITIONS FROM DATABASE test | ||
---- | ||
test t1 p1 NULL x t1@primary (1) [+dc=dc1] | ||
test t1 p2 NULL x t1@primary (2) [+dc=dc2] | ||
test t1 p3 NULL x t1@primary (3) [+dc=dc3] | ||
test t2 p1 NULL x t2@primary (1) TO (2) [+dc=dc1] | ||
test t2 p2 NULL x t2@primary (2) TO (3) [+dc=dc2] | ||
|
||
query TTTTTTTT | ||
SHOW PARTITIONS FROM TABLE t2 | ||
---- | ||
test t2 p1 NULL x t2@primary (1) TO (2) [+dc=dc1] | ||
test t2 p2 NULL x t2@primary (2) TO (3) [+dc=dc2] | ||
|
||
query TTTTTTTT | ||
SHOW PARTITIONS FROM INDEX t2@primary | ||
---- | ||
test t2 p1 NULL x t2@primary (1) TO (2) [+dc=dc1] | ||
test t2 p2 NULL x t2@primary (2) TO (3) [+dc=dc2] | ||
|
||
statement ok | ||
CREATE TABLE t3 (x INT PRIMARY KEY, y INT, INDEX sec (y)) | ||
|
||
statement ok | ||
ALTER TABLE t3 PARTITION BY LIST (x) ( | ||
PARTITION p1 VALUES IN (1), | ||
PARTITION p2 VALUES IN (2) | ||
) | ||
|
||
statement ok | ||
ALTER INDEX sec PARTITION BY LIST (y) ( | ||
PARTITION p3 VALUES IN (3), | ||
PARTITION p4 VALUES IN (4) | ||
) | ||
|
||
statement ok | ||
ALTER PARTITION p1 OF TABLE t3 CONFIGURE ZONE USING constraints='[+dc=dc1]'; | ||
ALTER PARTITION p2 OF TABLE t3 CONFIGURE ZONE USING constraints='[+dc=dc2]'; | ||
ALTER PARTITION p3 OF TABLE t3 CONFIGURE ZONE USING constraints='[+dc=dc3]'; | ||
ALTER PARTITION p4 OF TABLE t3 CONFIGURE ZONE USING constraints='[+dc=dc4]' | ||
|
||
query TTTTTTTT | ||
SHOW PARTITIONS FROM TABLE t3 | ||
---- | ||
test t3 p1 NULL x t3@primary (1) [+dc=dc1] | ||
test t3 p2 NULL x t3@primary (2) [+dc=dc2] | ||
test t3 p3 NULL y t3@sec (3) [+dc=dc3] | ||
test t3 p4 NULL y t3@sec (4) [+dc=dc4] | ||
|
||
query TTTTTTTT | ||
SHOW PARTITIONS FROM INDEX t3@sec | ||
---- | ||
test t3 p3 NULL y t3@sec (3) [+dc=dc3] | ||
test t3 p4 NULL y t3@sec (4) [+dc=dc4] | ||
|
||
statement ok | ||
CREATE TABLE t4 (x INT, y INT, PRIMARY KEY (x, y)) | ||
|
||
statement ok | ||
ALTER TABLE t4 PARTITION BY LIST (x) ( | ||
PARTITION p1 VALUES IN (1) PARTITION BY LIST (y) ( | ||
PARTITION p1_a VALUES in (2), | ||
PARTITION p1_b VALUES IN (3) | ||
), | ||
PARTITION p2 VALUES IN (4) PARTITION BY LIST (y) ( | ||
PARTITION p2_a VALUES IN (5) | ||
) | ||
) | ||
|
||
statement ok | ||
ALTER PARTITION p1 OF TABLE t4 CONFIGURE ZONE USING constraints='[+dc=dc1]'; | ||
ALTER PARTITION p1_a OF TABLE t4 CONFIGURE ZONE USING constraints='[+dc=dc2]'; | ||
ALTER PARTITION p1_b OF TABLE t4 CONFIGURE ZONE USING constraints='[+dc=dc3]'; | ||
ALTER PARTITION p2 OF TABLE t4 CONFIGURE ZONE USING constraints='[+dc=dc4]'; | ||
ALTER PARTITION p2_a OF TABLE t4 CONFIGURE ZONE USING constraints='[+dc=dc5]' | ||
|
||
query TTTTTTTT | ||
SHOW PARTITIONS FROM TABLE t4 | ||
---- | ||
test t4 p1 NULL x t4@primary (1) [+dc=dc1] | ||
test t4 p1_a p1 y t4@primary (2) [+dc=dc2] | ||
test t4 p1_b p1 y t4@primary (3) [+dc=dc3] | ||
test t4 p2 NULL x t4@primary (4) [+dc=dc4] | ||
test t4 p2_a p2 y t4@primary (5) [+dc=dc5] |
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.