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.78 2008/10/20 16:35:14 teodor Exp $
11+ * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.79 2008/10/22 12:53:56 teodor Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -51,7 +51,7 @@ killtuple(Relation r, GISTScanOpaque so, ItemPointer iptr)
5151
5252 for (offset = FirstOffsetNumber ; offset <= maxoff ; offset = OffsetNumberNext (offset ))
5353 {
54- IndexTuple ituple = (IndexTuple ) PageGetItem (p , PageGetItemId (p , offset ));
54+ IndexTuple ituple = (IndexTuple ) PageGetItem (p , PageGetItemId (p , offset ));
5555
5656 if (ItemPointerEquals (& (ituple -> t_tid ), iptr ))
5757 {
@@ -139,24 +139,28 @@ gistnext(IndexScanDesc scan, TIDBitmap *tbm)
139139 if ( so -> qual_ok == false )
140140 return 0 ;
141141
142- if (ItemPointerIsValid ( & so -> curpos ) == false)
142+ if ( so -> curbuf == InvalidBuffer )
143143 {
144- /* Being asked to fetch the first entry, so start at the root */
145- Assert (so -> curbuf == InvalidBuffer );
146- Assert (so -> stack == NULL );
144+ if (ItemPointerIsValid (& so -> curpos ) == false)
145+ {
146+ /* Being asked to fetch the first entry, so start at the root */
147+ Assert (so -> curbuf == InvalidBuffer );
148+ Assert (so -> stack == NULL );
147149
148- so -> curbuf = ReadBuffer (scan -> indexRelation , GIST_ROOT_BLKNO );
150+ so -> curbuf = ReadBuffer (scan -> indexRelation , GIST_ROOT_BLKNO );
149151
150- stk = so -> stack = (GISTSearchStack * ) palloc0 (sizeof (GISTSearchStack ));
152+ stk = so -> stack = (GISTSearchStack * ) palloc0 (sizeof (GISTSearchStack ));
151153
152- stk -> next = NULL ;
153- stk -> block = GIST_ROOT_BLKNO ;
154+ stk -> next = NULL ;
155+ stk -> block = GIST_ROOT_BLKNO ;
154156
155- pgstat_count_index_scan (scan -> indexRelation );
156- }
157- else if (so -> curbuf == InvalidBuffer )
158- {
159- return 0 ;
157+ pgstat_count_index_scan (scan -> indexRelation );
158+ }
159+ else
160+ {
161+ /* scan is finished */
162+ return 0 ;
163+ }
160164 }
161165
162166 /*
@@ -171,8 +175,13 @@ gistnext(IndexScanDesc scan, TIDBitmap *tbm)
171175
172176 if ( so -> curPageData < so -> nPageData )
173177 {
174- scan -> xs_ctup .t_self = so -> pageData [ so -> curPageData ].iptr ;
178+ scan -> xs_ctup .t_self = so -> pageData [ so -> curPageData ].heapPtr ;
175179 scan -> xs_recheck = so -> pageData [ so -> curPageData ].recheck ;
180+
181+ ItemPointerSet (& so -> curpos ,
182+ BufferGetBlockNumber (so -> curbuf ),
183+ so -> pageData [ so -> curPageData ].pageOffset );
184+
176185 so -> curPageData ++ ;
177186
178187 return 1 ;
@@ -307,8 +316,6 @@ gistnext(IndexScanDesc scan, TIDBitmap *tbm)
307316 * return success. Note that we keep "curbuf" pinned so that
308317 * we can efficiently resume the index scan later.
309318 */
310- ItemPointerSet (& (so -> curpos ),
311- BufferGetBlockNumber (so -> curbuf ), n );
312319
313320 if (!(scan -> ignore_killed_tuples &&
314321 ItemIdIsDead (PageGetItemId (p , n ))))
@@ -319,7 +326,8 @@ gistnext(IndexScanDesc scan, TIDBitmap *tbm)
319326 tbm_add_tuples (tbm , & it -> t_tid , 1 , scan -> xs_recheck );
320327 else
321328 {
322- so -> pageData [ so -> nPageData ].iptr = it -> t_tid ;
329+ so -> pageData [ so -> nPageData ].heapPtr = it -> t_tid ;
330+ so -> pageData [ so -> nPageData ].pageOffset = n ;
323331 so -> pageData [ so -> nPageData ].recheck = scan -> xs_recheck ;
324332 so -> nPageData ++ ;
325333 }
0 commit comments