From 56b3b3838284f53c83556592e60688522155f57f Mon Sep 17 00:00:00 2001 From: David Rowley Date: Wed, 5 Jun 2019 18:28:38 +1200 Subject: Fix incorrect index behavior in COPY FROM with partitioned tables 86b85044e rewrote how COPY FROM works to allow multiple tuple buffers to exist to once thus allowing multi-inserts to be used in more cases with partitioned tables. That commit neglected to update the estate's es_result_relation_info when flushing the insert buffer to the partition making it possible for the index tuples to be added into an index on the wrong partition. Fix this and also add an Assert in ExecInsertIndexTuples to help ensure that we never make this mistake again. Reported-by: Haruka Takatsuka Author: Ashutosh Sharma Discussion: https://postgr.es/m/15832-b1bf336a4ee246b5@postgresql.org --- src/backend/executor/execIndexing.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/backend/executor/execIndexing.c') diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c index c41c5f45e7e..40bd8049f05 100644 --- a/src/backend/executor/execIndexing.c +++ b/src/backend/executor/execIndexing.c @@ -299,6 +299,9 @@ ExecInsertIndexTuples(TupleTableSlot *slot, indexInfoArray = resultRelInfo->ri_IndexRelationInfo; heapRelation = resultRelInfo->ri_RelationDesc; + /* Sanity check: slot must belong to the same rel as the resultRelInfo. */ + Assert(slot->tts_tableOid == RelationGetRelid(heapRelation)); + /* * We will use the EState's per-tuple context for evaluating predicates * and index expressions (creating it if it's not already there). -- cgit v1.2.3