# LogicTest: 5node

# 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 TTTTTTTTT colnames
SELECT * FROM [SHOW PARTITIONS FROM DATABASE test] ORDER BY partition_name
----
database_name  table_name  partition_name  parent_partition  column_names  index_name  partition_value  zone_config  full_zone_config
test           t1          p1              NULL              x             t1@t1_pkey  (1)              NULL         range_min_bytes = 134217728,
                                                                                                                     range_max_bytes = 536870912,
                                                                                                                     gc.ttlseconds = 14400,
                                                                                                                     num_replicas = 3,
                                                                                                                     constraints = '[]',
                                                                                                                     lease_preferences = '[]'
test           t1          p2              NULL              x             t1@t1_pkey  (2)              NULL         range_min_bytes = 134217728,
                                                                                                                     range_max_bytes = 536870912,
                                                                                                                     gc.ttlseconds = 14400,
                                                                                                                     num_replicas = 3,
                                                                                                                     constraints = '[]',
                                                                                                                     lease_preferences = '[]'
test           t1          p3              NULL              x             t1@t1_pkey  (3)              NULL         range_min_bytes = 134217728,
                                                                                                                     range_max_bytes = 536870912,
                                                                                                                     gc.ttlseconds = 14400,
                                                                                                                     num_replicas = 3,
                                                                                                                     constraints = '[]',
                                                                                                                     lease_preferences = '[]'

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 TTTTTTTTT colnames
SELECT * FROM [SHOW PARTITIONS FROM DATABASE test] ORDER BY partition_name
----
database_name  table_name  partition_name  parent_partition  column_names  index_name  partition_value  zone_config                full_zone_config
test           t1          p1              NULL              x             t1@t1_pkey  (1)              constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                                                                                   range_max_bytes = 536870912,
                                                                                                                                   gc.ttlseconds = 14400,
                                                                                                                                   num_replicas = 3,
                                                                                                                                   constraints = '[+dc=dc1]',
                                                                                                                                   lease_preferences = '[]'
test           t1          p2              NULL              x             t1@t1_pkey  (2)              constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                                                                                   range_max_bytes = 536870912,
                                                                                                                                   gc.ttlseconds = 14400,
                                                                                                                                   num_replicas = 3,
                                                                                                                                   constraints = '[+dc=dc2]',
                                                                                                                                   lease_preferences = '[]'
test           t1          p3              NULL              x             t1@t1_pkey  (3)              constraints = '[+dc=dc3]'  range_min_bytes = 134217728,
                                                                                                                                   range_max_bytes = 536870912,
                                                                                                                                   gc.ttlseconds = 14400,
                                                                                                                                   num_replicas = 3,
                                                                                                                                   constraints = '[+dc=dc3]',
                                                                                                                                   lease_preferences = '[]'

query TTTTTTTTT
SELECT * FROM [SHOW PARTITIONS FROM TABLE t1] ORDER BY partition_name
----
test  t1  p1  NULL  x  t1@t1_pkey  (1)  constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc1]',
                                                                   lease_preferences = '[]'
test  t1  p2  NULL  x  t1@t1_pkey  (2)  constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc2]',
                                                                   lease_preferences = '[]'
test  t1  p3  NULL  x  t1@t1_pkey  (3)  constraints = '[+dc=dc3]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc3]',
                                                                   lease_preferences = '[]'

query TTTTTTTTT
SELECT * FROM [SHOW PARTITIONS FROM INDEX t1@t1_pkey] ORDER BY partition_name
----
test  t1  p1  NULL  x  t1@t1_pkey  (1)  constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc1]',
                                                                   lease_preferences = '[]'
test  t1  p2  NULL  x  t1@t1_pkey  (2)  constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc2]',
                                                                   lease_preferences = '[]'
test  t1  p3  NULL  x  t1@t1_pkey  (3)  constraints = '[+dc=dc3]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc3]',
                                                                   lease_preferences = '[]'

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 TTTTTTTTT
SELECT * FROM [SHOW PARTITIONS FROM DATABASE test] ORDER BY table_name, partition_name
----
test  t1  p1  NULL  x  t1@t1_pkey  (1)         constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                          range_max_bytes = 536870912,
                                                                          gc.ttlseconds = 14400,
                                                                          num_replicas = 3,
                                                                          constraints = '[+dc=dc1]',
                                                                          lease_preferences = '[]'
test  t1  p2  NULL  x  t1@t1_pkey  (2)         constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                          range_max_bytes = 536870912,
                                                                          gc.ttlseconds = 14400,
                                                                          num_replicas = 3,
                                                                          constraints = '[+dc=dc2]',
                                                                          lease_preferences = '[]'
test  t1  p3  NULL  x  t1@t1_pkey  (3)         constraints = '[+dc=dc3]'  range_min_bytes = 134217728,
                                                                          range_max_bytes = 536870912,
                                                                          gc.ttlseconds = 14400,
                                                                          num_replicas = 3,
                                                                          constraints = '[+dc=dc3]',
                                                                          lease_preferences = '[]'
test  t2  p1  NULL  x  t2@t2_pkey  (1) TO (2)  constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                          range_max_bytes = 536870912,
                                                                          gc.ttlseconds = 14400,
                                                                          num_replicas = 3,
                                                                          constraints = '[+dc=dc1]',
                                                                          lease_preferences = '[]'
test  t2  p2  NULL  x  t2@t2_pkey  (2) TO (3)  constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                          range_max_bytes = 536870912,
                                                                          gc.ttlseconds = 14400,
                                                                          num_replicas = 3,
                                                                          constraints = '[+dc=dc2]',
                                                                          lease_preferences = '[]'

query TTTTTTTTT
SELECT * FROM [SHOW PARTITIONS FROM TABLE t2] ORDER BY partition_name
----
test  t2  p1  NULL  x  t2@t2_pkey  (1) TO (2)  constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                          range_max_bytes = 536870912,
                                                                          gc.ttlseconds = 14400,
                                                                          num_replicas = 3,
                                                                          constraints = '[+dc=dc1]',
                                                                          lease_preferences = '[]'
test  t2  p2  NULL  x  t2@t2_pkey  (2) TO (3)  constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                          range_max_bytes = 536870912,
                                                                          gc.ttlseconds = 14400,
                                                                          num_replicas = 3,
                                                                          constraints = '[+dc=dc2]',
                                                                          lease_preferences = '[]'

query TTTTTTTTT
SELECT * FROM [SHOW PARTITIONS FROM INDEX t2@t2_pkey] ORDER BY partition_name
----
test  t2  p1  NULL  x  t2@t2_pkey  (1) TO (2)  constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                          range_max_bytes = 536870912,
                                                                          gc.ttlseconds = 14400,
                                                                          num_replicas = 3,
                                                                          constraints = '[+dc=dc1]',
                                                                          lease_preferences = '[]'
test  t2  p2  NULL  x  t2@t2_pkey  (2) TO (3)  constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                          range_max_bytes = 536870912,
                                                                          gc.ttlseconds = 14400,
                                                                          num_replicas = 3,
                                                                          constraints = '[+dc=dc2]',
                                                                          lease_preferences = '[]'

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 TTTTTTTTT
SELECT * FROM [SHOW PARTITIONS FROM TABLE t3] ORDER BY partition_name
----
test  t3  p1  NULL  x  t3@t3_pkey  (1)  constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc1]',
                                                                   lease_preferences = '[]'
test  t3  p2  NULL  x  t3@t3_pkey  (2)  constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc2]',
                                                                   lease_preferences = '[]'
test  t3  p3  NULL  y  t3@sec      (3)  constraints = '[+dc=dc3]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc3]',
                                                                   lease_preferences = '[]'
test  t3  p4  NULL  y  t3@sec      (4)  constraints = '[+dc=dc4]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc4]',
                                                                   lease_preferences = '[]'

query TTTTTTTTT
SELECT * FROM [SHOW PARTITIONS FROM INDEX t3@*] ORDER BY partition_name
----
test  t3  p1  NULL  x  t3@t3_pkey  (1)  constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc1]',
                                                                   lease_preferences = '[]'
test  t3  p2  NULL  x  t3@t3_pkey  (2)  constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc2]',
                                                                   lease_preferences = '[]'
test  t3  p3  NULL  y  t3@sec      (3)  constraints = '[+dc=dc3]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc3]',
                                                                   lease_preferences = '[]'
test  t3  p4  NULL  y  t3@sec      (4)  constraints = '[+dc=dc4]'  range_min_bytes = 134217728,
                                                                   range_max_bytes = 536870912,
                                                                   gc.ttlseconds = 14400,
                                                                   num_replicas = 3,
                                                                   constraints = '[+dc=dc4]',
                                                                   lease_preferences = '[]'

query TTTTTTTTT
SELECT * FROM [SHOW PARTITIONS FROM INDEX t3@sec] ORDER BY partition_name
----
test  t3  p3  NULL  y  t3@sec  (3)  constraints = '[+dc=dc3]'  range_min_bytes = 134217728,
                                                               range_max_bytes = 536870912,
                                                               gc.ttlseconds = 14400,
                                                               num_replicas = 3,
                                                               constraints = '[+dc=dc3]',
                                                               lease_preferences = '[]'
test  t3  p4  NULL  y  t3@sec  (4)  constraints = '[+dc=dc4]'  range_min_bytes = 134217728,
                                                               range_max_bytes = 536870912,
                                                               gc.ttlseconds = 14400,
                                                               num_replicas = 3,
                                                               constraints = '[+dc=dc4]',
                                                               lease_preferences = '[]'

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 TTTTTTTTT
SELECT * FROM [SHOW PARTITIONS FROM TABLE t4] ORDER BY partition_name
----
test  t4  p1    NULL  x  t4@t4_pkey  (1)  constraints = '[+dc=dc1]'  range_min_bytes = 134217728,
                                                                     range_max_bytes = 536870912,
                                                                     gc.ttlseconds = 14400,
                                                                     num_replicas = 3,
                                                                     constraints = '[+dc=dc1]',
                                                                     lease_preferences = '[]'
test  t4  p1_a  p1    y  t4@t4_pkey  (2)  constraints = '[+dc=dc2]'  range_min_bytes = 134217728,
                                                                     range_max_bytes = 536870912,
                                                                     gc.ttlseconds = 14400,
                                                                     num_replicas = 3,
                                                                     constraints = '[+dc=dc2]',
                                                                     lease_preferences = '[]'
test  t4  p1_b  p1    y  t4@t4_pkey  (3)  constraints = '[+dc=dc3]'  range_min_bytes = 134217728,
                                                                     range_max_bytes = 536870912,
                                                                     gc.ttlseconds = 14400,
                                                                     num_replicas = 3,
                                                                     constraints = '[+dc=dc3]',
                                                                     lease_preferences = '[]'
test  t4  p2    NULL  x  t4@t4_pkey  (4)  constraints = '[+dc=dc4]'  range_min_bytes = 134217728,
                                                                     range_max_bytes = 536870912,
                                                                     gc.ttlseconds = 14400,
                                                                     num_replicas = 3,
                                                                     constraints = '[+dc=dc4]',
                                                                     lease_preferences = '[]'
test  t4  p2_a  p2    y  t4@t4_pkey  (5)  constraints = '[+dc=dc5]'  range_min_bytes = 134217728,
                                                                     range_max_bytes = 536870912,
                                                                     gc.ttlseconds = 14400,
                                                                     num_replicas = 3,
                                                                     constraints = '[+dc=dc5]',
                                                                     lease_preferences = '[]'

# Partitioning inheritance test.
statement ok
CREATE DATABASE partitioning

statement ok
CREATE TABLE partitioning.inheritance (x INT PRIMARY KEY)

statement ok
ALTER INDEX partitioning.inheritance@inheritance_pkey PARTITION BY LIST (x) ( PARTITION p1 VALUES IN (1))

statement ok
ALTER DATABASE partitioning CONFIGURE ZONE USING range_min_bytes=64000, range_max_bytes=75000000

query TTTTTTTTT
SHOW PARTITIONS FROM TABLE partitioning.inheritance
----
partitioning  inheritance  p1  NULL  x  inheritance@inheritance_pkey  (1)  NULL  range_min_bytes = 64000,
                                                                                 range_max_bytes = 75000000,
                                                                                 gc.ttlseconds = 14400,
                                                                                 num_replicas = 3,
                                                                                 constraints = '[]',
                                                                                 lease_preferences = '[]'

statement ok
ALTER TABLE partitioning.inheritance CONFIGURE ZONE USING gc.ttlseconds=80000

query TTTTTTTTT
SHOW PARTITIONS FROM TABLE partitioning.inheritance
----
partitioning  inheritance  p1  NULL  x  inheritance@inheritance_pkey  (1)  NULL  range_min_bytes = 64000,
range_max_bytes = 75000000,
gc.ttlseconds = 80000,
num_replicas = 3,
constraints = '[]',
lease_preferences = '[]'

statement ok
ALTER INDEX partitioning.inheritance@inheritance_pkey CONFIGURE ZONE USING num_replicas=5

query TTTTTTTTT
SHOW PARTITIONS FROM TABLE partitioning.inheritance
----
partitioning  inheritance  p1  NULL  x  inheritance@inheritance_pkey  (1)  NULL  range_min_bytes = 64000,
range_max_bytes = 75000000,
gc.ttlseconds = 80000,
num_replicas = 5,
constraints = '[]',
lease_preferences = '[]'

statement ok
ALTER PARTITION p1 OF INDEX partitioning.inheritance@inheritance_pkey CONFIGURE ZONE USING constraints='[+dc=dc1]'

query TTTTTTTTT
SHOW PARTITIONS FROM TABLE partitioning.inheritance
----
partitioning  inheritance  p1  NULL  x  inheritance@inheritance_pkey  (1)  constraints = '[+dc=dc1]'  range_min_bytes = 64000,
range_max_bytes = 75000000,
gc.ttlseconds = 80000,
num_replicas = 5,
constraints = '[+dc=dc1]',
lease_preferences = '[]'
