summaryrefslogtreecommitdiff
path: root/src/backend/access/gin/gindatapage.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-03-24 20:17:18 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-03-24 20:17:18 +0000
commitff301d6e690bb5581502ea3d8591a1600fd87acc (patch)
tree9fd8b2fa00cf35f8b2e66b0960e7e9ca90dfaa66 /src/backend/access/gin/gindatapage.c
parent9987f66001ef7f59dd8f8c92295732dba5507c4f (diff)
Implement "fastupdate" support for GIN indexes, in which we try to accumulate
multiple index entries in a holding area before adding them to the main index structure. This helps because bulk insert is (usually) significantly faster than retail insert for GIN. This patch also removes GIN support for amgettuple-style index scans. The API defined for amgettuple is difficult to support with fastupdate, and the previously committed partial-match feature didn't really work with it either. We might eventually figure a way to put back amgettuple support, but it won't happen for 8.4. catversion bumped because of change in GIN's pg_am entry, and because the format of GIN indexes changed on-disk (there's a metapage now, and possibly a pending list). Teodor Sigaev
Diffstat (limited to 'src/backend/access/gin/gindatapage.c')
-rw-r--r--src/backend/access/gin/gindatapage.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/backend/access/gin/gindatapage.c b/src/backend/access/gin/gindatapage.c
index d0e426c6560..a872d44880c 100644
--- a/src/backend/access/gin/gindatapage.c
+++ b/src/backend/access/gin/gindatapage.c
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/gin/gindatapage.c,v 1.13 2009/01/01 17:23:34 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/gin/gindatapage.c,v 1.14 2009/03/24 20:17:10 tgl Exp $
*-------------------------------------------------------------------------
*/
@@ -43,8 +43,16 @@ MergeItemPointers(ItemPointerData *dst, ItemPointerData *a, uint32 na, ItemPoint
while (aptr - a < na && bptr - b < nb)
{
- if (compareItemPointers(aptr, bptr) > 0)
+ int cmp = compareItemPointers(aptr, bptr);
+
+ if (cmp > 0)
+ *dptr++ = *bptr++;
+ else if (cmp == 0)
+ {
+ /* we want only one copy of the identical items */
*dptr++ = *bptr++;
+ aptr++;
+ }
else
*dptr++ = *aptr++;
}
@@ -630,11 +638,16 @@ insertItemPointer(GinPostingTreeScan *gdi, ItemPointerData *items, uint32 nitem)
gdi->stack = ginFindLeafPage(&gdi->btree, gdi->stack);
if (gdi->btree.findItem(&(gdi->btree), gdi->stack))
- elog(ERROR, "item pointer (%u,%d) already exists",
- ItemPointerGetBlockNumber(gdi->btree.items + gdi->btree.curitem),
- ItemPointerGetOffsetNumber(gdi->btree.items + gdi->btree.curitem));
-
- ginInsertValue(&(gdi->btree), gdi->stack);
+ {
+ /*
+ * gdi->btree.items[gdi->btree.curitem] already exists in index
+ */
+ gdi->btree.curitem++;
+ LockBuffer(gdi->stack->buffer, GIN_UNLOCK);
+ freeGinBtreeStack(gdi->stack);
+ }
+ else
+ ginInsertValue(&(gdi->btree), gdi->stack);
gdi->stack = NULL;
}