aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/access/spgist/spgscan.c18
-rw-r--r--src/backend/utils/adt/geo_spgist.c9
2 files changed, 20 insertions, 7 deletions
diff --git a/src/backend/access/spgist/spgscan.c b/src/backend/access/spgist/spgscan.c
index 06011d2c024..24a13d89df8 100644
--- a/src/backend/access/spgist/spgscan.c
+++ b/src/backend/access/spgist/spgscan.c
@@ -463,11 +463,19 @@ spgNewHeapItem(SpGistScanOpaque so, int level, ItemPointer heapPtr,
item->level = level;
item->heapPtr = *heapPtr;
- /* copy value to queue cxt out of tmp cxt */
- /* caution: "leafValue" is of type attType not leafType */
- item->value = isnull ? (Datum) 0 :
- datumCopy(leafValue, so->state.attType.attbyval,
- so->state.attType.attlen);
+
+ /*
+ * If we need the reconstructed value, copy it to queue cxt out of tmp
+ * cxt. Caution: the leaf_consistent method may not have supplied a value
+ * if we didn't ask it to, and mildly-broken methods might supply one of
+ * the wrong type. The correct leafValue type is attType not leafType.
+ */
+ if (so->want_itup)
+ item->value = isnull ? (Datum) 0 :
+ datumCopy(leafValue, so->state.attType.attbyval,
+ so->state.attType.attlen);
+ else
+ item->value = (Datum) 0;
item->traversalValue = NULL;
item->isLeaf = true;
item->recheck = recheck;
diff --git a/src/backend/utils/adt/geo_spgist.c b/src/backend/utils/adt/geo_spgist.c
index d0ff5522cef..6ee75d008c0 100644
--- a/src/backend/utils/adt/geo_spgist.c
+++ b/src/backend/utils/adt/geo_spgist.c
@@ -749,8 +749,13 @@ spg_box_quad_leaf_consistent(PG_FUNCTION_ARGS)
/* All tests are exact. */
out->recheck = false;
- /* leafDatum is what it is... */
- out->leafValue = in->leafDatum;
+ /*
+ * Don't return leafValue unless told to; this is used for both box and
+ * polygon opclasses, and in the latter case the leaf datum is not even of
+ * the right type to return.
+ */
+ if (in->returnData)
+ out->leafValue = leaf;
/* Perform the required comparison(s) */
for (i = 0; i < in->nkeys; i++)