mirror of
https://github.com/postgres/postgres.git
synced 2025-10-22 14:32:25 +03:00
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
This commit is contained in:
@@ -151,8 +151,8 @@ typedef struct SpGistState
|
||||
typedef struct SpGistSearchItem
|
||||
{
|
||||
pairingheap_node phNode; /* pairing heap node */
|
||||
Datum value; /* value reconstructed from parent or
|
||||
* leafValue if heaptuple */
|
||||
Datum value; /* value reconstructed from parent, or
|
||||
* leafValue if isLeaf */
|
||||
void *traversalValue; /* opclass-specific traverse value */
|
||||
int level; /* level of items on this page */
|
||||
ItemPointerData heapPtr; /* heap info, if heap tuple */
|
||||
@@ -208,7 +208,7 @@ typedef struct SpGistScanOpaqueData
|
||||
|
||||
/* These fields are only used in amgettuple scans: */
|
||||
bool want_itup; /* are we reconstructing tuples? */
|
||||
TupleDesc indexTupDesc; /* if so, tuple descriptor for them */
|
||||
TupleDesc indexTupDesc; /* if so, descriptor for reconstructed tuples */
|
||||
int nPtrs; /* number of TIDs found on current page */
|
||||
int iPtr; /* index for scanning through same */
|
||||
ItemPointerData heapPtrs[MaxIndexTuplesPerPage]; /* TIDs from cur page */
|
||||
|
Reference in New Issue
Block a user