]> granicus.if.org Git - postgresql/commitdiff
Prevent synchronous scan during GIN index build, because GIN is optimized
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 13 Nov 2008 17:42:19 +0000 (17:42 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 13 Nov 2008 17:42:19 +0000 (17:42 +0000)
for inserting tuples in increasing TID order.  It's not clear whether this
fully explains Ivan Sergio Borgonovo's complaint, but simple testing
confirms that a scan that doesn't start at block 0 can slow GIN build by
a factor of three or four.

Backpatch to 8.3.  Sync scan didn't exist before that.

src/backend/access/gin/gininsert.c
src/backend/access/gist/gist.c
src/backend/access/hash/hash.c
src/backend/access/nbtree/nbtree.c
src/backend/catalog/index.c
src/include/catalog/index.h

index a20687f70327bdbe348f27bae083c0c798fe52b9..31af4a82f1d2887cf5eca9a658638c80ef73e017 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *                     $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.11 2008/01/01 19:45:46 momjian Exp $
+ *                     $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.11.2.1 2008/11/13 17:42:18 tgl Exp $
  *-------------------------------------------------------------------------
  */
 
@@ -326,8 +326,11 @@ ginbuild(PG_FUNCTION_ARGS)
        buildstate.accum.ginstate = &buildstate.ginstate;
        ginInitBA(&buildstate.accum);
 
-       /* do the heap scan */
-       reltuples = IndexBuildHeapScan(heap, index, indexInfo,
+       /*
+        * Do the heap scan.  We disallow sync scan here because dataPlaceToPage
+        * prefers to receive tuples in TID order.
+        */
+       reltuples = IndexBuildHeapScan(heap, index, indexInfo, false,
                                                                   ginBuildCallback, (void *) &buildstate);
 
        oldCtx = MemoryContextSwitchTo(buildstate.tmpCtx);
index 91b8fe4d055f0ef1a38d685aee648390f612a6be..26f3ddbf8534cb75379100f64df223ad2844264a 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.149 2008/01/01 19:45:46 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.149.2.1 2008/11/13 17:42:18 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -147,7 +147,7 @@ gistbuild(PG_FUNCTION_ARGS)
        buildstate.tmpCtx = createTempGistContext();
 
        /* do the heap scan */
-       reltuples = IndexBuildHeapScan(heap, index, indexInfo,
+       reltuples = IndexBuildHeapScan(heap, index, indexInfo, true,
                                                                   gistbuildCallback, (void *) &buildstate);
 
        /* okay, all heap tuples are indexed */
index f6c4d5705d4284a6393d3ebcb81ba09be88b66bd..4b58f46b13642739021535d88934680ddcd2e456 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.98 2008/01/01 19:45:46 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.98.2.1 2008/11/13 17:42:18 tgl Exp $
  *
  * NOTES
  *       This file contains only the public interface routines.
@@ -66,7 +66,7 @@ hashbuild(PG_FUNCTION_ARGS)
        buildstate.indtuples = 0;
 
        /* do the heap scan */
-       reltuples = IndexBuildHeapScan(heap, index, indexInfo,
+       reltuples = IndexBuildHeapScan(heap, index, indexInfo, true,
                                                                   hashbuildCallback, (void *) &buildstate);
 
        /*
index d547b910528cd01c4ba87eadf178c9dc12827cc6..8b30331be4b0b2ab6e8a01fec2f5606f6bb5dc3e 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.156.2.1 2008/04/16 23:59:51 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.156.2.2 2008/11/13 17:42:18 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -117,7 +117,7 @@ btbuild(PG_FUNCTION_ARGS)
                buildstate.spool2 = _bt_spoolinit(index, false, true);
 
        /* do the heap scan */
-       reltuples = IndexBuildHeapScan(heap, index, indexInfo,
+       reltuples = IndexBuildHeapScan(heap, index, indexInfo, true,
                                                                   btbuildCallback, (void *) &buildstate);
 
        /* okay, all heap tuples are indexed */
index 403e9ab5f25ed710b37e3f96c7bb4fae4a547e4f..85c368e4408b0bff0a32cd064d25d65daded6d7e 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.292.2.1 2008/08/10 19:02:46 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.292.2.2 2008/11/13 17:42:18 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -1450,6 +1450,7 @@ double
 IndexBuildHeapScan(Relation heapRelation,
                                   Relation indexRelation,
                                   IndexInfo *indexInfo,
+                                  bool allow_sync,
                                   IndexBuildCallback callback,
                                   void *callback_state)
 {
@@ -1512,10 +1513,12 @@ IndexBuildHeapScan(Relation heapRelation,
                OldestXmin = GetOldestXmin(heapRelation->rd_rel->relisshared, true);
        }
 
-       scan = heap_beginscan(heapRelation, /* relation */
-                                                 snapshot,             /* seeself */
-                                                 0,    /* number of keys */
-                                                 NULL);        /* scan key */
+       scan = heap_beginscan_strat(heapRelation,       /* relation */
+                                                               snapshot,               /* snapshot */
+                                                               0,                              /* number of keys */
+                                                               NULL,                   /* scan key */
+                                                               true,                   /* buffer access strategy OK */
+                                                               allow_sync);    /* syncscan OK? */
 
        reltuples = 0;
 
index a5ab195c233d92eac2332e537a376bb1c70241fb..70c265232bf57ffbba9abffceffb688fabc09c09 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/index.h,v 1.75 2008/01/01 19:45:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/index.h,v 1.75.2.1 2008/11/13 17:42:19 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -63,6 +63,7 @@ extern void index_build(Relation heapRelation,
 extern double IndexBuildHeapScan(Relation heapRelation,
                                   Relation indexRelation,
                                   IndexInfo *indexInfo,
+                                  bool allow_sync,
                                   IndexBuildCallback callback,
                                   void *callback_state);