1996-08-26 22:02:12 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* gistscan.c
|
2001-05-30 21:53:40 +02:00
|
|
|
* routines to manage scans on GiST index relations
|
1996-08-26 22:02:12 +02:00
|
|
|
*
|
|
|
|
*
|
2001-05-30 21:53:40 +02:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1996-08-26 22:02:12 +02:00
|
|
|
* IDENTIFICATION
|
2002-03-05 06:30:40 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/access/gist/gistscan.c,v 1.41 2002/03/05 05:30:35 momjian Exp $
|
1996-08-26 22:02:12 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "postgres.h"
|
1996-10-31 09:09:47 +01:00
|
|
|
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "access/genam.h"
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/gist.h"
|
|
|
|
#include "access/gistscan.h"
|
1996-10-21 07:14:02 +02:00
|
|
|
|
|
|
|
|
1996-08-26 22:02:12 +02:00
|
|
|
/* routines defined and used here */
|
1997-09-08 04:41:22 +02:00
|
|
|
static void gistregscan(IndexScanDesc s);
|
|
|
|
static void gistdropscan(IndexScanDesc s);
|
1998-09-01 06:40:42 +02:00
|
|
|
static void gistadjone(IndexScanDesc s, int op, BlockNumber blkno,
|
1997-09-07 07:04:48 +02:00
|
|
|
OffsetNumber offnum);
|
2002-03-05 06:30:40 +01:00
|
|
|
static void adjuststack(GISTSTACK *stk, BlockNumber blkno);
|
1998-09-01 06:40:42 +02:00
|
|
|
static void adjustiptr(IndexScanDesc s, ItemPointer iptr,
|
1997-09-07 07:04:48 +02:00
|
|
|
int op, BlockNumber blkno, OffsetNumber offnum);
|
1996-08-26 22:02:12 +02:00
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Whenever we start a GiST scan in a backend, we register it in private
|
|
|
|
* space. Then if the GiST index gets updated, we check all registered
|
|
|
|
* scans and adjust them if the tuple they point at got moved by the
|
|
|
|
* update. We only need to do this in private space, because when we update
|
|
|
|
* an GiST we have a write lock on the tree, so no other process can have
|
|
|
|
* any locks at all on it. A single transaction can have write and read
|
|
|
|
* locks on the same object, so that's why we need to handle this case.
|
1996-08-26 22:02:12 +02:00
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct GISTScanListData
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
IndexScanDesc gsl_scan;
|
1997-09-07 07:04:48 +02:00
|
|
|
struct GISTScanListData *gsl_next;
|
1997-09-08 23:56:23 +02:00
|
|
|
} GISTScanListData;
|
1996-08-26 22:02:12 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef GISTScanListData *GISTScanList;
|
1996-08-26 22:02:12 +02:00
|
|
|
|
|
|
|
/* pointer to list of local scans on GiSTs */
|
|
|
|
static GISTScanList GISTScans = (GISTScanList) NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
gistbeginscan(PG_FUNCTION_ARGS)
|
1996-08-26 22:02:12 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
Relation r = (Relation) PG_GETARG_POINTER(0);
|
|
|
|
bool fromEnd = PG_GETARG_BOOL(1);
|
|
|
|
uint16 nkeys = PG_GETARG_UINT16(2);
|
|
|
|
ScanKey key = (ScanKey) PG_GETARG_POINTER(3);
|
1997-09-08 04:41:22 +02:00
|
|
|
IndexScanDesc s;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
s = RelationGetIndexScan(r, fromEnd, nkeys, key);
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
gistregscan(s);
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_POINTER(s);
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
gistrescan(PG_FUNCTION_ARGS)
|
1996-08-26 22:02:12 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
|
|
|
|
bool fromEnd = PG_GETARG_BOOL(1);
|
|
|
|
ScanKey key = (ScanKey) PG_GETARG_POINTER(2);
|
1997-09-08 04:41:22 +02:00
|
|
|
GISTScanOpaque p;
|
|
|
|
int i;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear all the pointers.
|
|
|
|
*/
|
|
|
|
ItemPointerSetInvalid(&s->currentItemData);
|
|
|
|
ItemPointerSetInvalid(&s->currentMarkData);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set flags.
|
|
|
|
*/
|
|
|
|
if (RelationGetNumberOfBlocks(s->relation) == 0)
|
|
|
|
s->flags = ScanUnmarked;
|
|
|
|
else if (fromEnd)
|
|
|
|
s->flags = ScanUnmarked | ScanUncheckedPrevious;
|
|
|
|
else
|
|
|
|
s->flags = ScanUnmarked | ScanUncheckedNext;
|
|
|
|
|
|
|
|
s->scanFromEnd = fromEnd;
|
|
|
|
|
|
|
|
if (s->numberOfKeys > 0)
|
|
|
|
{
|
|
|
|
memmove(s->keyData,
|
|
|
|
key,
|
|
|
|
s->numberOfKeys * sizeof(ScanKeyData));
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (GISTScanOpaque) s->opaque;
|
|
|
|
if (p != (GISTScanOpaque) NULL)
|
|
|
|
{
|
|
|
|
gistfreestack(p->s_stack);
|
|
|
|
gistfreestack(p->s_markstk);
|
|
|
|
p->s_stack = p->s_markstk = (GISTSTACK *) NULL;
|
|
|
|
p->s_flags = 0x0;
|
|
|
|
for (i = 0; i < s->numberOfKeys; i++)
|
|
|
|
{
|
|
|
|
s->keyData[i].sk_procedure
|
|
|
|
= RelationGetGISTStrategy(s->relation, s->keyData[i].sk_attno,
|
|
|
|
s->keyData[i].sk_procedure);
|
2001-10-25 07:50:21 +02:00
|
|
|
s->keyData[i].sk_func = p->giststate->consistentFn[s->keyData[i].sk_attno - 1];
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* initialize opaque data */
|
|
|
|
p = (GISTScanOpaque) palloc(sizeof(GISTScanOpaqueData));
|
|
|
|
p->s_stack = p->s_markstk = (GISTSTACK *) NULL;
|
|
|
|
p->s_flags = 0x0;
|
|
|
|
s->opaque = p;
|
|
|
|
p->giststate = (GISTSTATE *) palloc(sizeof(GISTSTATE));
|
|
|
|
initGISTstate(p->giststate, s->relation);
|
|
|
|
if (s->numberOfKeys > 0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* * Play games here with the scan key to use the Consistent *
|
|
|
|
* function for all comparisons: * 1) the sk_procedure field
|
|
|
|
* will now be used to hold the * strategy number * 2) the
|
|
|
|
* sk_func field will point to the Consistent function
|
|
|
|
*/
|
|
|
|
for (i = 0; i < s->numberOfKeys; i++)
|
|
|
|
{
|
|
|
|
|
2001-03-23 05:49:58 +01:00
|
|
|
/*----------
|
1997-09-07 07:04:48 +02:00
|
|
|
* s->keyData[i].sk_procedure =
|
2001-10-25 07:50:21 +02:00
|
|
|
* index_getprocid(s->relation, 1, GIST_CONSISTENT_PROC);
|
2001-03-23 05:49:58 +01:00
|
|
|
*----------
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
|
|
|
s->keyData[i].sk_procedure
|
|
|
|
= RelationGetGISTStrategy(s->relation, s->keyData[i].sk_attno,
|
|
|
|
s->keyData[i].sk_procedure);
|
2001-10-25 07:50:21 +02:00
|
|
|
s->keyData[i].sk_func = p->giststate->consistentFn[s->keyData[i].sk_attno - 1];
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-05-22 18:01:33 +02:00
|
|
|
}
|
2000-06-13 09:35:40 +02:00
|
|
|
|
2000-06-14 07:24:50 +02:00
|
|
|
PG_RETURN_VOID();
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
gistmarkpos(PG_FUNCTION_ARGS)
|
1996-08-26 22:02:12 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
|
1997-09-08 04:41:22 +02:00
|
|
|
GISTScanOpaque p;
|
|
|
|
GISTSTACK *o,
|
|
|
|
*n,
|
|
|
|
*tmp;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
s->currentMarkData = s->currentItemData;
|
|
|
|
p = (GISTScanOpaque) s->opaque;
|
|
|
|
if (p->s_flags & GS_CURBEFORE)
|
|
|
|
p->s_flags |= GS_MRKBEFORE;
|
|
|
|
else
|
|
|
|
p->s_flags &= ~GS_MRKBEFORE;
|
|
|
|
|
|
|
|
o = (GISTSTACK *) NULL;
|
|
|
|
n = p->s_stack;
|
|
|
|
|
|
|
|
/* copy the parent stack from the current item data */
|
|
|
|
while (n != (GISTSTACK *) NULL)
|
|
|
|
{
|
|
|
|
tmp = (GISTSTACK *) palloc(sizeof(GISTSTACK));
|
|
|
|
tmp->gs_child = n->gs_child;
|
|
|
|
tmp->gs_blk = n->gs_blk;
|
|
|
|
tmp->gs_parent = o;
|
|
|
|
o = tmp;
|
|
|
|
n = n->gs_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
gistfreestack(p->s_markstk);
|
|
|
|
p->s_markstk = o;
|
2000-06-13 09:35:40 +02:00
|
|
|
|
2000-06-14 07:24:50 +02:00
|
|
|
PG_RETURN_VOID();
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
gistrestrpos(PG_FUNCTION_ARGS)
|
1996-08-26 22:02:12 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
|
1997-09-08 04:41:22 +02:00
|
|
|
GISTScanOpaque p;
|
|
|
|
GISTSTACK *o,
|
|
|
|
*n,
|
|
|
|
*tmp;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
s->currentItemData = s->currentMarkData;
|
|
|
|
p = (GISTScanOpaque) s->opaque;
|
|
|
|
if (p->s_flags & GS_MRKBEFORE)
|
|
|
|
p->s_flags |= GS_CURBEFORE;
|
|
|
|
else
|
|
|
|
p->s_flags &= ~GS_CURBEFORE;
|
|
|
|
|
|
|
|
o = (GISTSTACK *) NULL;
|
|
|
|
n = p->s_markstk;
|
|
|
|
|
|
|
|
/* copy the parent stack from the current item data */
|
|
|
|
while (n != (GISTSTACK *) NULL)
|
|
|
|
{
|
|
|
|
tmp = (GISTSTACK *) palloc(sizeof(GISTSTACK));
|
|
|
|
tmp->gs_child = n->gs_child;
|
|
|
|
tmp->gs_blk = n->gs_blk;
|
|
|
|
tmp->gs_parent = o;
|
|
|
|
o = tmp;
|
|
|
|
n = n->gs_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
gistfreestack(p->s_stack);
|
|
|
|
p->s_stack = o;
|
2000-06-13 09:35:40 +02:00
|
|
|
|
2000-06-14 07:24:50 +02:00
|
|
|
PG_RETURN_VOID();
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
gistendscan(PG_FUNCTION_ARGS)
|
1996-08-26 22:02:12 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
|
|
|
|
GISTScanOpaque p;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
p = (GISTScanOpaque) s->opaque;
|
|
|
|
|
|
|
|
if (p != (GISTScanOpaque) NULL)
|
|
|
|
{
|
|
|
|
gistfreestack(p->s_stack);
|
|
|
|
gistfreestack(p->s_markstk);
|
2001-10-25 07:50:21 +02:00
|
|
|
if (p->giststate != NULL)
|
|
|
|
freeGISTstate(p->giststate);
|
1997-09-07 07:04:48 +02:00
|
|
|
pfree(s->opaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
gistdropscan(s);
|
|
|
|
/* XXX don't unset read lock -- two-phase locking */
|
2000-06-13 09:35:40 +02:00
|
|
|
|
2000-06-14 07:24:50 +02:00
|
|
|
PG_RETURN_VOID();
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gistregscan(IndexScanDesc s)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
GISTScanList l;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
l = (GISTScanList) palloc(sizeof(GISTScanListData));
|
|
|
|
l->gsl_scan = s;
|
|
|
|
l->gsl_next = GISTScans;
|
|
|
|
GISTScans = l;
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gistdropscan(IndexScanDesc s)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
GISTScanList l;
|
|
|
|
GISTScanList prev;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
prev = (GISTScanList) NULL;
|
|
|
|
|
|
|
|
for (l = GISTScans;
|
|
|
|
l != (GISTScanList) NULL && l->gsl_scan != s;
|
|
|
|
l = l->gsl_next)
|
|
|
|
prev = l;
|
|
|
|
|
|
|
|
if (l == (GISTScanList) NULL)
|
2000-04-12 19:17:23 +02:00
|
|
|
elog(ERROR, "GiST scan list corrupted -- cannot find 0x%p", (void *) s);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (prev == (GISTScanList) NULL)
|
|
|
|
GISTScans = l->gsl_next;
|
|
|
|
else
|
|
|
|
prev->gsl_next = l->gsl_next;
|
|
|
|
|
|
|
|
pfree(l);
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
Restructure index AM interface for index building and index tuple deletion,
per previous discussion on pghackers. Most of the duplicate code in
different AMs' ambuild routines has been moved out to a common routine
in index.c; this means that all index types now do the right things about
inserting recently-dead tuples, etc. (I also removed support for EXTEND
INDEX in the ambuild routines, since that's about to go away anyway, and
it cluttered the code a lot.) The retail indextuple deletion routines have
been replaced by a "bulk delete" routine in which the indexscan is inside
the access method. I haven't pushed this change as far as it should go yet,
but it should allow considerable simplification of the internal bookkeeping
for deletions. Also, add flag columns to pg_am to eliminate various
hardcoded tests on AM OIDs, and remove unused pg_am columns.
Fix rtree and gist index types to not attempt to store NULLs; before this,
gist usually crashed, while rtree managed not to crash but computed wacko
bounding boxes for NULL entries (which might have had something to do with
the performance problems we've heard about occasionally).
Add AtEOXact routines to hash, rtree, and gist, all of which have static
state that needs to be reset after an error. We discovered this need long
ago for btree, but missed the other guys.
Oh, one more thing: concurrent VACUUM is now the default.
2001-07-16 00:48:19 +02:00
|
|
|
/*
|
|
|
|
* AtEOXact_gist() --- clean up gist subsystem at xact abort or commit.
|
|
|
|
*
|
|
|
|
* This is here because it needs to touch this module's static var GISTScans.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
AtEOXact_gist(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Note: these actions should only be necessary during xact abort; but
|
|
|
|
* they can't hurt during a commit.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the active-scans list to empty. We do not need to free the
|
|
|
|
* list elements, because they're all palloc()'d, so they'll go away
|
|
|
|
* at end of transaction anyway.
|
|
|
|
*/
|
|
|
|
GISTScans = NULL;
|
|
|
|
}
|
|
|
|
|
1996-08-26 22:02:12 +02:00
|
|
|
void
|
1998-08-19 04:04:17 +02:00
|
|
|
gistadjscans(Relation rel, int op, BlockNumber blkno, OffsetNumber offnum)
|
1996-08-26 22:02:12 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
GISTScanList l;
|
|
|
|
Oid relid;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-08-19 04:04:17 +02:00
|
|
|
relid = RelationGetRelid(rel);
|
1997-09-07 07:04:48 +02:00
|
|
|
for (l = GISTScans; l != (GISTScanList) NULL; l = l->gsl_next)
|
|
|
|
{
|
|
|
|
if (l->gsl_scan->relation->rd_id == relid)
|
|
|
|
gistadjone(l->gsl_scan, op, blkno, offnum);
|
|
|
|
}
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* gistadjone() -- adjust one scan for update.
|
1996-08-26 22:02:12 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* By here, the scan passed in is on a modified relation. Op tells
|
|
|
|
* us what the modification is, and blkno and offind tell us what
|
|
|
|
* block and offset index were affected. This routine checks the
|
|
|
|
* current and marked positions, and the current and marked stacks,
|
|
|
|
* to see if any stored location needs to be changed because of the
|
|
|
|
* update. If so, we make the change here.
|
1996-08-26 22:02:12 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gistadjone(IndexScanDesc s,
|
1997-09-07 07:04:48 +02:00
|
|
|
int op,
|
|
|
|
BlockNumber blkno,
|
|
|
|
OffsetNumber offnum)
|
1996-08-26 22:02:12 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
GISTScanOpaque so;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
adjustiptr(s, &(s->currentItemData), op, blkno, offnum);
|
|
|
|
adjustiptr(s, &(s->currentMarkData), op, blkno, offnum);
|
|
|
|
|
|
|
|
so = (GISTScanOpaque) s->opaque;
|
|
|
|
|
|
|
|
if (op == GISTOP_SPLIT)
|
|
|
|
{
|
2002-03-05 06:30:40 +01:00
|
|
|
adjuststack(so->s_stack, blkno);
|
|
|
|
adjuststack(so->s_markstk, blkno);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* adjustiptr() -- adjust current and marked item pointers in the scan
|
1996-08-26 22:02:12 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Depending on the type of update and the place it happened, we
|
|
|
|
* need to do nothing, to back up one record, or to start over on
|
|
|
|
* the same page.
|
1996-08-26 22:02:12 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
adjustiptr(IndexScanDesc s,
|
1997-09-07 07:04:48 +02:00
|
|
|
ItemPointer iptr,
|
|
|
|
int op,
|
|
|
|
BlockNumber blkno,
|
|
|
|
OffsetNumber offnum)
|
1996-08-26 22:02:12 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
OffsetNumber curoff;
|
|
|
|
GISTScanOpaque so;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (ItemPointerIsValid(iptr))
|
|
|
|
{
|
|
|
|
if (ItemPointerGetBlockNumber(iptr) == blkno)
|
|
|
|
{
|
|
|
|
curoff = ItemPointerGetOffsetNumber(iptr);
|
|
|
|
so = (GISTScanOpaque) s->opaque;
|
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case GISTOP_DEL:
|
|
|
|
/* back up one if we need to */
|
|
|
|
if (curoff >= offnum)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
|
|
|
|
if (curoff > FirstOffsetNumber)
|
|
|
|
{
|
|
|
|
/* just adjust the item pointer */
|
|
|
|
ItemPointerSet(iptr, blkno, OffsetNumberPrev(curoff));
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
else
|
1997-09-08 04:41:22 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* remember that we're before the current
|
|
|
|
* tuple
|
|
|
|
*/
|
|
|
|
ItemPointerSet(iptr, blkno, FirstOffsetNumber);
|
|
|
|
if (iptr == &(s->currentItemData))
|
|
|
|
so->s_flags |= GS_CURBEFORE;
|
|
|
|
else
|
|
|
|
so->s_flags |= GS_MRKBEFORE;
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GISTOP_SPLIT:
|
|
|
|
/* back to start of page on split */
|
|
|
|
ItemPointerSet(iptr, blkno, FirstOffsetNumber);
|
|
|
|
if (iptr == &(s->currentItemData))
|
|
|
|
so->s_flags &= ~GS_CURBEFORE;
|
|
|
|
else
|
|
|
|
so->s_flags &= ~GS_MRKBEFORE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1998-01-07 22:07:04 +01:00
|
|
|
elog(ERROR, "Bad operation in GiST scan adjust: %d", op);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* adjuststack() -- adjust the supplied stack for a split on a page in
|
|
|
|
* the index we're scanning.
|
1996-08-26 22:02:12 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* If a page on our parent stack has split, we need to back up to the
|
|
|
|
* beginning of the page and rescan it. The reason for this is that
|
|
|
|
* the split algorithm for GiSTs doesn't order tuples in any useful
|
|
|
|
* way on a single page. This means on that a split, we may wind up
|
|
|
|
* looking at some heap tuples more than once. This is handled in the
|
|
|
|
* access method update code for heaps; if we've modified the tuple we
|
|
|
|
* are looking at already in this transaction, we ignore the update
|
|
|
|
* request.
|
1996-08-26 22:02:12 +02:00
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
|
|
|
static void
|
1997-09-08 23:56:23 +02:00
|
|
|
adjuststack(GISTSTACK *stk,
|
2002-03-05 06:30:40 +01:00
|
|
|
BlockNumber blkno)
|
1996-08-26 22:02:12 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
while (stk != (GISTSTACK *) NULL)
|
|
|
|
{
|
|
|
|
if (stk->gs_blk == blkno)
|
|
|
|
stk->gs_child = FirstOffsetNumber;
|
|
|
|
|
|
|
|
stk = stk->gs_parent;
|
|
|
|
}
|
1996-08-26 22:02:12 +02:00
|
|
|
}
|