Commit 77db9d9f authored by Teodor Sigaev's avatar Teodor Sigaev

Remove mark/restore support in GIN and GiST indexes.

Per Tom's comment.
Also revome useless GISTScanOpaque->flags field.
parent 7f6bc33f
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gin/ginget.c,v 1.19 2008/09/04 11:47:05 teodor Exp $ * $PostgreSQL: pgsql/src/backend/access/gin/ginget.c,v 1.20 2008/10/20 13:39:44 teodor Exp $
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -582,54 +582,6 @@ entryGetItem(Relation index, GinScanEntry entry) ...@@ -582,54 +582,6 @@ entryGetItem(Relation index, GinScanEntry entry)
return entry->isFinished; return entry->isFinished;
} }
/*
* restart from saved position. Actually it's needed only for
* partial match. function is called only by ginrestpos()
*/
void
ginrestartentry(GinScanEntry entry)
{
ItemPointerData stopItem = entry->curItem;
bool savedReduceResult;
if ( entry->master || entry->partialMatch == NULL )
return; /* entry is slave or not a partial match type*/
if ( entry->isFinished )
return; /* entry was finished before ginmarkpos() call */
if ( ItemPointerGetBlockNumber(&stopItem) == InvalidBlockNumber )
return; /* entry wasn't began before ginmarkpos() call */
/*
* Reset iterator
*/
tbm_begin_iterate( entry->partialMatch );
entry->partialMatchResult = NULL;
entry->offset = 0;
/*
* Temporary reset reduceResult flag to guarantee refinding
* of curItem
*/
savedReduceResult = entry->reduceResult;
entry->reduceResult = FALSE;
do
{
/*
* We can use null instead of index because
* partial match doesn't use it
*/
if ( entryGetItem( NULL, entry ) == false )
elog(ERROR, "cannot refind scan position"); /* must not be here! */
} while( compareItemPointers( &stopItem, &entry->curItem ) != 0 );
Assert( entry->isFinished == FALSE );
entry->reduceResult = savedReduceResult;
}
/* /*
* Sets key->curItem to new found heap item pointer for one scan key * Sets key->curItem to new found heap item pointer for one scan key
* Returns isFinished, ie TRUE means we did NOT get a new item pointer! * Returns isFinished, ie TRUE means we did NOT get a new item pointer!
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gin/ginscan.c,v 1.18 2008/09/04 11:47:05 teodor Exp $ * $PostgreSQL: pgsql/src/backend/access/gin/ginscan.c,v 1.19 2008/10/20 13:39:44 teodor Exp $
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -114,7 +114,7 @@ resetScanKeys(GinScanKey keys, uint32 nkeys) ...@@ -114,7 +114,7 @@ resetScanKeys(GinScanKey keys, uint32 nkeys)
#endif #endif
static void static void
freeScanKeys(GinScanKey keys, uint32 nkeys, bool removeRes) freeScanKeys(GinScanKey keys, uint32 nkeys)
{ {
uint32 i, uint32 i,
j; j;
...@@ -130,14 +130,13 @@ freeScanKeys(GinScanKey keys, uint32 nkeys, bool removeRes) ...@@ -130,14 +130,13 @@ freeScanKeys(GinScanKey keys, uint32 nkeys, bool removeRes)
{ {
if (key->scanEntry[j].buffer != InvalidBuffer) if (key->scanEntry[j].buffer != InvalidBuffer)
ReleaseBuffer(key->scanEntry[j].buffer); ReleaseBuffer(key->scanEntry[j].buffer);
if (removeRes && key->scanEntry[j].list) if (key->scanEntry[j].list)
pfree(key->scanEntry[j].list); pfree(key->scanEntry[j].list);
if (removeRes && key->scanEntry[j].partialMatch) if (key->scanEntry[j].partialMatch)
tbm_free(key->scanEntry[j].partialMatch); tbm_free(key->scanEntry[j].partialMatch);
} }
if (removeRes) pfree(key->entryRes);
pfree(key->entryRes);
pfree(key->scanEntry); pfree(key->scanEntry);
} }
...@@ -233,11 +232,10 @@ ginrescan(PG_FUNCTION_ARGS) ...@@ -233,11 +232,10 @@ ginrescan(PG_FUNCTION_ARGS)
} }
else else
{ {
freeScanKeys(so->keys, so->nkeys, TRUE); freeScanKeys(so->keys, so->nkeys);
freeScanKeys(so->markPos, so->nkeys, FALSE);
} }
so->markPos = so->keys = NULL; so->keys = NULL;
if (scankey && scan->numberOfKeys > 0) if (scankey && scan->numberOfKeys > 0)
{ {
...@@ -257,8 +255,7 @@ ginendscan(PG_FUNCTION_ARGS) ...@@ -257,8 +255,7 @@ ginendscan(PG_FUNCTION_ARGS)
if (so != NULL) if (so != NULL)
{ {
freeScanKeys(so->keys, so->nkeys, TRUE); freeScanKeys(so->keys, so->nkeys);
freeScanKeys(so->markPos, so->nkeys, FALSE);
MemoryContextDelete(so->tempCtx); MemoryContextDelete(so->tempCtx);
...@@ -268,60 +265,16 @@ ginendscan(PG_FUNCTION_ARGS) ...@@ -268,60 +265,16 @@ ginendscan(PG_FUNCTION_ARGS)
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
static GinScanKey
copyScanKeys(GinScanKey keys, uint32 nkeys, bool restart)
{
GinScanKey newkeys;
uint32 i,
j;
newkeys = (GinScanKey) palloc(sizeof(GinScanKeyData) * nkeys);
memcpy(newkeys, keys, sizeof(GinScanKeyData) * nkeys);
for (i = 0; i < nkeys; i++)
{
newkeys[i].scanEntry = (GinScanEntry) palloc(sizeof(GinScanEntryData) * keys[i].nentries);
memcpy(newkeys[i].scanEntry, keys[i].scanEntry, sizeof(GinScanEntryData) * keys[i].nentries);
for (j = 0; j < keys[i].nentries; j++)
{
if (keys[i].scanEntry[j].buffer != InvalidBuffer)
IncrBufferRefCount(keys[i].scanEntry[j].buffer);
if (keys[i].scanEntry[j].master)
{
int masterN = keys[i].scanEntry[j].master - keys[i].scanEntry;
newkeys[i].scanEntry[j].master = newkeys[i].scanEntry + masterN;
}
if ( restart )
ginrestartentry( &keys[i].scanEntry[j] );
}
}
return newkeys;
}
Datum Datum
ginmarkpos(PG_FUNCTION_ARGS) ginmarkpos(PG_FUNCTION_ARGS)
{ {
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0); elog(ERROR, "GIN does not support mark/restore");
GinScanOpaque so = (GinScanOpaque) scan->opaque;
freeScanKeys(so->markPos, so->nkeys, FALSE);
so->markPos = copyScanKeys(so->keys, so->nkeys, FALSE);
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
Datum Datum
ginrestrpos(PG_FUNCTION_ARGS) ginrestrpos(PG_FUNCTION_ARGS)
{ {
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0); elog(ERROR, "GIN does not support mark/restore");
GinScanOpaque so = (GinScanOpaque) scan->opaque;
freeScanKeys(so->keys, so->nkeys, FALSE);
so->keys = copyScanKeys(so->markPos, so->nkeys, TRUE);
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.76 2008/10/17 17:02:21 teodor Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.77 2008/10/20 13:39:44 teodor Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -494,16 +494,6 @@ gistfindnext(IndexScanDesc scan, OffsetNumber n, ScanDirection dir) ...@@ -494,16 +494,6 @@ gistfindnext(IndexScanDesc scan, OffsetNumber n, ScanDirection dir)
*/ */
oldcxt = MemoryContextSwitchTo(so->tempCxt); oldcxt = MemoryContextSwitchTo(so->tempCxt);
/*
* If we modified the index during the scan, we may have a pointer to a
* ghost tuple, before the scan. If this is the case, back up one.
*/
if (so->flags & GS_CURBEFORE)
{
so->flags &= ~GS_CURBEFORE;
n = OffsetNumberPrev(n);
}
while (n >= FirstOffsetNumber && n <= maxoff) while (n >= FirstOffsetNumber && n <= maxoff)
{ {
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n)); it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.72 2008/10/17 17:02:21 teodor Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistscan.c,v 1.73 2008/10/20 13:39:44 teodor Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -49,30 +49,21 @@ gistrescan(PG_FUNCTION_ARGS) ...@@ -49,30 +49,21 @@ gistrescan(PG_FUNCTION_ARGS)
{ {
/* rescan an existing indexscan --- reset state */ /* rescan an existing indexscan --- reset state */
gistfreestack(so->stack); gistfreestack(so->stack);
gistfreestack(so->markstk); so->stack = NULL;
so->stack = so->markstk = NULL;
so->flags = 0x0;
/* drop pins on buffers -- no locks held */ /* drop pins on buffers -- no locks held */
if (BufferIsValid(so->curbuf)) if (BufferIsValid(so->curbuf))
{ {
ReleaseBuffer(so->curbuf); ReleaseBuffer(so->curbuf);
so->curbuf = InvalidBuffer; so->curbuf = InvalidBuffer;
} }
if (BufferIsValid(so->markbuf))
{
ReleaseBuffer(so->markbuf);
so->markbuf = InvalidBuffer;
}
} }
else else
{ {
/* initialize opaque data */ /* initialize opaque data */
so = (GISTScanOpaque) palloc(sizeof(GISTScanOpaqueData)); so = (GISTScanOpaque) palloc(sizeof(GISTScanOpaqueData));
so->stack = so->markstk = NULL; so->stack = NULL;
so->flags = 0x0;
so->tempCxt = createTempGistContext(); so->tempCxt = createTempGistContext();
so->curbuf = so->markbuf = InvalidBuffer; so->curbuf = InvalidBuffer;
so->giststate = (GISTSTATE *) palloc(sizeof(GISTSTATE)); so->giststate = (GISTSTATE *) palloc(sizeof(GISTSTATE));
initGISTstate(so->giststate, scan->indexRelation); initGISTstate(so->giststate, scan->indexRelation);
...@@ -83,7 +74,6 @@ gistrescan(PG_FUNCTION_ARGS) ...@@ -83,7 +74,6 @@ gistrescan(PG_FUNCTION_ARGS)
* Clear all the pointers. * Clear all the pointers.
*/ */
ItemPointerSetInvalid(&so->curpos); ItemPointerSetInvalid(&so->curpos);
ItemPointerSetInvalid(&so->markpos);
so->nPageData = so->curPageData = 0; so->nPageData = so->curPageData = 0;
/* Update scan key, if a new one is given */ /* Update scan key, if a new one is given */
...@@ -119,108 +109,14 @@ gistrescan(PG_FUNCTION_ARGS) ...@@ -119,108 +109,14 @@ gistrescan(PG_FUNCTION_ARGS)
Datum Datum
gistmarkpos(PG_FUNCTION_ARGS) gistmarkpos(PG_FUNCTION_ARGS)
{ {
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0); elog(ERROR, "GiST does not support mark/restore");
GISTScanOpaque so;
GISTSearchStack *o,
*n,
*tmp;
so = (GISTScanOpaque) scan->opaque;
so->markpos = so->curpos;
if (so->flags & GS_CURBEFORE)
so->flags |= GS_MRKBEFORE;
else
so->flags &= ~GS_MRKBEFORE;
o = NULL;
n = so->stack;
/* copy the parent stack from the current item data */
while (n != NULL)
{
tmp = (GISTSearchStack *) palloc(sizeof(GISTSearchStack));
tmp->lsn = n->lsn;
tmp->parentlsn = n->parentlsn;
tmp->block = n->block;
tmp->next = o;
o = tmp;
n = n->next;
}
gistfreestack(so->markstk);
so->markstk = o;
/* Update markbuf: make sure to bump ref count on curbuf */
if (BufferIsValid(so->markbuf))
{
ReleaseBuffer(so->markbuf);
so->markbuf = InvalidBuffer;
}
if (BufferIsValid(so->curbuf))
{
IncrBufferRefCount(so->curbuf);
so->markbuf = so->curbuf;
}
so->markNPageData = so->nPageData;
so->markCurPageData = so->curPageData;
if ( so->markNPageData > 0 )
memcpy( so->markPageData, so->pageData, sizeof(ItemResult) * so->markNPageData );
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
Datum Datum
gistrestrpos(PG_FUNCTION_ARGS) gistrestrpos(PG_FUNCTION_ARGS)
{ {
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0); elog(ERROR, "GiST does not support mark/restore");
GISTScanOpaque so;
GISTSearchStack *o,
*n,
*tmp;
so = (GISTScanOpaque) scan->opaque;
so->curpos = so->markpos;
if (so->flags & GS_MRKBEFORE)
so->flags |= GS_CURBEFORE;
else
so->flags &= ~GS_CURBEFORE;
o = NULL;
n = so->markstk;
/* copy the parent stack from the current item data */
while (n != NULL)
{
tmp = (GISTSearchStack *) palloc(sizeof(GISTSearchStack));
tmp->lsn = n->lsn;
tmp->parentlsn = n->parentlsn;
tmp->block = n->block;
tmp->next = o;
o = tmp;
n = n->next;
}
gistfreestack(so->stack);
so->stack = o;
/* Update curbuf: be sure to bump ref count on markbuf */
if (BufferIsValid(so->curbuf))
{
ReleaseBuffer(so->curbuf);
so->curbuf = InvalidBuffer;
}
if (BufferIsValid(so->markbuf))
{
IncrBufferRefCount(so->markbuf);
so->curbuf = so->markbuf;
}
so->nPageData = so->markNPageData;
so->curPageData = so->markNPageData;
if ( so->markNPageData > 0 )
memcpy( so->pageData, so->markPageData, sizeof(ItemResult) * so->markNPageData );
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
...@@ -235,14 +131,11 @@ gistendscan(PG_FUNCTION_ARGS) ...@@ -235,14 +131,11 @@ gistendscan(PG_FUNCTION_ARGS)
if (so != NULL) if (so != NULL)
{ {
gistfreestack(so->stack); gistfreestack(so->stack);
gistfreestack(so->markstk);
if (so->giststate != NULL) if (so->giststate != NULL)
freeGISTstate(so->giststate); freeGISTstate(so->giststate);
/* drop pins on buffers -- we aren't holding any locks */ /* drop pins on buffers -- we aren't holding any locks */
if (BufferIsValid(so->curbuf)) if (BufferIsValid(so->curbuf))
ReleaseBuffer(so->curbuf); ReleaseBuffer(so->curbuf);
if (BufferIsValid(so->markbuf))
ReleaseBuffer(so->markbuf);
MemoryContextDelete(so->tempCxt); MemoryContextDelete(so->tempCxt);
pfree(scan->opaque); pfree(scan->opaque);
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Copyright (c) 2006-2008, PostgreSQL Global Development Group * Copyright (c) 2006-2008, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/include/access/gin.h,v 1.24 2008/07/13 21:50:04 tgl Exp $ * $PostgreSQL: pgsql/src/include/access/gin.h,v 1.25 2008/10/20 13:39:44 teodor Exp $
*-------------------------------------------------------------------------- *--------------------------------------------------------------------------
*/ */
...@@ -426,8 +426,6 @@ typedef struct GinScanOpaqueData ...@@ -426,8 +426,6 @@ typedef struct GinScanOpaqueData
uint32 nkeys; uint32 nkeys;
bool isVoidRes; /* true if ginstate.extractQueryFn guarantees bool isVoidRes; /* true if ginstate.extractQueryFn guarantees
* that nothing will be found */ * that nothing will be found */
GinScanKey markPos;
} GinScanOpaqueData; } GinScanOpaqueData;
typedef GinScanOpaqueData *GinScanOpaque; typedef GinScanOpaqueData *GinScanOpaque;
...@@ -449,7 +447,6 @@ extern PGDLLIMPORT int GinFuzzySearchLimit; ...@@ -449,7 +447,6 @@ extern PGDLLIMPORT int GinFuzzySearchLimit;
extern Datum gingetbitmap(PG_FUNCTION_ARGS); extern Datum gingetbitmap(PG_FUNCTION_ARGS);
extern Datum gingettuple(PG_FUNCTION_ARGS); extern Datum gingettuple(PG_FUNCTION_ARGS);
extern void ginrestartentry(GinScanEntry entry);
/* ginvacuum.c */ /* ginvacuum.c */
extern Datum ginbulkdelete(PG_FUNCTION_ARGS); extern Datum ginbulkdelete(PG_FUNCTION_ARGS);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.33 2008/10/17 17:02:21 teodor Exp $ * $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.34 2008/10/20 13:39:44 teodor Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -72,21 +72,15 @@ typedef struct GISTScanOpaqueData ...@@ -72,21 +72,15 @@ typedef struct GISTScanOpaqueData
{ {
GISTSearchStack *stack; GISTSearchStack *stack;
GISTSearchStack *markstk; GISTSearchStack *markstk;
uint16 flags;
bool qual_ok; /* false if qual can never be satisfied */ bool qual_ok; /* false if qual can never be satisfied */
GISTSTATE *giststate; GISTSTATE *giststate;
MemoryContext tempCxt; MemoryContext tempCxt;
Buffer curbuf; Buffer curbuf;
ItemPointerData curpos; ItemPointerData curpos;
Buffer markbuf;
ItemPointerData markpos;
ItemResult pageData[BLCKSZ/sizeof(IndexTupleData)]; ItemResult pageData[BLCKSZ/sizeof(IndexTupleData)];
OffsetNumber nPageData; OffsetNumber nPageData;
OffsetNumber curPageData; OffsetNumber curPageData;
ItemResult markPageData[BLCKSZ/sizeof(IndexTupleData)];
OffsetNumber markNPageData;
OffsetNumber markCurPageData;
} GISTScanOpaqueData; } GISTScanOpaqueData;
typedef GISTScanOpaqueData *GISTScanOpaque; typedef GISTScanOpaqueData *GISTScanOpaque;
...@@ -225,15 +219,6 @@ typedef struct ...@@ -225,15 +219,6 @@ typedef struct
ItemPointerData key; ItemPointerData key;
} GISTInsertState; } GISTInsertState;
/*
* When we're doing a scan and updating a tree at the same time, the
* updates may affect the scan. We use the flags entry of the scan's
* opaque space to record our actual position in response to updates
* that we can't handle simply by adjusting pointers.
*/
#define GS_CURBEFORE ((uint16) (1 << 0))
#define GS_MRKBEFORE ((uint16) (1 << 1))
/* root page of a gist index */ /* root page of a gist index */
#define GIST_ROOT_BLKNO 0 #define GIST_ROOT_BLKNO 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment