* Similarly, *recheck_distances_p is set to indicate whether the distances
* need to be rechecked, and it is also ignored for non-leaf entries.
*
- * If we are doing an ordered scan, so->distances[] is filled with distance
- * data from the distance() functions before returning success.
+ * If we are doing an ordered scan, so->distancesValues[] and
+ * so->distancesNulls[] is filled with distance data from the distance()
+ * functions before returning success.
*
* We must decompress the key in the IndexTuple before passing it to the
* sk_funcs (which actually are the opclass Consistent or Distance methods).
GISTSTATE *giststate = so->giststate;
ScanKey key = scan->keyData;
int keySize = scan->numberOfKeys;
- double *distance_p;
+ double *distance_value_p;
+ bool *distance_null_p;
Relation r = scan->indexRelation;
*recheck_p = false;
if (GistPageIsLeaf(page)) /* shouldn't happen */
elog(ERROR, "invalid GiST tuple found on leaf page");
for (i = 0; i < scan->numberOfOrderBys; i++)
- so->distances[i] = -get_float8_infinity();
+ {
+ so->distanceValues[i] = -get_float8_infinity();
+ so->distanceNulls[i] = false;
+ }
return true;
}
/* OK, it passes --- now let's compute the distances */
key = scan->orderByData;
- distance_p = so->distances;
+ distance_value_p = so->distanceValues;
+ distance_null_p = so->distanceNulls;
keySize = scan->numberOfOrderBys;
while (keySize > 0)
{
if ((key->sk_flags & SK_ISNULL) || isNull)
{
- /* Assume distance computes as null and sorts to the end */
- *distance_p = get_float8_infinity();
+ /* Assume distance computes as null */
+ *distance_value_p = 0.0;
+ *distance_null_p = true;
}
else
{
ObjectIdGetDatum(key->sk_subtype),
PointerGetDatum(&recheck));
*recheck_distances_p |= recheck;
- *distance_p = DatumGetFloat8(dist);
+ *distance_value_p = DatumGetFloat8(dist);
+ *distance_null_p = false;
}
key++;
- distance_p++;
+ distance_value_p++;
+ distance_null_p++;
keySize--;
}
*
* scan: index scan we are executing
* pageItem: search queue item identifying an index page to scan
- * myDistances: distances array associated with pageItem, or NULL at the root
+ * myDistanceValues: distances array associated with pageItem, or NULL at the root
+ * myDistanceNulls: null flags for myDistanceValues array, or NULL at the root
* tbm: if not NULL, gistgetbitmap's output bitmap
* ntids: if not NULL, gistgetbitmap's output tuple counter
*
* sibling will be processed next.
*/
static void
-gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem, double *myDistances,
+gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
+ double *myDistanceValues, bool *myDistanceNulls,
TIDBitmap *tbm, int64 *ntids)
{
GISTScanOpaque so = (GISTScanOpaque) scan->opaque;
GISTSearchItem *item;
/* This can't happen when starting at the root */
- Assert(myDistances != NULL);
+ Assert(myDistanceValues != NULL && myDistanceNulls != NULL);
oldcxt = MemoryContextSwitchTo(so->queueCxt);
item->data.parentlsn = pageItem->data.parentlsn;
/* Insert it into the queue using same distances as for this page */
- memcpy(item->distances, myDistances,
- sizeof(double) * scan->numberOfOrderBys);
+ memcpy(GISTSearchItemDistanceValues(item, scan->numberOfOrderBys),
+ myDistanceValues, sizeof(double) * scan->numberOfOrderBys);
+ memcpy(GISTSearchItemDistanceNulls(item, scan->numberOfOrderBys),
+ myDistanceNulls, sizeof(bool) * scan->numberOfOrderBys);
pairingheap_add(so->queue, &item->phNode);
* search.
*/
GISTSearchItem *item;
+ int nOrderBys = scan->numberOfOrderBys;
oldcxt = MemoryContextSwitchTo(so->queueCxt);
}
/* Insert it into the queue using new distance data */
- memcpy(item->distances, so->distances,
- sizeof(double) * scan->numberOfOrderBys);
+ memcpy(GISTSearchItemDistanceValues(item, nOrderBys),
+ so->distanceValues, sizeof(double) * nOrderBys);
+ memcpy(GISTSearchItemDistanceNulls(item, nOrderBys),
+ so->distanceNulls, sizeof(bool) * nOrderBys);
pairingheap_add(so->queue, &item->phNode);
scan->xs_recheck = item->data.heap.recheck;
index_store_float8_orderby_distances(scan, so->orderByTypes,
- item->distances,
+ GISTSearchItemDistanceValues(item, scan->numberOfOrderBys),
+ GISTSearchItemDistanceNulls(item, scan->numberOfOrderBys),
item->data.heap.recheckDistances);
/* in an index-only scan, also return the reconstructed tuple. */
/* visit an index page, extract its items into queue */
CHECK_FOR_INTERRUPTS();
- gistScanPage(scan, item, item->distances, NULL, NULL);
+ gistScanPage(scan, item,
+ GISTSearchItemDistanceValues(item, scan->numberOfOrderBys),
+ GISTSearchItemDistanceNulls(item, scan->numberOfOrderBys),
+ NULL, NULL);
}
pfree(item);
fakeItem.blkno = GIST_ROOT_BLKNO;
memset(&fakeItem.data.parentlsn, 0, sizeof(GistNSN));
- gistScanPage(scan, &fakeItem, NULL, NULL, NULL);
+ gistScanPage(scan, &fakeItem, NULL, NULL, NULL, NULL);
}
if (scan->numberOfOrderBys > 0)
* this page, we fall out of the inner "do" and loop around to
* return them.
*/
- gistScanPage(scan, item, item->distances, NULL, NULL);
+ gistScanPage(scan, item,
+ GISTSearchItemDistanceValues(item, scan->numberOfOrderBys),
+ GISTSearchItemDistanceNulls(item, scan->numberOfOrderBys),
+ NULL, NULL);
pfree(item);
} while (so->nPageData == 0);
fakeItem.blkno = GIST_ROOT_BLKNO;
memset(&fakeItem.data.parentlsn, 0, sizeof(GistNSN));
- gistScanPage(scan, &fakeItem, NULL, tbm, &ntids);
+ gistScanPage(scan, &fakeItem, NULL, NULL, tbm, &ntids);
/*
* While scanning a leaf page, ItemPointers of matching heap tuples will
CHECK_FOR_INTERRUPTS();
- gistScanPage(scan, item, item->distances, tbm, &ntids);
+ gistScanPage(scan, item,
+ GISTSearchItemDistanceValues(item, scan->numberOfOrderBys),
+ GISTSearchItemDistanceNulls(item, scan->numberOfOrderBys),
+ tbm, &ntids);
pfree(item);
}