@@ -110,9 +110,8 @@ gistkillitems(IndexScanDesc scan)
110
110
* Similarly, *recheck_distances_p is set to indicate whether the distances
111
111
* need to be rechecked, and it is also ignored for non-leaf entries.
112
112
*
113
- * If we are doing an ordered scan, so->distancesValues[] and
114
- * so->distancesNulls[] is filled with distance data from the distance()
115
- * functions before returning success.
113
+ * If we are doing an ordered scan, so->distances[] is filled with distance
114
+ * data from the distance() functions before returning success.
116
115
*
117
116
* We must decompress the key in the IndexTuple before passing it to the
118
117
* sk_funcs (which actually are the opclass Consistent or Distance methods).
@@ -133,8 +132,7 @@ gistindex_keytest(IndexScanDesc scan,
133
132
GISTSTATE * giststate = so -> giststate ;
134
133
ScanKey key = scan -> keyData ;
135
134
int keySize = scan -> numberOfKeys ;
136
- double * distance_value_p ;
137
- bool * distance_null_p ;
135
+ IndexOrderByDistance * distance_p ;
138
136
Relation r = scan -> indexRelation ;
139
137
140
138
* recheck_p = false;
@@ -153,8 +151,8 @@ gistindex_keytest(IndexScanDesc scan,
153
151
elog (ERROR ,"invalid GiST tuple found on leaf page" );
154
152
for (i = 0 ;i < scan -> numberOfOrderBys ;i ++ )
155
153
{
156
- so -> distanceValues [i ]= - get_float8_infinity ();
157
- so -> distanceNulls [i ]= false;
154
+ so -> distances [i ]. value = - get_float8_infinity ();
155
+ so -> distances [i ]. isnull = false;
158
156
}
159
157
return true;
160
158
}
@@ -238,8 +236,7 @@ gistindex_keytest(IndexScanDesc scan,
238
236
239
237
/* OK, it passes --- now let's compute the distances */
240
238
key = scan -> orderByData ;
241
- distance_value_p = so -> distanceValues ;
242
- distance_null_p = so -> distanceNulls ;
239
+ distance_p = so -> distances ;
243
240
keySize = scan -> numberOfOrderBys ;
244
241
while (keySize > 0 )
245
242
{
@@ -254,8 +251,8 @@ gistindex_keytest(IndexScanDesc scan,
254
251
if ((key -> sk_flags & SK_ISNULL )|| isNull )
255
252
{
256
253
/* Assume distance computes as null */
257
- * distance_value_p = 0.0 ;
258
- * distance_null_p = true;
254
+ distance_p -> value = 0.0 ;
255
+ distance_p -> isnull = true;
259
256
}
260
257
else
261
258
{
@@ -292,13 +289,12 @@ gistindex_keytest(IndexScanDesc scan,
292
289
ObjectIdGetDatum (key -> sk_subtype ),
293
290
PointerGetDatum (& recheck ));
294
291
* recheck_distances_p |=recheck ;
295
- * distance_value_p = DatumGetFloat8 (dist );
296
- * distance_null_p = false;
292
+ distance_p -> value = DatumGetFloat8 (dist );
293
+ distance_p -> isnull = false;
297
294
}
298
295
299
296
key ++ ;
300
- distance_value_p ++ ;
301
- distance_null_p ++ ;
297
+ distance_p ++ ;
302
298
keySize -- ;
303
299
}
304
300
@@ -311,8 +307,7 @@ gistindex_keytest(IndexScanDesc scan,
311
307
*
312
308
* scan: index scan we are executing
313
309
* pageItem: search queue item identifying an index page to scan
314
- * myDistanceValues: distances array associated with pageItem, or NULL at the root
315
- * myDistanceNulls: null flags for myDistanceValues array, or NULL at the root
310
+ * myDistances: distances array associated with pageItem, or NULL at the root
316
311
* tbm: if not NULL, gistgetbitmap's output bitmap
317
312
* ntids: if not NULL, gistgetbitmap's output tuple counter
318
313
*
@@ -330,8 +325,7 @@ gistindex_keytest(IndexScanDesc scan,
330
325
*/
331
326
static void
332
327
gistScanPage (IndexScanDesc scan ,GISTSearchItem * pageItem ,
333
- double * myDistanceValues ,bool * myDistanceNulls ,
334
- TIDBitmap * tbm ,int64 * ntids )
328
+ IndexOrderByDistance * myDistances ,TIDBitmap * tbm ,int64 * ntids )
335
329
{
336
330
GISTScanOpaque so = (GISTScanOpaque )scan -> opaque ;
337
331
GISTSTATE * giststate = so -> giststate ;
@@ -367,7 +361,7 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
367
361
GISTSearchItem * item ;
368
362
369
363
/* This can't happen when starting at the root */
370
- Assert (myDistanceValues != NULL && myDistanceNulls != NULL );
364
+ Assert (myDistances != NULL );
371
365
372
366
oldcxt = MemoryContextSwitchTo (so -> queueCxt );
373
367
@@ -377,10 +371,8 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
377
371
item -> data .parentlsn = pageItem -> data .parentlsn ;
378
372
379
373
/* Insert it into the queue using same distances as for this page */
380
- memcpy (GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys ),
381
- myDistanceValues ,sizeof (double )* scan -> numberOfOrderBys );
382
- memcpy (GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys ),
383
- myDistanceNulls ,sizeof (bool )* scan -> numberOfOrderBys );
374
+ memcpy (item -> distances ,myDistances ,
375
+ sizeof (item -> distances [0 ])* scan -> numberOfOrderBys );
384
376
385
377
pairingheap_add (so -> queue ,& item -> phNode );
386
378
@@ -510,10 +502,8 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
510
502
}
511
503
512
504
/* Insert it into the queue using new distance data */
513
- memcpy (GISTSearchItemDistanceValues (item ,nOrderBys ),
514
- so -> distanceValues ,sizeof (double )* nOrderBys );
515
- memcpy (GISTSearchItemDistanceNulls (item ,nOrderBys ),
516
- so -> distanceNulls ,sizeof (bool )* nOrderBys );
505
+ memcpy (item -> distances ,so -> distances ,
506
+ sizeof (item -> distances [0 ])* nOrderBys );
517
507
518
508
pairingheap_add (so -> queue ,& item -> phNode );
519
509
@@ -568,8 +558,6 @@ getNextNearest(IndexScanDesc scan)
568
558
do
569
559
{
570
560
GISTSearchItem * item = getNextGISTSearchItem (so );
571
- float8 * distanceValues = GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys );
572
- bool * distanceNulls = GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys );
573
561
574
562
if (!item )
575
563
break ;
@@ -589,8 +577,8 @@ getNextNearest(IndexScanDesc scan)
589
577
if (!scan -> xs_orderbynulls [i ])
590
578
pfree (DatumGetPointer (scan -> xs_orderbyvals [i ]));
591
579
#endif
592
- scan -> xs_orderbyvals [i ]= Float8GetDatum ( distanceValues [i ]) ;
593
- scan -> xs_orderbynulls [i ]= distanceNulls [i ];
580
+ scan -> xs_orderbyvals [i ]= item -> distances [i ]. value ;
581
+ scan -> xs_orderbynulls [i ]= item -> distances [i ]. isnull ;
594
582
}
595
583
else if (so -> orderByTypes [i ]== FLOAT4OID )
596
584
{
@@ -600,8 +588,8 @@ getNextNearest(IndexScanDesc scan)
600
588
if (!scan -> xs_orderbynulls [i ])
601
589
pfree (DatumGetPointer (scan -> xs_orderbyvals [i ]));
602
590
#endif
603
- scan -> xs_orderbyvals [i ]= Float4GetDatum (distanceValues [i ]);
604
- scan -> xs_orderbynulls [i ]= distanceNulls [i ];
591
+ scan -> xs_orderbyvals [i ]= Float4GetDatum (item -> distances [i ]. value );
592
+ scan -> xs_orderbynulls [i ]= item -> distances [i ]. isnull ;
605
593
}
606
594
else
607
595
{
@@ -629,10 +617,7 @@ getNextNearest(IndexScanDesc scan)
629
617
/* visit an index page, extract its items into queue */
630
618
CHECK_FOR_INTERRUPTS ();
631
619
632
- gistScanPage (scan ,item ,
633
- GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys ),
634
- GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys ),
635
- NULL ,NULL );
620
+ gistScanPage (scan ,item ,item -> distances ,NULL ,NULL );
636
621
}
637
622
638
623
pfree (item );
@@ -670,7 +655,7 @@ gistgettuple(IndexScanDesc scan, ScanDirection dir)
670
655
671
656
fakeItem .blkno = GIST_ROOT_BLKNO ;
672
657
memset (& fakeItem .data .parentlsn ,0 ,sizeof (GistNSN ));
673
- gistScanPage (scan ,& fakeItem ,NULL ,NULL ,NULL , NULL );
658
+ gistScanPage (scan ,& fakeItem ,NULL ,NULL ,NULL );
674
659
}
675
660
676
661
if (scan -> numberOfOrderBys > 0 )
@@ -764,10 +749,7 @@ gistgettuple(IndexScanDesc scan, ScanDirection dir)
764
749
* this page, we fall out of the inner "do" and loop around to
765
750
* return them.
766
751
*/
767
- gistScanPage (scan ,item ,
768
- GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys ),
769
- GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys ),
770
- NULL ,NULL );
752
+ gistScanPage (scan ,item ,item -> distances ,NULL ,NULL );
771
753
772
754
pfree (item );
773
755
}while (so -> nPageData == 0 );
@@ -798,7 +780,7 @@ gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
798
780
799
781
fakeItem .blkno = GIST_ROOT_BLKNO ;
800
782
memset (& fakeItem .data .parentlsn ,0 ,sizeof (GistNSN ));
801
- gistScanPage (scan ,& fakeItem ,NULL ,NULL , tbm ,& ntids );
783
+ gistScanPage (scan ,& fakeItem ,NULL ,tbm ,& ntids );
802
784
803
785
/*
804
786
* While scanning a leaf page, ItemPointers of matching heap tuples will
@@ -813,10 +795,7 @@ gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
813
795
814
796
CHECK_FOR_INTERRUPTS ();
815
797
816
- gistScanPage (scan ,item ,
817
- GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys ),
818
- GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys ),
819
- tbm ,& ntids );
798
+ gistScanPage (scan ,item ,item -> distances ,tbm ,& ntids );
820
799
821
800
pfree (item );
822
801
}