pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix confusion in SP-GiST between attribute type and leaf storage
Date: Sun, 04 Apr 2021 18:29:09 +0000
Message-ID: <E1lT7Uj-0004Ku-Hy@gemulon.postgresql.org> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <E1lT7Uj-0004Ku-Hy@gemulon.postgresql.org>
Permalink:  ../E1lT7Uj-0004Ku-Hy@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lT7Uj-0004Ku-Hy@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix confusion in SP-GiST between attribute type and leaf storage
  In-Reply-To: <E1lT7Uj-0004Ku-Hy@gemulon.postgresql.org>
  References: <E1lT7Uj-0004Ku-Hy@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox