• H
    Disable changing distribution keys implicitly when creating unique index (#10510) · 84d2a23f
    Hao Wu 提交于
    In previous GPDB version, the distribution keys may be changed implicitly
    when creating a unique index on a hash-distributed empty table.
    ```SQL
    create table foo(a int, b int) distributed by(a);
    create unique index on foo(b);
    -- now, foo is hash distributed by b, not by a
    ```
    It might be useful(maybe) to avoid changing the distribution keys. However,
    on the other side, it's crazy if the user doesn't notice the NOTICE message
    like, "NOTICE:  updating distribution policy to match new UNIQUE index".
    
    What's worse, this behavior could bring data inconsistency. See,
    ```SQL
    create table foo(a int, b int) distributed by(a);
    insert into foo select i,i from generate_series(1,5)i;
    
    create table foopart (i int4, j int4) distributed by (i) partition by
            range (i) (start (1) end (3) every (1));
    create unique index on foopart_1_prt_1 (j);
    insert into foopart values(1,2),(2,1);
    ```
    The data inconsistency is
    ```
    gpadmin=# select gp_segment_id, * from foopart_1_prt_1;
     gp_segment_id | i | j
     ---------------+---+---
                 1 | 1 | 2
     (1 row)
    
    gpadmin=# select * from foo f, foopart_1_prt_1 p where f.a = p.j;
     a | b | i | j
     ---+---+---+---
     (0 rows)
    ```
    
    Implicitly changing the distribution keys is not very useful, but harmful.
    This PR disables changing the distribution keys when creating a unique index.
    Reviewed-by: NHubert Zhang <hzhang@pivotal.io>
    84d2a23f
gp_index.out 4.6 KB