aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/createas.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/createas.c
parent26a76cb64072df6fa5585c2c15df39970ccdce01 (diff)
downloadpostgresql-d45e40158623baacd3f36f92a670d435cc1e845f.tar.gz
postgresql-d45e40158623baacd3f36f92a670d435cc1e845f.zip
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/createas.c')
-rw-r--r--src/backend/commands/createas.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 3bdb67c697c..43c2fa91242 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -27,8 +27,8 @@
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/htup_details.h"
-#include "access/tableam.h"
#include "access/sysattr.h"
+#include "access/tableam.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "catalog/namespace.h"
@@ -60,7 +60,7 @@ typedef struct
Relation rel; /* relation to write to */
ObjectAddress reladdr; /* address of rel, for ExecCreateTableAs */
CommandId output_cid; /* cmin to insert in output tuples */
- int hi_options; /* heap_insert performance options */
+ int ti_options; /* table_insert performance options */
BulkInsertState bistate; /* bulk insert state */
} DR_intorel;
@@ -558,8 +558,8 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
* We can skip WAL-logging the insertions, unless PITR or streaming
* replication is in use. We can skip the FSM in any case.
*/
- myState->hi_options = HEAP_INSERT_SKIP_FSM |
- (XLogIsNeeded() ? 0 : HEAP_INSERT_SKIP_WAL);
+ myState->ti_options = TABLE_INSERT_SKIP_FSM |
+ (XLogIsNeeded() ? 0 : TABLE_INSERT_SKIP_WAL);
myState->bistate = GetBulkInsertState();
/* Not using WAL requires smgr_targblock be initially invalid */
@@ -586,7 +586,7 @@ intorel_receive(TupleTableSlot *slot, DestReceiver *self)
table_insert(myState->rel,
slot,
myState->output_cid,
- myState->hi_options,
+ myState->ti_options,
myState->bistate);
/* We know this is a newly created relation, so there are no indexes */
@@ -604,9 +604,7 @@ intorel_shutdown(DestReceiver *self)
FreeBulkInsertState(myState->bistate);
- /* If we skipped using WAL, must heap_sync before commit */
- if (myState->hi_options & HEAP_INSERT_SKIP_WAL)
- heap_sync(myState->rel);
+ table_finish_bulk_insert(myState->rel, myState->ti_options);
/* close rel, but keep lock until commit */
table_close(myState->rel, NoLock);