create_distributed_table doesn't create INVALID indexes properly
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
```SQL
create table part ( a int, list varchar(5) ) partition by list (list);
create table part_1 partition of part for values in ('beer');
create table part_2 partition of part for values in ('wine');
create index i_test_1 on only part_1 (a);
create index i_test on only part (a);
SELECT create_distributed_table('part', 'a');
-- now check the index states
-- as expected the parent index is markes as INVALID
\d part
Partitioned table "public.part"
Column | Type | Collation | Nullable | Default
--------+----------------------+-----------+----------+---------
a | integer | | |
list | character varying(5) | | |
Partition key: LIST (list)
Indexes:
"i_test" btree (a) INVALID
Number of partitions: 2 (Use \d+ to list them.)
-- now, connect to a worker node and pick a shard
-- the index on the parent shard IS NOT INVALID
\d+ part_102104
Partitioned table "public.part_102104"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+----------------------+-----------+----------+---------+----------+--------------+-------------
a | integer | | | | plain | |
list | character varying(5) | | | | extended | |
Partition key: LIST (list)
Indexes:
"i_test_102104" btree (a)
Partitions: part_1_102136 FOR VALUES IN ('beer'),
part_2_102168 FOR VALUES IN ('wine')
-- and, the second partition has also index WHICH IT SHOULDN"T have
\d part_2_102168
Table "public.part_2_102168"
Column | Type | Collation | Nullable | Default
--------+----------------------+-----------+----------+---------
a | integer | | |
list | character varying(5) | | |
Partition of: part_102104 FOR VALUES IN ('wine')
Indexes:
"part_2_102168_a_idx" btree (a)
-- now connect back to the coordinator, create index on partition
create index i_test_2 on only part_2 (a);
-- now attach the first index
alter index i_test attach partition i_test_1;
-- and the ATTACHING the second index fails
alter index i_test attach partition i_test_2;
ERROR: cannot attach index "i_test_2" as a partition of index "i_test"
DETAIL: Another index is already attached for partition "part_2".
CONTEXT: while executing command on localhost:9700
```
Contributor guide
Assessment
This issue has not been assessed yet.