aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/nbtree/nbtree.c9
-rw-r--r--src/backend/access/nbtree/nbtsort.c17
2 files changed, 19 insertions, 7 deletions
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index b989ee3c23c..b423c8fdbe8 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.109 2004/01/07 18:56:24 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.110 2004/02/03 17:34:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -117,13 +117,14 @@ btbuild(PG_FUNCTION_ARGS)
if (buildstate.usefast)
{
- buildstate.spool = _bt_spoolinit(index, indexInfo->ii_Unique);
+ buildstate.spool = _bt_spoolinit(index, indexInfo->ii_Unique, false);
/*
- * Different from spool, the uniqueness isn't checked for spool2.
+ * If building a unique index, put dead tuples in a second spool
+ * to keep them out of the uniqueness check.
*/
if (indexInfo->ii_Unique)
- buildstate.spool2 = _bt_spoolinit(index, false);
+ buildstate.spool2 = _bt_spoolinit(index, false, true);
}
/* do the heap scan */
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 0986f49a6e3..08be20a0271 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -36,7 +36,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.80 2004/01/07 18:56:24 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.81 2004/02/03 17:34:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -112,14 +112,25 @@ static void _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2);
* create and initialize a spool structure
*/
BTSpool *
-_bt_spoolinit(Relation index, bool isunique)
+_bt_spoolinit(Relation index, bool isunique, bool isdead)
{
BTSpool *btspool = (BTSpool *) palloc0(sizeof(BTSpool));
+ int btKbytes;
btspool->index = index;
btspool->isunique = isunique;
- btspool->sortstate = tuplesort_begin_index(index, isunique, false);
+ /*
+ * We size the sort area as maintenance_work_mem rather than work_mem to
+ * speed index creation. This should be OK since a single backend can't
+ * run multiple index creations in parallel. Note that creation of a
+ * unique index actually requires two BTSpool objects. We expect that the
+ * second one (for dead tuples) won't get very full, so we give it only
+ * work_mem.
+ */
+ btKbytes = isdead ? work_mem : maintenance_work_mem;
+ btspool->sortstate = tuplesort_begin_index(index, isunique,
+ btKbytes, false);
/*
* Currently, tuplesort provides sort functions on IndexTuples. If we