diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-04-04 17:57:07 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-04-04 17:57:07 -0400 |
commit | dfc843d465689d2c2af8b0e01c66c51ccaae2343 (patch) | |
tree | 1c338d4f29044e5693479c9a451ee0d8f77c5412 /src/backend/utils/adt/geo_spgist.c | |
parent | ac9099fc1dd460bffaafec19272159dd7bc86f5b (diff) | |
download | postgresql-dfc843d465689d2c2af8b0e01c66c51ccaae2343.tar.gz postgresql-dfc843d465689d2c2af8b0e01c66c51ccaae2343.zip |
Fix more confusion in SP-GiST.
spg_box_quad_leaf_consistent unconditionally returned the leaf
datum as leafValue, even though in its usage for poly_ops that
value is of completely the wrong type.
In versions before 12, that was harmless because the core code did
nothing with leafValue in non-index-only scans ... but since commit
2a6368343, if we were doing a KNN-style scan, spgNewHeapItem would
unconditionally try to copy the value using the wrong datatype
parameters. Said copying is a waste of time and space if we're not
going to return the data, but it accidentally failed to fail until
I fixed the datatype confusion in ac9099fc1.
Hence, change spgNewHeapItem to not copy the datum unless we're
actually going to return it later. This saves cycles and dodges
the question of whether lossy opclasses are returning the right
type. Also change spg_box_quad_leaf_consistent to not return
data that might be of the wrong type, as insurance against
somebody introducing a similar bug into the core code in future.
It seems like a good idea to back-patch these two changes into
v12 and v13, although I'm afraid to change spgNewHeapItem's
mistaken idea of which datatype to use in those branches.
Per buildfarm results from ac9099fc1.
Discussion: https://postgr.es/m/3728741.1617381471@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/adt/geo_spgist.c')
-rw-r--r-- | src/backend/utils/adt/geo_spgist.c | 9 |
1 files changed, 7 insertions, 2 deletions
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++) |