aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-11-13 17:42:19 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-11-13 17:42:19 +0000
commitb608b24245cb3acffac6f596107a8ffab6880ae6 (patch)
tree25705a494e620874c68418e94015954f3184d789 /src
parent940c412d7fe1ac9fc779d4f3f181f4928da90ba6 (diff)
downloadpostgresql-b608b24245cb3acffac6f596107a8ffab6880ae6.tar.gz
postgresql-b608b24245cb3acffac6f596107a8ffab6880ae6.zip
Prevent synchronous scan during GIN index build, because GIN is optimized
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/gin/gininsert.c9
-rw-r--r--src/backend/access/gist/gist.c4
-rw-r--r--src/backend/access/hash/hash.c4
-rw-r--r--src/backend/access/nbtree/nbtree.c4
-rw-r--r--src/backend/catalog/index.c13
-rw-r--r--src/include/catalog/index.h3
6 files changed, 22 insertions, 15 deletions
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index a20687f7032..31af4a82f1d 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -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);
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 91b8fe4d055..26f3ddbf853 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -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 */
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index f6c4d5705d4..4b58f46b136 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -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);
/*
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index d547b910528..8b30331be4b 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -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 */
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 403e9ab5f25..85c368e4408 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -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;
diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h
index a5ab195c233..70c265232bf 100644
--- a/src/include/catalog/index.h
+++ b/src/include/catalog/index.h
@@ -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);