pgsql: Fix confusion in SP-GiST between attribute type and leaf storage - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix confusion in SP-GiST between attribute type and leaf storage
Date
Msg-id E1lT7Uj-0004Ku-Hy@gemulon.postgresql.org
Whole thread Raw
Responses Re: pgsql: Fix confusion in SP-GiST between attribute type and leaf storage  (Michael Paquier <michael@paquier.xyz>)
List pgsql-committers
Fix confusion in SP-GiST between attribute type and leaf storage type.

According to the documentation, the attType passed to the opclass
config function (and also relied on by the core code) is the type
of the heap column or expression being indexed.  But what was
actually being passed was the type stored for the index column.
This made no difference for user-defined SP-GiST opclasses,
because we weren't allowing the STORAGE clause of CREATE OPCLASS
to be used, so the two types would be the same.  But it's silly
not to allow that, seeing that the built-in poly_ops opclass
has a different value for opckeytype than opcintype, and that if you
want to do lossy storage then the types must really be different.
(Thus, user-defined opclasses doing lossy storage had to lie about
what type is in the index.)  Hence, remove the restriction, and make
sure that we use the input column type not opckeytype where relevant.

For reasons of backwards compatibility with existing user-defined
opclasses, we can't quite insist that the specified leafType match
the STORAGE clause; instead just add an amvalidate() warning if
they don't match.

Also fix some bugs that would only manifest when trying to return
index entries when attType is different from attLeafType.  It's not
too surprising that these have not been reported, because the only
usual reason for such a difference is to store the leaf value
lossily, rendering index-only scans impossible.

Add a src/test/modules module to exercise cases where attType is
different from attLeafType and yet index-only scan is supported.

Discussion: https://postgr.es/m/3728741.1617381471@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ac9099fc1dd460bffaafec19272159dd7bc86f5b

Modified Files
--------------
doc/src/sgml/ref/create_opclass.sgml               |   2 +-
doc/src/sgml/spgist.sgml                           |  74 +--
src/backend/access/spgist/spgscan.c                |  31 +-
src/backend/access/spgist/spgutils.c               |  84 +++-
src/backend/access/spgist/spgvalidate.c            |  27 +-
src/include/access/spgist_private.h                |   6 +-
src/test/modules/Makefile                          |   1 +
src/test/modules/spgist_name_ops/.gitignore        |   4 +
src/test/modules/spgist_name_ops/Makefile          |  23 +
src/test/modules/spgist_name_ops/README            |   8 +
.../spgist_name_ops/expected/spgist_name_ops.out   |  95 ++++
.../spgist_name_ops/spgist_name_ops--1.0.sql       |  54 +++
src/test/modules/spgist_name_ops/spgist_name_ops.c | 501 +++++++++++++++++++++
.../spgist_name_ops/spgist_name_ops.control        |   4 +
.../spgist_name_ops/sql/spgist_name_ops.sql        |  38 ++
src/test/regress/expected/rangetypes.out           |  19 +
src/test/regress/sql/rangetypes.sql                |  10 +
17 files changed, 937 insertions(+), 44 deletions(-)


pgsql-committers by date:

Previous
From: Tomas Vondra
Date:
Subject: pgsql: Fix bug in brin_minmax_multi_union
Next
From: Tom Lane
Date:
Subject: pgsql: Fix more confusion in SP-GiST.