@@ -112,9 +112,8 @@ gistkillitems(IndexScanDesc scan)
112112 * Similarly, *recheck_distances_p is set to indicate whether the distances
113113 * need to be rechecked, and it is also ignored for non-leaf entries.
114114 *
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.
118117 *
119118 * We must decompress the key in the IndexTuple before passing it to the
120119 * sk_funcs (which actually are the opclass Consistent or Distance methods).
@@ -135,8 +134,7 @@ gistindex_keytest(IndexScanDesc scan,
135134GISTSTATE * giststate = so -> giststate ;
136135ScanKey key = scan -> keyData ;
137136int keySize = scan -> numberOfKeys ;
138- double * distance_value_p ;
139- bool * distance_null_p ;
137+ IndexOrderByDistance * distance_p ;
140138Relation r = scan -> indexRelation ;
141139
142140* recheck_p = false;
@@ -155,8 +153,8 @@ gistindex_keytest(IndexScanDesc scan,
155153elog (ERROR ,"invalid GiST tuple found on leaf page" );
156154for (i = 0 ;i < scan -> numberOfOrderBys ;i ++ )
157155{
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;
160158}
161159return true;
162160}
@@ -240,8 +238,7 @@ gistindex_keytest(IndexScanDesc scan,
240238
241239/* OK, it passes --- now let's compute the distances */
242240key = scan -> orderByData ;
243- distance_value_p = so -> distanceValues ;
244- distance_null_p = so -> distanceNulls ;
241+ distance_p = so -> distances ;
245242keySize = scan -> numberOfOrderBys ;
246243while (keySize > 0 )
247244{
@@ -256,8 +253,8 @@ gistindex_keytest(IndexScanDesc scan,
256253if ((key -> sk_flags & SK_ISNULL )|| isNull )
257254{
258255/* 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;
261258}
262259else
263260{
@@ -294,13 +291,12 @@ gistindex_keytest(IndexScanDesc scan,
294291ObjectIdGetDatum (key -> sk_subtype ),
295292PointerGetDatum (& recheck ));
296293* 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;
299296}
300297
301298key ++ ;
302- distance_value_p ++ ;
303- distance_null_p ++ ;
299+ distance_p ++ ;
304300keySize -- ;
305301}
306302
@@ -313,8 +309,7 @@ gistindex_keytest(IndexScanDesc scan,
313309 *
314310 * scan: index scan we are executing
315311 * 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
318313 * tbm: if not NULL, gistgetbitmap's output bitmap
319314 * ntids: if not NULL, gistgetbitmap's output tuple counter
320315 *
@@ -332,8 +327,7 @@ gistindex_keytest(IndexScanDesc scan,
332327 */
333328static void
334329gistScanPage (IndexScanDesc scan ,GISTSearchItem * pageItem ,
335- double * myDistanceValues ,bool * myDistanceNulls ,
336- TIDBitmap * tbm ,int64 * ntids )
330+ IndexOrderByDistance * myDistances ,TIDBitmap * tbm ,int64 * ntids )
337331{
338332GISTScanOpaque so = (GISTScanOpaque )scan -> opaque ;
339333GISTSTATE * giststate = so -> giststate ;
@@ -370,7 +364,7 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
370364GISTSearchItem * item ;
371365
372366/* This can't happen when starting at the root */
373- Assert (myDistanceValues != NULL && myDistanceNulls != NULL );
367+ Assert (myDistances != NULL );
374368
375369oldcxt = MemoryContextSwitchTo (so -> queueCxt );
376370
@@ -380,10 +374,8 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
380374item -> data .parentlsn = pageItem -> data .parentlsn ;
381375
382376/* 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 );
387379
388380pairingheap_add (so -> queue ,& item -> phNode );
389381
@@ -513,10 +505,8 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
513505}
514506
515507/* 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 );
520510
521511pairingheap_add (so -> queue ,& item -> phNode );
522512
@@ -571,8 +561,6 @@ getNextNearest(IndexScanDesc scan)
571561do
572562{
573563GISTSearchItem * item = getNextGISTSearchItem (so );
574- float8 * distanceValues = GISTSearchItemDistanceValues (item ,scan -> numberOfOrderBys );
575- bool * distanceNulls = GISTSearchItemDistanceNulls (item ,scan -> numberOfOrderBys );
576564
577565if (!item )
578566break ;
@@ -592,8 +580,8 @@ getNextNearest(IndexScanDesc scan)
592580if (!scan -> xs_orderbynulls [i ])
593581pfree (DatumGetPointer (scan -> xs_orderbyvals [i ]));
594582#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 ;
597585}
598586else if (so -> orderByTypes [i ]== FLOAT4OID )
599587{
@@ -603,8 +591,8 @@ getNextNearest(IndexScanDesc scan)
603591if (!scan -> xs_orderbynulls [i ])
604592pfree (DatumGetPointer (scan -> xs_orderbyvals [i ]));
605593#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 ;
608596}
609597else
610598{
@@ -632,10 +620,7 @@ getNextNearest(IndexScanDesc scan)
632620/* visit an index page, extract its items into queue */
633621CHECK_FOR_INTERRUPTS ();
634622
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 );
639624}
640625
641626pfree (item );
@@ -673,7 +658,7 @@ gistgettuple(IndexScanDesc scan, ScanDirection dir)
673658
674659fakeItem .blkno = GIST_ROOT_BLKNO ;
675660memset (& fakeItem .data .parentlsn ,0 ,sizeof (GistNSN ));
676- gistScanPage (scan ,& fakeItem ,NULL ,NULL ,NULL , NULL );
661+ gistScanPage (scan ,& fakeItem ,NULL ,NULL ,NULL );
677662}
678663
679664if (scan -> numberOfOrderBys > 0 )
@@ -767,10 +752,7 @@ gistgettuple(IndexScanDesc scan, ScanDirection dir)
767752 * this page, we fall out of the inner "do" and loop around to
768753 * return them.
769754 */
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 );
774756
775757pfree (item );
776758}while (so -> nPageData == 0 );
@@ -801,7 +783,7 @@ gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
801783
802784fakeItem .blkno = GIST_ROOT_BLKNO ;
803785memset (& fakeItem .data .parentlsn ,0 ,sizeof (GistNSN ));
804- gistScanPage (scan ,& fakeItem ,NULL ,NULL , tbm ,& ntids );
786+ gistScanPage (scan ,& fakeItem ,NULL ,tbm ,& ntids );
805787
806788/*
807789 * While scanning a leaf page, ItemPointers of matching heap tuples will
@@ -816,10 +798,7 @@ gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
816798
817799CHECK_FOR_INTERRUPTS ();
818800
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 );
823802
824803pfree (item );
825804}