gpdb icon indicating copy to clipboard operation
gpdb copied to clipboard

REINDEX the primary key result in a key conflict issue

Open cobolbaby opened this issue 1 year ago • 0 comments

Bug Report

Greenplum version or build

  • 6.26.3

OS version and uname -a

autoconf options used ( config.status --config )

Installation information ( pg_config )

Expected behavior

Actual behavior

select count(1) from dw.fact_sn_info where mcbsno = '4744PP5902'

-- 1

explain analyse 
select count(1) from dw.fact_sn_info where mcbsno = '4744PP5902'

/*
"Aggregate  (cost=0.00..6.00 rows=1 width=8) (actual time=0.632..0.632 rows=1 loops=1)"
"  ->  Gather Motion 20:1  (slice1; segments: 20)  (cost=0.00..6.00 rows=1 width=8) (actual time=0.024..0.618 rows=20 loops=1)"
"        ->  Aggregate  (cost=0.00..6.00 rows=1 width=8) (actual time=0.026..0.026 rows=1 loops=1)"
"              ->  Index Scan using fact_sn_info_pkey on fact_sn_info  (cost=0.00..6.00 rows=1 width=1) (actual time=0.052..0.053 rows=1 loops=1)"
"                    Index Cond: ((mcbsno)::text = '4744PP5902'::text)"
"Planning time: 20.500 ms"
"  (slice0)    Executor memory: 96K bytes."
"  (slice1)    Executor memory: 90K bytes avg x 20 workers, 90K bytes max (seg0)."
"Memory used:  262144kB"
"Optimizer: Pivotal Optimizer (GPORCA)"
"Execution time: 1.646 ms"	
*/
	
reindex index dw.fact_sn_info_pkey;

/*
ERROR:  Key (mcbsno)=(4744PP5902) is duplicated.could not create unique index "fact_sn_info_pkey"  (seg9 192.168.2.13:40001 pid=1173794) 

ERROR:  could not create unique index "fact_sn_info_pkey"  (seg9 192.168.2.13:40001 pid=1173794)
SQL state: 23505
Detail: Key (mcbsno)=(4744PP5902) is duplicated.
*/
CREATE TABLE IF NOT EXISTS dw.fact_sn_info
(
    orig_mcbsno character varying(11),
    mcbsno character varying(11) NOT NULL,
    ...,
    CONSTRAINT fact_sn_info_pkey PRIMARY KEY (mcbsno))

WITH (
    OIDS = FALSE
)
TABLESPACE tbs_ssd01
DISTRIBUTED BY (mcbsno)
;

Step to reproduce the behavior

cobolbaby avatar Apr 27 '24 07:04 cobolbaby