# 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)
)

query TTTTTTTT colnames
SHOW PARTITIONS FROM DATABASE test
----
database_name table_name partition_name parent_partition column_names index_name partition_value zone_config
test t1 p1 NULL x t1@primary (1) NULL
test t1 p2 NULL x t1@primary (2) NULL
test t1 p3 NULL x t1@primary (3) NULL

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_config
test t1 p1 NULL x t1@primary (1) constraints = '[+dc=dc1]'
test t1 p2 NULL x t1@primary (2) constraints = '[+dc=dc2]'
test t1 p3 NULL x t1@primary (3) constraints = '[+dc=dc3]'

query TTTTTTTT
SHOW PARTITIONS FROM TABLE t1
----
test t1 p1 NULL x t1@primary (1) constraints = '[+dc=dc1]'
test t1 p2 NULL x t1@primary (2) constraints = '[+dc=dc2]'
test t1 p3 NULL x t1@primary (3) constraints = '[+dc=dc3]'

query TTTTTTTT
SHOW PARTITIONS FROM INDEX t1@primary
----
test t1 p1 NULL x t1@primary (1) constraints = '[+dc=dc1]'
test t1 p2 NULL x t1@primary (2) constraints = '[+dc=dc2]'
test t1 p3 NULL x t1@primary (3) constraints = '[+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)       constraints = '[+dc=dc1]'
test t1 p2 NULL x t1@primary     (2)       constraints = '[+dc=dc2]'
test t1 p3 NULL x t1@primary     (3)       constraints = '[+dc=dc3]'
test t2 p1 NULL x t2@primary  (1) TO (2)   constraints = '[+dc=dc1]'
test t2 p2 NULL x t2@primary  (2) TO (3)   constraints = '[+dc=dc2]'

query TTTTTTTT
SHOW PARTITIONS FROM TABLE t2
----
test t2 p1 NULL x t2@primary  (1) TO (2)  constraints = '[+dc=dc1]'
test t2 p2 NULL x t2@primary  (2) TO (3)  constraints = '[+dc=dc2]'

query TTTTTTTT
SHOW PARTITIONS FROM INDEX t2@primary
----
test t2 p1 NULL x t2@primary  (1) TO (2)  constraints = '[+dc=dc1]'
test t2 p2 NULL x t2@primary  (2) TO (3)  constraints = '[+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 INDEX t3@sec CONFIGURE ZONE USING constraints='[+dc=dc3]';
ALTER PARTITION p4 OF INDEX t3@sec CONFIGURE ZONE USING constraints='[+dc=dc4]'

query TTTTTTTT
SHOW PARTITIONS FROM TABLE t3
----
test t3 p1 NULL x t3@primary  (1)  constraints = '[+dc=dc1]'
test t3 p2 NULL x t3@primary  (2)  constraints = '[+dc=dc2]'
test t3 p3 NULL y t3@sec      (3)  constraints = '[+dc=dc3]'
test t3 p4 NULL y t3@sec      (4)  constraints = '[+dc=dc4]'

query TTTTTTTT
SHOW PARTITIONS FROM INDEX t3@*
----
test t3 p1 NULL x t3@primary  (1)  constraints = '[+dc=dc1]'
test t3 p2 NULL x t3@primary  (2)  constraints = '[+dc=dc2]'
test t3 p3 NULL y t3@sec      (3)  constraints = '[+dc=dc3]'
test t3 p4 NULL y t3@sec      (4)  constraints = '[+dc=dc4]'

query TTTTTTTT
SHOW PARTITIONS FROM INDEX t3@sec
----
test t3 p3 NULL y t3@sec      (3)  constraints = '[+dc=dc3]'
test t3 p4 NULL y t3@sec      (4)  constraints = '[+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)  constraints = '[+dc=dc1]'
test t4 p1_a p1   y t4@primary  (2)  constraints = '[+dc=dc2]'
test t4 p1_b p1   y t4@primary  (3)  constraints = '[+dc=dc3]'
test t4 p2   NULL x t4@primary  (4)  constraints = '[+dc=dc4]'
test t4 p2_a p2   y t4@primary  (5)  constraints = '[+dc=dc5]'
