tableam: finish_bulk_insert().
authorAndres Freund <[email protected]>
Sun, 20 Jan 2019 07:18:24 +0000 (23:18 -0800)
committerAndres Freund <[email protected]>
Wed, 6 Mar 2019 06:59:31 +0000 (22:59 -0800)
Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

src/backend/access/heap/heapam_handler.c
src/backend/commands/copy.c
src/backend/commands/createas.c
src/backend/commands/matview.c
src/backend/commands/tablecmds.c
src/include/access/tableam.h

index c289bd99c430d2c6b934af4b7b49b110e99637ec..1de749ac6c25037b5db3e87067b3921d92965671 100644 (file)
@@ -426,6 +426,18 @@ retry:
    return result;
 }
 
+static void
+heapam_finish_bulk_insert(Relation relation, int options)
+{
+   /*
+    * If we skipped writing WAL, then we need to sync the heap (but not
+    * indexes since those use WAL anyway)
+    */
+   if (options & HEAP_INSERT_SKIP_WAL)
+       heap_sync(relation);
+}
+
+
 static bool
 heapam_fetch_row_version(Relation relation,
                         ItemPointer tid,
@@ -563,6 +575,7 @@ static const TableAmRoutine heapam_methods = {
    .tuple_update = heapam_heap_update,
    .multi_insert = heap_multi_insert,
    .tuple_lock = heapam_lock_tuple,
+   .finish_bulk_insert = heapam_finish_bulk_insert,
 
    .tuple_fetch_row_version = heapam_fetch_row_version,
    .tuple_get_latest_tid = heap_get_latest_tid,
index 36f09b5ac98c0d94e7067c1d2ce8de7c16864e48..f76b3addde1193b38e56667af1ce2c9ba4c119a6 100644 (file)
@@ -3098,12 +3098,7 @@ CopyFrom(CopyState cstate)
 
    FreeExecutorState(estate);
 
-   /*
-    * If we skipped writing WAL, then we need to sync the heap (but not
-    * indexes since those use WAL anyway)
-    */
-   if (hi_options & HEAP_INSERT_SKIP_WAL)
-       heap_sync(cstate->rel);
+   table_finish_bulk_insert(cstate->rel, hi_options);
 
    return processed;
 }
index 0ac295cea3f1ef9d170d4a294cfdcf4650252ba9..55f6185461483a3203e04f10a51b4bd777f623f9 100644 (file)
@@ -28,6 +28,7 @@
 #include "access/reloptions.h"
 #include "access/htup_details.h"
 #include "access/sysattr.h"
+#include "access/tableam.h"
 #include "access/xact.h"
 #include "access/xlog.h"
 #include "catalog/namespace.h"
@@ -601,9 +602,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->hi_options);
 
    /* close rel, but keep lock until commit */
    table_close(myState->rel, NoLock);
index 5a47be4b33c51f49193d6842af207cb94c44d3a4..62b76cfd358b6a87b3b1de1ad99f4cd7fd83f7dc 100644 (file)
@@ -18,6 +18,7 @@
 #include "access/heapam.h"
 #include "access/htup_details.h"
 #include "access/multixact.h"
+#include "access/tableam.h"
 #include "access/xact.h"
 #include "access/xlog.h"
 #include "catalog/catalog.h"
@@ -509,9 +510,7 @@ transientrel_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->transientrel);
+   table_finish_bulk_insert(myState->transientrel, myState->hi_options);
 
    /* close transientrel, but keep lock until commit */
    table_close(myState->transientrel, NoLock);
index 3a04a26f01a8455d520035a1b3aee41d4b7ed469..0b1b73c434c639a446230279a3d2b582fbbcf9bc 100644 (file)
@@ -4953,9 +4953,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, hi_options);
 
        table_close(newrel, NoLock);
    }
index e6530f23858067b3b10acc78ea40ec26e2b8308a..b5909d8b6b1024da259674557e3f9e792b5906ea 100644 (file)
@@ -157,6 +157,18 @@ typedef struct TableAmRoutine
                               LockWaitPolicy wait_policy,
                               uint8 flags,
                               HeapUpdateFailureData *hufd);
+
+   /*
+    * Perform operations necessary to complete insertions made via
+    * tuple_insert and multi_insert with a BulkInsertState specified. This
+    * e.g. may e.g. used to flush the relation when inserting with skipping
+    * WAL.
+    *
+    * May be NULL.
+    */
+   void        (*finish_bulk_insert) (Relation rel, int options);
+
+
    /* ------------------------------------------------------------------------
     * Non-modifying operations on individual tuples.
     * ------------------------------------------------------------------------
@@ -445,6 +457,16 @@ table_lock_tuple(Relation rel, ItemPointer tid, Snapshot snapshot,
                                       cid, mode, wait_policy,
                                       flags, hufd);
 }
+
+static inline void
+table_finish_bulk_insert(Relation rel, int options)
+{
+   /* optional */
+   if (rel->rd_tableam && rel->rd_tableam->finish_bulk_insert)
+       rel->rd_tableam->finish_bulk_insert(rel, options);
+}
+
+
 /* ----------------------------------------------------------------------------
  * Non-modifying operations on individual tuples.
  * ----------------------------------------------------------------------------