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

Commitf7c830f

Browse files
committed
Fix missing calls to table_finish_bulk_insert during COPY, take 2
86b8504 abstracted calls to heap functions in COPY FROM to support ageneric table AM. However, when performing a copy into a partitionedtable, this commit neglected to call table_finish_bulk_insert for eachpartition. Before86b8504, when we always called the heap functions,there was no need to call heapam_finish_bulk_insert for partitions sinceit only did any work when performing a copy without WAL. For partitionedtables, this was unsupported anyway, so there was no issue. Withpluggable storage, we can't make any assumptions about what the table AMmight want to do in its equivalent function, so we'd better ensure wealways call table_finish_bulk_insert each partition that's received a row.For now, we make the table_finish_bulk_insert call whenever we evict aCopyMultiInsertBuffer out of the CopyMultiInsertInfo. This does meanthat it's possible that we call table_finish_bulk_insert multiple timesper partition, which is not a problem other than being an inefficiency.Improving this requires a more invasive patch, so let's leave that foranother day.This also changes things so that we no longer needlessly calltable_finish_bulk_insert when performing a COPY FROM for a non-partitionedtable when not using multi-inserts.Reported-by: Robert HaasBackpatch-through: 12Discussion:https://postgr.es/m/CA+TgmoYK=6BpxiJ0tN-p9wtH0BTAfbdxzHhwou0mdud4+BkYuQ@mail.gmail.com
1 parentbd56cd7 commitf7c830f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

‎src/backend/commands/copy.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,8 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
25182518
* The buffer must be flushed before cleanup.
25192519
*/
25202520
staticinlinevoid
2521-
CopyMultiInsertBufferCleanup(CopyMultiInsertBuffer*buffer)
2521+
CopyMultiInsertBufferCleanup(CopyMultiInsertInfo*miinfo,
2522+
CopyMultiInsertBuffer*buffer)
25222523
{
25232524
inti;
25242525

@@ -2534,6 +2535,9 @@ CopyMultiInsertBufferCleanup(CopyMultiInsertBuffer *buffer)
25342535
for (i=0;i<MAX_BUFFERED_TUPLES&&buffer->slots[i]!=NULL;i++)
25352536
ExecDropSingleTupleTableSlot(buffer->slots[i]);
25362537

2538+
table_finish_bulk_insert(buffer->resultRelInfo->ri_RelationDesc,
2539+
miinfo->ti_options);
2540+
25372541
pfree(buffer);
25382542
}
25392543

@@ -2585,7 +2589,7 @@ CopyMultiInsertInfoFlush(CopyMultiInsertInfo *miinfo, ResultRelInfo *curr_rri)
25852589
buffer= (CopyMultiInsertBuffer*)linitial(miinfo->multiInsertBuffers);
25862590
}
25872591

2588-
CopyMultiInsertBufferCleanup(buffer);
2592+
CopyMultiInsertBufferCleanup(miinfo,buffer);
25892593
miinfo->multiInsertBuffers=list_delete_first(miinfo->multiInsertBuffers);
25902594
}
25912595
}
@@ -2599,7 +2603,7 @@ CopyMultiInsertInfoCleanup(CopyMultiInsertInfo *miinfo)
25992603
ListCell*lc;
26002604

26012605
foreach(lc,miinfo->multiInsertBuffers)
2602-
CopyMultiInsertBufferCleanup(lfirst(lc));
2606+
CopyMultiInsertBufferCleanup(miinfo,lfirst(lc));
26032607

26042608
list_free(miinfo->multiInsertBuffers);
26052609
}
@@ -3321,9 +3325,6 @@ CopyFrom(CopyState cstate)
33213325
{
33223326
if (!CopyMultiInsertInfoIsEmpty(&multiInsertInfo))
33233327
CopyMultiInsertInfoFlush(&multiInsertInfo,NULL);
3324-
3325-
/* Tear down the multi-insert buffer data */
3326-
CopyMultiInsertInfoCleanup(&multiInsertInfo);
33273328
}
33283329

33293330
/* Done, clean up */
@@ -3355,6 +3356,10 @@ CopyFrom(CopyState cstate)
33553356
target_resultRelInfo->ri_FdwRoutine->EndForeignInsert(estate,
33563357
target_resultRelInfo);
33573358

3359+
/* Tear down the multi-insert buffer data */
3360+
if (insertMethod!=CIM_SINGLE)
3361+
CopyMultiInsertInfoCleanup(&multiInsertInfo);
3362+
33583363
ExecCloseIndices(target_resultRelInfo);
33593364

33603365
/* Close all the partitioned tables, leaf partitions, and their indices */
@@ -3366,8 +3371,6 @@ CopyFrom(CopyState cstate)
33663371

33673372
FreeExecutorState(estate);
33683373

3369-
table_finish_bulk_insert(cstate->rel,ti_options);
3370-
33713374
returnprocessed;
33723375
}
33733376

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp