Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1add0b1

Browse files
committed
Fix COPY's handling of transition tables with indexes.
Commit c46c0e5 failed to pass the TransitionCaptureState object to ExecARInsertTriggers() in the case where it's using heap_multi_insert and there are indexes. Repair. Thomas Munro, from a report by David Fetter Discussion: https://postgr.es/m/20170708084213.GA14720%40fetter.org
1 parent 7b02ba6 commit 1add0b1

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/backend/commands/copy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,7 @@ CopyFromInsertBatch(CopyState cstate, EState *estate, CommandId mycid,
29152915
estate, false, NULL, NIL);
29162916
ExecARInsertTriggers(estate, resultRelInfo,
29172917
bufferedTuples[i],
2918-
recheckIndexes, NULL);
2918+
recheckIndexes, cstate->transition_capture);
29192919
list_free(recheckIndexes);
29202920
}
29212921
}

src/test/regress/expected/triggers.out

+6-1
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,11 @@ NOTICE: trigger = child3_delete_trig, old table = (CCC,42,foo)
21562156
-- are really inserted into the parent)
21572157
copy parent (a, b) from stdin;
21582158
NOTICE: trigger = parent_insert_trig, new table = (AAA,42), (BBB,42), (CCC,42)
2159+
-- same behavior for copy if there is an index (interesting because rows are
2160+
-- captured by a different code path in copy.c if there are indexes)
2161+
create index on parent(b);
2162+
copy parent (a, b) from stdin;
2163+
NOTICE: trigger = parent_insert_trig, new table = (DDD,42)
21592164
-- DML affecting parent sees tuples collected from children even if
21602165
-- there is no transition table trigger on the children
21612166
drop trigger child1_insert_trig on child1;
@@ -2168,7 +2173,7 @@ drop trigger child3_insert_trig on child3;
21682173
drop trigger child3_update_trig on child3;
21692174
drop trigger child3_delete_trig on child3;
21702175
delete from parent;
2171-
NOTICE: trigger = parent_delete_trig, old table = (AAA,42), (BBB,42), (CCC,42)
2176+
NOTICE: trigger = parent_delete_trig, old table = (AAA,42), (BBB,42), (CCC,42), (DDD,42)
21722177
drop table child1, child2, child3, parent;
21732178
--
21742179
-- Verify prohibition of row triggers with transition triggers on

src/test/regress/sql/triggers.sql

+7
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,13 @@ BBB 42
16611661
CCC 42
16621662
\.
16631663

1664+
-- same behavior for copy if there is an index (interesting because rows are
1665+
-- captured by a different code path in copy.c if there are indexes)
1666+
create index on parent(b);
1667+
copy parent (a, b) from stdin;
1668+
DDD 42
1669+
\.
1670+
16641671
-- DML affecting parent sees tuples collected from children even if
16651672
-- there is no transition table trigger on the children
16661673
drop trigger child1_insert_trig on child1;

0 commit comments

Comments
 (0)