This issue entails a scenario that an unique index created on a partitioned table.
The issue can be reproduced via below steps:
#Create a partition table distributed with (a, b, c)
gpadmin=# CREATE TABLE foo1 (a int, b int, c int) DISTRIBUTED BY (a,b,c) PARTITION BY RANGE(a)
gpadmin-# (PARTITION p1 START (1) END (10000) INCLUSIVE,
gpadmin(# PARTITION p2 START (10001) END (100000) INCLUSIVE,
gpadmin(# PARTITION p3 START (100001) END (1000000) INCLUSIVE);
NOTICE: CREATE TABLE will create partition "foo1_1_prt_p1" for table "foo1"
NOTICE: CREATE TABLE will create partition "foo1_1_prt_p2" for table "foo1"
NOTICE: CREATE TABLE will create partition "foo1_1_prt_p3" for table "foo1"
CREATE TABLE
#Create UNIQUE index on DIFFERENT COLUMN ORDER from the distribution order
create unique index acb_idx on public.foo1 using btree(a,c,b);
#Add a parition p4
gpadmin=# alter table public.foo1 add partition p4 START (1000001) END (2000000) INCLUSIVE;
NOTICE: CREATE TABLE will create partition "foo1_1_prt_p4" for table "foo1"
ALTER TABLE
#Now we can find the partition p4's distribution key order is getting different from other leaf partitions including the root
gpadmin=# \d+ foo1_1_prt_p4
Table "public.foo1_1_prt_p4"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
a | integer | | plain | |
b | integer | | plain | |
c | integer | | plain | |
Indexes:
"foo1_1_prt_p4_a_c_b_idx" UNIQUE, btree (a, c, b)
Check constraints:
"foo1_1_prt_p4_check" CHECK (a >= 1000001 AND a <= 2000000)
Inherits: foo1
Distributed by: (a, c, b)
gpadmin=# \d+ foo1_1_prt_p3
Table "public.foo1_1_prt_p3"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
a | integer | | plain | |
b | integer | | plain | |
c | integer | | plain | |
Indexes:
"foo1_1_prt_p3_a_c_b_idx" UNIQUE, btree (a, c, b)
Check constraints:
"foo1_1_prt_p3_check" CHECK (a >= 100001 AND a <= 1000000)
Inherits: foo1
Distributed by: (a, b, c)
gpadmin=#
gpadmin=# \d+ foo1
Table "public.foo1"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+---------+--------------+-------------
a | integer | | plain | |
b | integer | | plain | |
c | integer | | plain | |
Indexes:
"acb_idx" UNIQUE, btree (a, c, b)
Child tables: foo1_1_prt_p1,
foo1_1_prt_p2,
foo1_1_prt_p3,
foo1_1_prt_p4
Distributed by: (a, b, c)
Partition by: (a)
Then you will see such error in the gpcheckcat log.
Related code for the defect
foreach(cell, index_stmt->indexParams) <- The unique index columns
{
IndexElem *iparam = lfirst(cell);
ListCell *dkcell;
// ...
foreach(dkcell, distrkeys) <- The distribution key columns
{
IndexElem *dk = (IndexElem *) lfirst(dkcell);
if (strcmp(dk->name, iparam->name) == 0)
{
// The columns in the newly created distribution key
// follow the unique index's columns order.
new_distrkeys = lappend(new_distrkeys, dk);
break;
}
}
}