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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix confusion in SP-GiST between attribute type and leaf storage
Date: 2021-04-04 18:29:09
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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.




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(-)


Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2021-04-04 21:57:20 pgsql: Fix more confusion in SP-GiST.
Previous Message Tomas Vondra 2021-04-04 17:37:15 pgsql: Fix bug in brin_minmax_multi_union