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

Commit86b8504

Browse files
committed
tableam: Add table_multi_insert() and revamp/speed-up COPY FROM buffering.
This adds table_multi_insert(), and converts COPY FROM, the only userof heap_multi_insert, to it.A simple conversion of COPY FROM use slots would have yielded aslowdown when inserting into a partitioned table for someworkloads. Different partitions might need different slots (both slottypes and their descriptors), and dropping / creating slots whenthere's constant partition changes is measurable.Thus instead revamp the COPY FROM buffering for partitioned tables toallow to buffer inserts into multiple tables, flushing only whenlimits are reached across all partition buffers. By only droppingslots when there've been inserts into too many different partitions,the aforementioned overhead is gone. By allowing larger batches, evenwhen there are frequent partition changes, we actuall speed such casesup significantly.By using slots COPY of very narrow rows into unlogged / temporarymight slow down very slightly (due to the indirect function calls).Author: David Rowley, Andres Freund, Haribabu KommiDiscussion:https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.dehttps://postgr.es/m/20190327054923.t3epfuewxfqdt22e@alap3.anarazel.de
1 parent7bac3ac commit86b8504

File tree

9 files changed

+587
-366
lines changed

9 files changed

+587
-366
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,7 @@ heap_prepare_insert(Relation relation, HeapTuple tup, TransactionId xid,
21062106
* temporary context before calling this, if that's a problem.
21072107
*/
21082108
void
2109-
heap_multi_insert(Relationrelation,HeapTuple*tuples,intntuples,
2109+
heap_multi_insert(Relationrelation,TupleTableSlot**slots,intntuples,
21102110
CommandIdcid,intoptions,BulkInsertStatebistate)
21112111
{
21122112
TransactionIdxid=GetCurrentTransactionId();
@@ -2127,11 +2127,18 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
21272127
saveFreeSpace=RelationGetTargetPageFreeSpace(relation,
21282128
HEAP_DEFAULT_FILLFACTOR);
21292129

2130-
/* Toast and set header data in all thetuples */
2130+
/* Toast and set header data in all theslots */
21312131
heaptuples=palloc(ntuples*sizeof(HeapTuple));
21322132
for (i=0;i<ntuples;i++)
2133-
heaptuples[i]=heap_prepare_insert(relation,tuples[i],
2134-
xid,cid,options);
2133+
{
2134+
HeapTupletuple;
2135+
2136+
tuple=ExecFetchSlotHeapTuple(slots[i], true,NULL);
2137+
slots[i]->tts_tableOid=RelationGetRelid(relation);
2138+
tuple->t_tableOid=slots[i]->tts_tableOid;
2139+
heaptuples[i]=heap_prepare_insert(relation,tuple,xid,cid,
2140+
options);
2141+
}
21352142

21362143
/*
21372144
* We're about to do the actual inserts -- but check for conflict first,
@@ -2361,13 +2368,9 @@ heap_multi_insert(Relation relation, HeapTuple *tuples, int ntuples,
23612368
CacheInvalidateHeapTuple(relation,heaptuples[i],NULL);
23622369
}
23632370

2364-
/*
2365-
* Copy t_self fields back to the caller's original tuples. This does
2366-
* nothing for untoasted tuples (tuples[i] == heaptuples[i)], but it's
2367-
* probably faster to always copy than check.
2368-
*/
2371+
/* copy t_self fields back to the caller's slots */
23692372
for (i=0;i<ntuples;i++)
2370-
tuples[i]->t_self=heaptuples[i]->t_self;
2373+
slots[i]->tts_tid=heaptuples[i]->t_self;
23712374

23722375
pgstat_count_heap_insert(relation,ntuples);
23732376
}

‎src/backend/access/heap/heapam_handler.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,7 @@ static const TableAmRoutine heapam_methods = {
25162516
.tuple_insert=heapam_tuple_insert,
25172517
.tuple_insert_speculative=heapam_tuple_insert_speculative,
25182518
.tuple_complete_speculative=heapam_tuple_complete_speculative,
2519+
.multi_insert=heap_multi_insert,
25192520
.tuple_delete=heapam_tuple_delete,
25202521
.tuple_update=heapam_tuple_update,
25212522
.tuple_lock=heapam_tuple_lock,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp