88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.70 2008/04/10 22:25:25 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.71 2008/04/13 19:18:14 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
2323
2424static OffsetNumber gistfindnext (IndexScanDesc scan ,OffsetNumber n ,
2525ScanDirection dir );
26- static int64 gistnext (IndexScanDesc scan ,ScanDirection dir ,
27- ItemPointer tid ,TIDBitmap * tbm ,
28- bool ignore_killed_tuples );
26+ static int64 gistnext (IndexScanDesc scan ,ScanDirection dir ,TIDBitmap * tbm );
2927static bool gistindex_keytest (IndexTuple tuple ,IndexScanDesc scan ,
3028OffsetNumber offset );
3129
@@ -100,7 +98,6 @@ gistgettuple(PG_FUNCTION_ARGS)
10098IndexScanDesc scan = (IndexScanDesc )PG_GETARG_POINTER (0 );
10199ScanDirection dir = (ScanDirection )PG_GETARG_INT32 (1 );
102100GISTScanOpaque so ;
103- ItemPointerData tid ;
104101bool res ;
105102
106103so = (GISTScanOpaque )scan -> opaque ;
@@ -113,11 +110,9 @@ gistgettuple(PG_FUNCTION_ARGS)
113110killtuple (scan -> indexRelation ,so ,& (so -> curpos ));
114111
115112/*
116- * Get the next tuple that matches the search key. If asked to skip killed
117- * tuples, continue looping until we find a non-killed tuple that matches
118- * the search key.
113+ * Get the next tuple that matches the search key.
119114 */
120- res = (gistnext (scan ,dir ,& tid , NULL , scan -> ignore_killed_tuples )> 0 ) ? true : false ;
115+ res = (gistnext (scan ,dir ,NULL )> 0 );
121116
122117PG_RETURN_BOOL (res );
123118}
@@ -129,7 +124,7 @@ gistgetbitmap(PG_FUNCTION_ARGS)
129124TIDBitmap * tbm = (TIDBitmap * )PG_GETARG_POINTER (1 );
130125int64 ntids ;
131126
132- ntids = gistnext (scan ,ForwardScanDirection ,NULL , tbm , false );
127+ ntids = gistnext (scan ,ForwardScanDirection ,tbm );
133128
134129PG_RETURN_INT64 (ntids );
135130}
@@ -140,20 +135,23 @@ gistgetbitmap(PG_FUNCTION_ARGS)
140135 *
141136 * This function is used by both gistgettuple and gistgetbitmap. When
142137 * invoked from gistgettuple, tbm is null and the next matching tuple
143- * is returned in *tid. When invoked from getbitmap, tid is null and
144- * all matching tuples are added to tbm. In both cases, the function
145- * result is the number of returned tuples.
138+ * is returned in scan->xs_ctup.t_self. When invoked from getbitmap,
139+ * tbm is non-null and all matching tuples are added to tbm before
140+ * returning. In both cases, the function result is the number of
141+ * returned tuples.
142+ *
143+ * If scan specifies to skip killed tuples, continue looping until we find a
144+ * non-killed tuple that matches the search key.
146145 */
147146static int64
148- gistnext (IndexScanDesc scan ,ScanDirection dir ,
149- ItemPointer tid ,TIDBitmap * tbm ,
150- bool ignore_killed_tuples )
147+ gistnext (IndexScanDesc scan ,ScanDirection dir ,TIDBitmap * tbm )
151148{
152149Page p ;
153150OffsetNumber n ;
154151GISTScanOpaque so ;
155152GISTSearchStack * stk ;
156153IndexTuple it ;
154+ bool recheck ;
157155GISTPageOpaque opaque ;
158156bool resetoffset = false;
159157int64 ntids = 0 ;
@@ -194,7 +192,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir,
194192
195193if (XLogRecPtrIsInvalid (so -> stack -> lsn )|| !XLByteEQ (so -> stack -> lsn ,PageGetLSN (p )))
196194{
197- /* page changed from last visit or visit first time , reset offset */
195+ /*first visit or page changed from last visit, reset offset */
198196so -> stack -> lsn = PageGetLSN (p );
199197resetoffset = true;
200198
@@ -259,6 +257,8 @@ gistnext(IndexScanDesc scan, ScanDirection dir,
259257for (;;)
260258{
261259n = gistfindnext (scan ,n ,dir );
260+ /* XXX for the moment, treat all GIST operators as lossy */
261+ recheck = true;
262262
263263if (!OffsetNumberIsValid (n ))
264264{
@@ -298,15 +298,17 @@ gistnext(IndexScanDesc scan, ScanDirection dir,
298298ItemPointerSet (& (so -> curpos ),
299299BufferGetBlockNumber (so -> curbuf ),n );
300300
301- if (!(ignore_killed_tuples && ItemIdIsDead (PageGetItemId (p ,n ))))
301+ if (!(scan -> ignore_killed_tuples &&
302+ ItemIdIsDead (PageGetItemId (p ,n ))))
302303{
303304it = (IndexTuple )PageGetItem (p ,PageGetItemId (p ,n ));
304305ntids ++ ;
305306if (tbm != NULL )
306- tbm_add_tuples (tbm ,& it -> t_tid ,1 ,false );
307+ tbm_add_tuples (tbm ,& it -> t_tid ,1 ,recheck );
307308else
308309{
309- * tid = scan -> xs_ctup .t_self = it -> t_tid ;
310+ scan -> xs_ctup .t_self = it -> t_tid ;
311+ scan -> xs_recheck = recheck ;
310312
311313LockBuffer (so -> curbuf ,GIST_UNLOCK );
312314return ntids ;/* always 1 */