@@ -112,9 +112,8 @@ gistkillitems(IndexScanDesc scan)
112
112
* Similarly, *recheck_distances_p is set to indicate whether the distances
113
113
* need to be rechecked, and it is also ignored for non-leaf entries.
114
114
*
115
- * If we are doing an ordered scan, so->distancesValues[] and
116
- * so->distancesNulls[] is filled with distance data from the distance()
117
- * functions before returning success.
115
+ * If we are doing an ordered scan, so->distances[] is filled with distance
116
+ * data from the distance() functions before returning success.
118
117
*
119
118
* We must decompress the key in the IndexTuple before passing it to the
120
119
* sk_funcs (which actually are the opclass Consistent or Distance methods).
@@ -135,8 +134,7 @@ gistindex_keytest(IndexScanDesc scan,
135
134
GISTSTATE * giststate = so -> giststate ;
136
135
ScanKey key = scan -> keyData ;
137
136
int keySize = scan -> numberOfKeys ;
138
- double * distance_value_p ;
139
- bool * distance_null_p ;
137
+ IndexOrderByDistance * distance_p ;
140
138
Relation r = scan -> indexRelation ;
141
139
142
140
* recheck_p = false;
@@ -155,8 +153,8 @@ gistindex_keytest(IndexScanDesc scan,
155
153
elog (ERROR ,"invalid GiST tuple found on leaf page" );
156
154
for (i = 0 ;i < scan -> numberOfOrderBys ;i ++ )
157
155
{
158
- so -> distanceValues [i ]= - get_float8_infinity ();
159
- so -> distanceNulls [i ]= false;
156
+ so -> distances [i ]. value = - get_float8_infinity ();
157
+ so -> distances [i ]. isnull = false;
160
158
}
161
159
return true;
162
160
}
@@ -240,8 +238,7 @@ gistindex_keytest(IndexScanDesc scan,
240
238
241
239
/* OK, it passes --- now let's compute the distances */
242
240
key = scan -> orderByData ;
243
- distance_value_p = so -> distanceValues ;
244
- distance_null_p = so -> distanceNulls ;
241
+ distance_p = so -> distances ;
245
242
keySize = scan -> numberOfOrderBys ;
246
243
while (keySize > 0 )
247
244
{
@@ -256,8 +253,8 @@ gistindex_keytest(IndexScanDesc scan,
256
253
if ((key -> sk_flags & SK_ISNULL )|| isNull )
257
254
{
258
255
/* Assume distance computes as null */
259
- * distance_value_p = 0.0 ;
260
- * distance_null_p = true;
256
+ distance_p -> value = 0.0 ;
257
+ distance_p -> isnull = true;
261
258
}
262
259
else
263
260
{
@@ -294,13 +291,12 @@ gistindex_keytest(IndexScanDesc scan,
294
291
ObjectIdGetDatum (key -> sk_subtype ),
295
292
PointerGetDatum (& recheck ));
296
293
* recheck_distances_p |=recheck ;
297
- * distance_value_p = DatumGetFloat8 (dist );
298
- * distance_null_p = false;
294
+ distance_p -> value = DatumGetFloat8 (dist );
295
+ distance_p -> isnull = false;
299
296
}
300
297
301
298
key ++ ;
302
- distance_value_p ++ ;
303
- distance_null_p ++ ;
299
+ distance_p ++ ;
304
300
keySize -- ;
305
301
}
306
302
@@ -313,8 +309,7 @@ gistindex_keytest(IndexScanDesc scan,
313
309
*
314
310
* scan: index scan we are executing
315
311
* pageItem: search queue item identifying an index page to scan
316
- * myDistanceValues: distances array associated with pageItem, or NULL at the root
317
- * myDistanceNulls: null flags for myDistanceValues array, or NULL at the root
312
+ * myDistances: distances array associated with pageItem, or NULL at the root
318
313
* tbm: if not NULL, gistgetbitmap's output bitmap
319
314
* ntids: if not NULL, gistgetbitmap's output tuple counter
320
315
*
@@ -332,8 +327,7 @@ gistindex_keytest(IndexScanDesc scan,
332
327
*/
333
328
static void
334
329
gistScanPage (IndexScanDesc scan ,GISTSearchItem * pageItem ,
335
- double * myDistanceValues ,bool * myDistanceNulls ,
336
- TIDBitmap * tbm ,int64 * ntids )
330
+ IndexOrderByDistance * myDistances ,TIDBitmap * tbm ,int64 * ntids )
337
331
{
338
332
GISTScanOpaque so = (GISTScanOpaque )scan -> opaque ;
339
333
GISTSTATE * giststate = so -> giststate ;
@@ -370,7 +364,7 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
370
364
GISTSearchItem * item ;
371
365
372
366
/* This can't happen when starting at the root */
373
- Assert (myDistanceValues != NULL && myDistanceNulls != NULL );
367
+ Assert (myDistances != NULL );
374
368
375
369
oldcxt = MemoryContextSwitchTo (so -> queueCxt );
376
370
@@ -380,10 +374,8 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
380
374
item -> data .parentlsn = pageItem -> data .parentlsn ;
381
375
382
376
/* Insert it into the queue using same distances as for this page */
383
- memcpy (GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys ),
384
- myDistanceValues ,sizeof (double )* scan -> numberOfOrderBys );
385
- memcpy (GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys ),
386
- myDistanceNulls ,sizeof (bool )* scan -> numberOfOrderBys );
377
+ memcpy (item -> distances ,myDistances ,
378
+ sizeof (item -> distances [0 ])* scan -> numberOfOrderBys );
387
379
388
380
pairingheap_add (so -> queue ,& item -> phNode );
389
381
@@ -513,10 +505,8 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
513
505
}
514
506
515
507
/* Insert it into the queue using new distance data */
516
- memcpy (GISTSearchItemDistanceValues (item ,nOrderBys ),
517
- so -> distanceValues ,sizeof (double )* nOrderBys );
518
- memcpy (GISTSearchItemDistanceNulls (item ,nOrderBys ),
519
- so -> distanceNulls ,sizeof (bool )* nOrderBys );
508
+ memcpy (item -> distances ,so -> distances ,
509
+ sizeof (item -> distances [0 ])* nOrderBys );
520
510
521
511
pairingheap_add (so -> queue ,& item -> phNode );
522
512
@@ -571,8 +561,6 @@ getNextNearest(IndexScanDesc scan)
571
561
do
572
562
{
573
563
GISTSearchItem * item = getNextGISTSearchItem (so );
574
- float8 * distanceValues = GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys );
575
- bool * distanceNulls = GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys );
576
564
577
565
if (!item )
578
566
break ;
@@ -592,8 +580,8 @@ getNextNearest(IndexScanDesc scan)
592
580
if (!scan -> xs_orderbynulls [i ])
593
581
pfree (DatumGetPointer (scan -> xs_orderbyvals [i ]));
594
582
#endif
595
- scan -> xs_orderbyvals [i ]= Float8GetDatum ( distanceValues [i ]) ;
596
- scan -> xs_orderbynulls [i ]= distanceNulls [i ];
583
+ scan -> xs_orderbyvals [i ]= item -> distances [i ]. value ;
584
+ scan -> xs_orderbynulls [i ]= item -> distances [i ]. isnull ;
597
585
}
598
586
else if (so -> orderByTypes [i ]== FLOAT4OID )
599
587
{
@@ -603,8 +591,8 @@ getNextNearest(IndexScanDesc scan)
603
591
if (!scan -> xs_orderbynulls [i ])
604
592
pfree (DatumGetPointer (scan -> xs_orderbyvals [i ]));
605
593
#endif
606
- scan -> xs_orderbyvals [i ]= Float4GetDatum (distanceValues [i ]);
607
- scan -> xs_orderbynulls [i ]= distanceNulls [i ];
594
+ scan -> xs_orderbyvals [i ]= Float4GetDatum (item -> distances [i ]. value );
595
+ scan -> xs_orderbynulls [i ]= item -> distances [i ]. isnull ;
608
596
}
609
597
else
610
598
{
@@ -632,10 +620,7 @@ getNextNearest(IndexScanDesc scan)
632
620
/* visit an index page, extract its items into queue */
633
621
CHECK_FOR_INTERRUPTS ();
634
622
635
- gistScanPage (scan ,item ,
636
- GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys ),
637
- GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys ),
638
- NULL ,NULL );
623
+ gistScanPage (scan ,item ,item -> distances ,NULL ,NULL );
639
624
}
640
625
641
626
pfree (item );
@@ -673,7 +658,7 @@ gistgettuple(IndexScanDesc scan, ScanDirection dir)
673
658
674
659
fakeItem .blkno = GIST_ROOT_BLKNO ;
675
660
memset (& fakeItem .data .parentlsn ,0 ,sizeof (GistNSN ));
676
- gistScanPage (scan ,& fakeItem ,NULL ,NULL ,NULL , NULL );
661
+ gistScanPage (scan ,& fakeItem ,NULL ,NULL ,NULL );
677
662
}
678
663
679
664
if (scan -> numberOfOrderBys > 0 )
@@ -767,10 +752,7 @@ gistgettuple(IndexScanDesc scan, ScanDirection dir)
767
752
* this page, we fall out of the inner "do" and loop around to
768
753
* return them.
769
754
*/
770
- gistScanPage (scan ,item ,
771
- GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys ),
772
- GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys ),
773
- NULL ,NULL );
755
+ gistScanPage (scan ,item ,item -> distances ,NULL ,NULL );
774
756
775
757
pfree (item );
776
758
}while (so -> nPageData == 0 );
@@ -801,7 +783,7 @@ gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
801
783
802
784
fakeItem .blkno = GIST_ROOT_BLKNO ;
803
785
memset (& fakeItem .data .parentlsn ,0 ,sizeof (GistNSN ));
804
- gistScanPage (scan ,& fakeItem ,NULL ,NULL , tbm ,& ntids );
786
+ gistScanPage (scan ,& fakeItem ,NULL ,tbm ,& ntids );
805
787
806
788
/*
807
789
* While scanning a leaf page, ItemPointers of matching heap tuples will
@@ -816,10 +798,7 @@ gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
816
798
817
799
CHECK_FOR_INTERRUPTS ();
818
800
819
- gistScanPage (scan ,item ,
820
- GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys ),
821
- GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys ),
822
- tbm ,& ntids );
801
+ gistScanPage (scan ,item ,item -> distances ,tbm ,& ntids );
823
802
824
803
pfree (item );
825
804
}