From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Cc: Pavel Borisov <pashkin.elfe@gmail.com>
Subject: SP-GiST confusion: indexed column's type vs. index column type
Date: Fri, 02 Apr 2021 12:37:51 -0400
Message-ID: <3728741.1617381471@sss.pgh.pa.us> (raw)
While reviewing Pavel Borisov's patch to enable INCLUDE columns in
SP-GiST, I found some things that seem like pre-existing bugs.
These only accidentally fail to cause any problems in the existing
SP-GiST opclasses:
1. The attType passed to an opclass's config method is documented as
Oid attType; /* Data type to be indexed */
Now, I would read that as meaning the type of the underlying heap
column; the documentation and code about when a "compress" method
is required certainly seem to think so too. What is actually being
passed, though, is the data type of the index column, that is the
"opckeytype" of the index opclass. We've failed to notice this because
(1) for most of the core SP-GiST opclasses, the two types are the same,
and (2) none of the core opclasses bother to examine attType anyway.
2. When performing an index-only scan on an SP-GiST index, what we
pass back as the tuple descriptor of the output tuples is just the
index relation's own tupdesc, cf spgbeginscan:
/* Set up indexTupDesc and xs_hitupdesc in case it's an index-only scan */
so->indexTupDesc = scan->xs_hitupdesc = RelationGetDescr(rel);
Again, what this is going to report is the opckeytype, not the
reconstructed heap column datatype. That's just flat out wrong.
We've failed to notice because the only core opclass for which
those types are different is poly_ops, which does not support
reconstructing the polygons for index-only scan.
We need to do something about this because the INCLUDE patch needs
the relation descriptor of an SP-GiST index to match the reality
of what is stored in the leaf tuples. Right now, as far as I can tell,
there isn't really any necessary connection between the atttype
claimed by the relation descriptor and the leaf type that's physically
stored. They're accidentally the same in all existing opclasses,
but only accidentally.
I propose changing things so that
(A) attType really is the input (heap) data type.
(B) We enforce that leafType agrees with the opclass opckeytype,
ensuring the index tupdesc can be used for leaf tuples.
(C) The tupdesc passed back for an index-only scan reports the
input (heap) data type.
This might be too much change for the back branches. Given the
lack of complaints to date, I think we can just fix it in HEAD.
regards, tom lane
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-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, pashkin.elfe@gmail.com
Subject: Re: SP-GiST confusion: indexed column's type vs. index column type
In-Reply-To: <3728741.1617381471@sss.pgh.pa.us>
References: <3728741.1617381471@sss.pgh.pa.us>
* 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