Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56b3b38

Browse files
committed
Fix incorrect index behavior in COPY FROM with partitioned tables
86b8504 rewrote how COPY FROM works to allow multiple tuple buffers toexist to once thus allowing multi-inserts to be used in more cases withpartitioned tables. That commit neglected to update the estate'ses_result_relation_info when flushing the insert buffer to the partitionmaking it possible for the index tuples to be added into an index on thewrong partition.Fix this and also add an Assert in ExecInsertIndexTuples to help ensurethat we never make this mistake again.Reported-by: Haruka TakatsukaAuthor: Ashutosh SharmaDiscussion:https://postgr.es/m/15832-b1bf336a4ee246b5@postgresql.org
1 parentf7e954a commit56b3b38

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

‎src/backend/commands/copy.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,9 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
24462446
ResultRelInfo*resultRelInfo=buffer->resultRelInfo;
24472447
TupleTableSlot**slots=buffer->slots;
24482448

2449+
/* Set es_result_relation_info to the ResultRelInfo we're flushing. */
2450+
estate->es_result_relation_info=resultRelInfo;
2451+
24492452
/*
24502453
* Print error context information correctly, if one of the operations
24512454
* below fail.

‎src/backend/executor/execIndexing.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
299299
indexInfoArray=resultRelInfo->ri_IndexRelationInfo;
300300
heapRelation=resultRelInfo->ri_RelationDesc;
301301

302+
/* Sanity check: slot must belong to the same rel as the resultRelInfo. */
303+
Assert(slot->tts_tableOid==RelationGetRelid(heapRelation));
304+
302305
/*
303306
* We will use the EState's per-tuple context for evaluating predicates
304307
* and index expressions (creating it if it's not already there).

‎src/test/regress/input/copy.source

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,17 @@ copy parted_copytest from '@abs_builddir@/results/parted_copytest.csv';
187187
select tableoid::regclass,count(*),sum(a) from parted_copytest
188188
group by tableoid order by tableoid::regclass::name;
189189

190+
truncate table parted_copytest;
191+
create index on parted_copytest (b);
192+
drop trigger part_ins_trig on parted_copytest_a2;
193+
194+
copy parted_copytest from stdin;
195+
11str1
196+
22str2
197+
\.
198+
199+
-- Ensure index entries were properly added during the copy.
200+
select * from parted_copytest where b = 1;
201+
select * from parted_copytest where b = 2;
202+
190203
drop table parted_copytest;

‎src/test/regress/output/copy.source

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,21 @@ group by tableoid order by tableoid::regclass::name;
147147
parted_copytest_a2 | 10 | 10055
148148
(2 rows)
149149

150+
truncate table parted_copytest;
151+
create index on parted_copytest (b);
152+
drop trigger part_ins_trig on parted_copytest_a2;
153+
copy parted_copytest from stdin;
154+
-- Ensure index entries were properly added during the copy.
155+
select * from parted_copytest where b = 1;
156+
a | b | c
157+
---+---+------
158+
1 | 1 | str1
159+
(1 row)
160+
161+
select * from parted_copytest where b = 2;
162+
a | b | c
163+
---+---+------
164+
2 | 2 | str2
165+
(1 row)
166+
150167
drop table parted_copytest;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp