mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
tableam: Add table_finish_bulk_insert().
This replaces the previous calls of heap_sync() in places using bulk-insert. By passing in the flags used for bulk-insert the AM can decide (first at insert time and then during the finish call) which of the optimizations apply to it, and what operations are necessary to finish a bulk insert operation. Also change HEAP_INSERT_* flags to TABLE_INSERT, and rename hi_options to ti_options. These changes are made even in copy.c, which hasn't yet been converted to tableam. There's no harm in doing so. Author: Andres Freund Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
This commit is contained in:
@ -4687,7 +4687,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
||||
EState *estate;
|
||||
CommandId mycid;
|
||||
BulkInsertState bistate;
|
||||
int hi_options;
|
||||
int ti_options;
|
||||
ExprState *partqualstate = NULL;
|
||||
|
||||
/*
|
||||
@ -4704,7 +4704,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
||||
newrel = NULL;
|
||||
|
||||
/*
|
||||
* Prepare a BulkInsertState and options for heap_insert. Because we're
|
||||
* Prepare a BulkInsertState and options for table_insert. Because we're
|
||||
* building a new heap, we can skip WAL-logging and fsync it to disk at
|
||||
* the end instead (unless WAL-logging is required for archiving or
|
||||
* streaming replication). The FSM is empty too, so don't bother using it.
|
||||
@ -4714,16 +4714,16 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
||||
mycid = GetCurrentCommandId(true);
|
||||
bistate = GetBulkInsertState();
|
||||
|
||||
hi_options = HEAP_INSERT_SKIP_FSM;
|
||||
ti_options = TABLE_INSERT_SKIP_FSM;
|
||||
if (!XLogIsNeeded())
|
||||
hi_options |= HEAP_INSERT_SKIP_WAL;
|
||||
ti_options |= TABLE_INSERT_SKIP_WAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* keep compiler quiet about using these uninitialized */
|
||||
mycid = 0;
|
||||
bistate = NULL;
|
||||
hi_options = 0;
|
||||
ti_options = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -4977,7 +4977,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
||||
|
||||
/* Write the tuple out to the new relation */
|
||||
if (newrel)
|
||||
table_insert(newrel, insertslot, mycid, hi_options, bistate);
|
||||
table_insert(newrel, insertslot, mycid, ti_options, bistate);
|
||||
|
||||
ResetExprContext(econtext);
|
||||
|
||||
@ -5000,9 +5000,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
|
||||
{
|
||||
FreeBulkInsertState(bistate);
|
||||
|
||||
/* If we skipped writing WAL, then we need to sync the heap. */
|
||||
if (hi_options & HEAP_INSERT_SKIP_WAL)
|
||||
heap_sync(newrel);
|
||||
table_finish_bulk_insert(newrel, ti_options);
|
||||
|
||||
table_close(newrel, NoLock);
|
||||
}
|
||||
|
Reference in New Issue
Block a user