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.77 2008/10/20 13:39:44 teodor Exp $
11+ * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.78 2008/10/20 16:35:14 teodor Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
2323#include "utils/memutils.h"
2424
2525
26- static OffsetNumber gistfindnext (IndexScanDesc scan , OffsetNumber n ,
27- ScanDirection dir );
28- static int64 gistnext (IndexScanDesc scan , ScanDirection dir , TIDBitmap * tbm );
26+ static OffsetNumber gistfindnext (IndexScanDesc scan , OffsetNumber n );
27+ static int64 gistnext (IndexScanDesc scan , TIDBitmap * tbm );
2928static bool gistindex_keytest (IndexTuple tuple , IndexScanDesc scan ,
3029 OffsetNumber offset );
3130
@@ -80,6 +79,9 @@ gistgettuple(PG_FUNCTION_ARGS)
8079
8180 so = (GISTScanOpaque ) scan -> opaque ;
8281
82+ if (dir != ForwardScanDirection )
83+ elog (ERROR , "GiST doesn't support other scan directions than forward" );
84+
8385 /*
8486 * If we have produced an index tuple in the past and the executor has
8587 * informed us we need to mark it as "killed", do so now.
@@ -90,7 +92,7 @@ gistgettuple(PG_FUNCTION_ARGS)
9092 /*
9193 * Get the next tuple that matches the search key.
9294 */
93- res = (gistnext (scan , dir , NULL ) > 0 );
95+ res = (gistnext (scan , NULL ) > 0 );
9496
9597 PG_RETURN_BOOL (res );
9698}
@@ -102,7 +104,7 @@ gistgetbitmap(PG_FUNCTION_ARGS)
102104 TIDBitmap * tbm = (TIDBitmap * ) PG_GETARG_POINTER (1 );
103105 int64 ntids ;
104106
105- ntids = gistnext (scan , ForwardScanDirection , tbm );
107+ ntids = gistnext (scan , tbm );
106108
107109 PG_RETURN_INT64 (ntids );
108110}
@@ -122,7 +124,7 @@ gistgetbitmap(PG_FUNCTION_ARGS)
122124 * non-killed tuple that matches the search key.
123125 */
124126static int64
125- gistnext (IndexScanDesc scan , ScanDirection dir , TIDBitmap * tbm )
127+ gistnext (IndexScanDesc scan , TIDBitmap * tbm )
126128{
127129 Page p ;
128130 OffsetNumber n ;
@@ -169,9 +171,6 @@ gistnext(IndexScanDesc scan, ScanDirection dir, TIDBitmap *tbm)
169171
170172 if ( so -> curPageData < so -> nPageData )
171173 {
172- /*
173- * pageData is already ordered for scan's direction
174- */
175174 scan -> xs_ctup .t_self = so -> pageData [ so -> curPageData ].iptr ;
176175 scan -> xs_recheck = so -> pageData [ so -> curPageData ].recheck ;
177176 so -> curPageData ++ ;
@@ -252,17 +251,14 @@ gistnext(IndexScanDesc scan, ScanDirection dir, TIDBitmap *tbm)
252251 continue ;
253252 }
254253
255- if (ScanDirectionIsBackward (dir ))
256- n = PageGetMaxOffsetNumber (p );
257- else
258- n = FirstOffsetNumber ;
254+ n = FirstOffsetNumber ;
259255
260256 /* wonderful, we can look at page */
261257 so -> nPageData = so -> curPageData = 0 ;
262258
263259 for (;;)
264260 {
265- n = gistfindnext (scan , n , dir );
261+ n = gistfindnext (scan , n );
266262
267263 if (!OffsetNumberIsValid (n ))
268264 {
@@ -275,7 +271,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir, TIDBitmap *tbm)
275271 if ( !tbm && so -> nPageData > 0 )
276272 {
277273 LockBuffer (so -> curbuf , GIST_UNLOCK );
278- return gistnext (scan , dir , NULL );
274+ return gistnext (scan , NULL );
279275 }
280276
281277 /*
@@ -346,10 +342,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir, TIDBitmap *tbm)
346342 so -> stack -> next = stk ;
347343 }
348344
349- if (ScanDirectionIsBackward (dir ))
350- n = OffsetNumberPrev (n );
351- else
352- n = OffsetNumberNext (n );
345+ n = OffsetNumberNext (n );
353346 }
354347 }
355348
@@ -475,7 +468,7 @@ gistindex_keytest(IndexTuple tuple,
475468 * Page should be locked....
476469 */
477470static OffsetNumber
478- gistfindnext (IndexScanDesc scan , OffsetNumber n , ScanDirection dir )
471+ gistfindnext (IndexScanDesc scan , OffsetNumber n )
479472{
480473 OffsetNumber maxoff ;
481474 IndexTuple it ;
@@ -500,10 +493,7 @@ gistfindnext(IndexScanDesc scan, OffsetNumber n, ScanDirection dir)
500493 if (gistindex_keytest (it , scan , n ))
501494 break ;
502495
503- if (ScanDirectionIsBackward (dir ))
504- n = OffsetNumberPrev (n );
505- else
506- n = OffsetNumberNext (n );
496+ n = OffsetNumberNext (n );
507497 }
508498
509499 MemoryContextSwitchTo (oldcxt );
0 commit comments