summaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2019-04-01 14:41:42 -0700
committerAndres Freund <andres@anarazel.de>2019-04-01 14:41:42 -0700
commitd45e40158623baacd3f36f92a670d435cc1e845f (patch)
treea40ff43e146006118c44fed313454f0768eb44f7 /src/backend/commands/tablecmds.c
parent26a76cb64072df6fa5585c2c15df39970ccdce01 (diff)
downloadpostgresql-d45e40158623baacd3f36f92a670d435cc1e845f.tar.gz
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
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 31e2b508b8..654179297c 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -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);
}