Skip to content

Commit cfd2ce4

Browse files
zhangwenchao-123my-ship-it
authored andcommitted
Fix copy to replicated table display copy number is incorrect.
Reproduece SQL: CREATE TABLE test_rep(a int) DISTRIBUTED REPLICATED; INSERT INTO test_rep SELECT i FROM generate_series(1, 99) i; COPY test_rep TO 'tmp/rep.csv'; COPY test_rep FROM 'tmp/rep.csv'; The display copy row numbers will be RowNums * numsegments which is incorrect. In this commit, we fix this. Authored-by: Zhang Wenchao [email protected]
1 parent 06ae183 commit cfd2ce4

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/backend/commands/copy.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt,
440440
*processed = CopyDispatchOnSegment(stmt);
441441
else
442442
*processed = CopyFrom(cstate); /* copy from file to database */
443+
444+
/* Handle copy to replicated table returns processed number */
445+
if (Gp_role == GP_ROLE_DISPATCH && cstate->rel->rd_cdbpolicy &&
446+
cstate->rel->rd_cdbpolicy->ptype == POLICYTYPE_REPLICATED)
447+
*processed = *processed / cstate->rel->rd_cdbpolicy->numsegments;
443448
}
444449
PG_CATCH();
445450
{

src/test/isolation2/expected/ao_unique_index.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,20 @@ CREATE
390390
1: BEGIN;
391391
BEGIN
392392
1: COPY unique_index_ao_row FROM PROGRAM 'seq 1 10';
393-
COPY 30
393+
COPY 10
394394
-- concurrent tx inserting conflicting row should block.
395395
2&: COPY unique_index_ao_row FROM PROGRAM 'seq 1 1'; <waiting ...>
396396
-- concurrent tx inserting non-conflicting rows should be successful.
397397
3: COPY unique_index_ao_row FROM PROGRAM 'seq 11 20';
398-
COPY 30
398+
COPY 10
399399
-- inserting a conflicting row in the same transaction should ERROR out.
400400
1: COPY unique_index_ao_row FROM PROGRAM 'seq 1 1';
401401
ERROR: duplicate key value violates unique constraint "unique_index_ao_row_a_key"
402402
DETAIL: Key (a)=(1) already exists.
403403
CONTEXT: COPY unique_index_ao_row, line 1
404404
-- now that tx 1 was aborted, tx 2 is successful.
405405
2<: <... completed>
406-
COPY 3
406+
COPY 1
407407
1: END;
408408
END
409409

src/test/isolation2/expected/aocs_unique_index.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,20 @@ CREATE
390390
1: BEGIN;
391391
BEGIN
392392
1: COPY unique_index_ao_column FROM PROGRAM 'seq 1 10';
393-
COPY 30
393+
COPY 10
394394
-- concurrent tx inserting conflicting row should block.
395395
2&: COPY unique_index_ao_column FROM PROGRAM 'seq 1 1'; <waiting ...>
396396
-- concurrent tx inserting non-conflicting rows should be successful.
397397
3: COPY unique_index_ao_column FROM PROGRAM 'seq 11 20';
398-
COPY 30
398+
COPY 10
399399
-- inserting a conflicting row in the same transaction should ERROR out.
400400
1: COPY unique_index_ao_column FROM PROGRAM 'seq 1 1';
401401
ERROR: duplicate key value violates unique constraint "unique_index_ao_column_a_key"
402402
DETAIL: Key (a)=(1) already exists.
403403
CONTEXT: COPY unique_index_ao_column, line 1
404404
-- now that tx 1 was aborted, tx 2 is successful.
405405
2<: <... completed>
406-
COPY 3
406+
COPY 1
407407
1: END;
408408
END
409409

0 commit comments

Comments
 (0)