aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/spgist/spgutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-11-20 14:29:56 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2021-11-20 14:29:56 -0500
commitf4e7ae2b8a67ad6801726553a024a3306716ef80 (patch)
tree2dc5d198847cc8026ede38d3af8d4e34c69a4636 /src/backend/access/spgist/spgutils.c
parent46d665bc26ce57b5afecbc218c8fc3c6848211d8 (diff)
downloadpostgresql-f4e7ae2b8a67ad6801726553a024a3306716ef80.tar.gz
postgresql-f4e7ae2b8a67ad6801726553a024a3306716ef80.zip
Fix SP-GiST scan initialization logic for binary-compatible cases.
Commit ac9099fc1 rearranged the logic in spgGetCache() that determines the index's attType (nominal input data type) and leafType (actual type stored in leaf index tuples). Turns out this broke things for the case where (a) the actual input data type is different from the nominal type, (b) the opclass's config function leaves leafType defaulted, and (c) the opclass has no "compress" function. (b) caused us to assign the actual input data type as leafType, and then since that's not attType, we complained that a "compress" function is required. For non-polymorphic opclasses, condition (a) arises in binary-compatible cases, such as using SP-GiST text_ops for a varchar column, or using any opclass on a domain over its nominal input type. To fix, use attType for leafType when the index's declared column type is different from but binary-compatible with attType. Do this only in the defaulted-leafType case, to avoid overriding any explicit selection made by the opclass. Per bug #17294 from Ilya Anfimov. Back-patch to v14. Discussion: https://postgr.es/m/17294-8f6c7962ce877edc@postgresql.org
Diffstat (limited to 'src/backend/access/spgist/spgutils.c')
-rw-r--r--src/backend/access/spgist/spgutils.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/backend/access/spgist/spgutils.c b/src/backend/access/spgist/spgutils.c
index 03a9cd36e63..3235d215e1a 100644
--- a/src/backend/access/spgist/spgutils.c
+++ b/src/backend/access/spgist/spgutils.c
@@ -25,6 +25,7 @@
#include "catalog/pg_amop.h"
#include "commands/vacuum.h"
#include "nodes/nodeFuncs.h"
+#include "parser/parse_coerce.h"
#include "storage/bufmgr.h"
#include "storage/indexfsm.h"
#include "storage/lmgr.h"
@@ -218,9 +219,20 @@ spgGetCache(Relation index)
* correctly, so believe leafType if it's given.)
*/
if (!OidIsValid(cache->config.leafType))
+ {
cache->config.leafType =
TupleDescAttr(RelationGetDescr(index), spgKeyColumn)->atttypid;
+ /*
+ * If index column type is binary-coercible to atttype (for
+ * example, it's a domain over atttype), treat it as plain atttype
+ * to avoid thinking we need to compress.
+ */
+ if (cache->config.leafType != atttype &&
+ IsBinaryCoercible(cache->config.leafType, atttype))
+ cache->config.leafType = atttype;
+ }
+
/* Get the information we need about each relevant datatype */
fillTypeDesc(&cache->attType, atttype);