8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
23
23
#include "utils/memutils.h"
24
24
25
25
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 );
29
28
static bool gistindex_keytest (IndexTuple tuple , IndexScanDesc scan ,
30
29
OffsetNumber offset );
31
30
@@ -80,6 +79,9 @@ gistgettuple(PG_FUNCTION_ARGS)
80
79
81
80
so = (GISTScanOpaque ) scan -> opaque ;
82
81
82
+ if (dir != ForwardScanDirection )
83
+ elog (ERROR , "GiST doesn't support other scan directions than forward" );
84
+
83
85
/*
84
86
* If we have produced an index tuple in the past and the executor has
85
87
* informed us we need to mark it as "killed", do so now.
@@ -90,7 +92,7 @@ gistgettuple(PG_FUNCTION_ARGS)
90
92
/*
91
93
* Get the next tuple that matches the search key.
92
94
*/
93
- res = (gistnext (scan , dir , NULL ) > 0 );
95
+ res = (gistnext (scan , NULL ) > 0 );
94
96
95
97
PG_RETURN_BOOL (res );
96
98
}
@@ -102,7 +104,7 @@ gistgetbitmap(PG_FUNCTION_ARGS)
102
104
TIDBitmap * tbm = (TIDBitmap * ) PG_GETARG_POINTER (1 );
103
105
int64 ntids ;
104
106
105
- ntids = gistnext (scan , ForwardScanDirection , tbm );
107
+ ntids = gistnext (scan , tbm );
106
108
107
109
PG_RETURN_INT64 (ntids );
108
110
}
@@ -122,7 +124,7 @@ gistgetbitmap(PG_FUNCTION_ARGS)
122
124
* non-killed tuple that matches the search key.
123
125
*/
124
126
static int64
125
- gistnext (IndexScanDesc scan , ScanDirection dir , TIDBitmap * tbm )
127
+ gistnext (IndexScanDesc scan , TIDBitmap * tbm )
126
128
{
127
129
Page p ;
128
130
OffsetNumber n ;
@@ -169,9 +171,6 @@ gistnext(IndexScanDesc scan, ScanDirection dir, TIDBitmap *tbm)
169
171
170
172
if ( so -> curPageData < so -> nPageData )
171
173
{
172
- /*
173
- * pageData is already ordered for scan's direction
174
- */
175
174
scan -> xs_ctup .t_self = so -> pageData [ so -> curPageData ].iptr ;
176
175
scan -> xs_recheck = so -> pageData [ so -> curPageData ].recheck ;
177
176
so -> curPageData ++ ;
@@ -252,17 +251,14 @@ gistnext(IndexScanDesc scan, ScanDirection dir, TIDBitmap *tbm)
252
251
continue ;
253
252
}
254
253
255
- if (ScanDirectionIsBackward (dir ))
256
- n = PageGetMaxOffsetNumber (p );
257
- else
258
- n = FirstOffsetNumber ;
254
+ n = FirstOffsetNumber ;
259
255
260
256
/* wonderful, we can look at page */
261
257
so -> nPageData = so -> curPageData = 0 ;
262
258
263
259
for (;;)
264
260
{
265
- n = gistfindnext (scan , n , dir );
261
+ n = gistfindnext (scan , n );
266
262
267
263
if (!OffsetNumberIsValid (n ))
268
264
{
@@ -275,7 +271,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir, TIDBitmap *tbm)
275
271
if ( !tbm && so -> nPageData > 0 )
276
272
{
277
273
LockBuffer (so -> curbuf , GIST_UNLOCK );
278
- return gistnext (scan , dir , NULL );
274
+ return gistnext (scan , NULL );
279
275
}
280
276
281
277
/*
@@ -346,10 +342,7 @@ gistnext(IndexScanDesc scan, ScanDirection dir, TIDBitmap *tbm)
346
342
so -> stack -> next = stk ;
347
343
}
348
344
349
- if (ScanDirectionIsBackward (dir ))
350
- n = OffsetNumberPrev (n );
351
- else
352
- n = OffsetNumberNext (n );
345
+ n = OffsetNumberNext (n );
353
346
}
354
347
}
355
348
@@ -475,7 +468,7 @@ gistindex_keytest(IndexTuple tuple,
475
468
* Page should be locked....
476
469
*/
477
470
static OffsetNumber
478
- gistfindnext (IndexScanDesc scan , OffsetNumber n , ScanDirection dir )
471
+ gistfindnext (IndexScanDesc scan , OffsetNumber n )
479
472
{
480
473
OffsetNumber maxoff ;
481
474
IndexTuple it ;
@@ -500,10 +493,7 @@ gistfindnext(IndexScanDesc scan, OffsetNumber n, ScanDirection dir)
500
493
if (gistindex_keytest (it , scan , n ))
501
494
break ;
502
495
503
- if (ScanDirectionIsBackward (dir ))
504
- n = OffsetNumberPrev (n );
505
- else
506
- n = OffsetNumberNext (n );
496
+ n = OffsetNumberNext (n );
507
497
}
508
498
509
499
MemoryContextSwitchTo (oldcxt );
0 commit comments