]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Properly check index mark/restore in ExecSupportsMarkRestore.
authorAndrew Gierth <rhodiumtoad@postgresql.org>
Tue, 24 Nov 2020 20:58:32 +0000 (20:58 +0000)
committerAndrew Gierth <rhodiumtoad@postgresql.org>
Tue, 24 Nov 2020 21:36:09 +0000 (21:36 +0000)
Previously this code assumed that all IndexScan nodes supported
mark/restore, which is not true since it depends on optional index AM
support functions. This could lead to errors about missing support
functions in rare edge cases of mergejoins with no sort keys, where an
unordered non-btree index scan was placed on the inner path without a
protecting Materialize node. (Normally, the fact that merge join
requires ordered input would avoid this error.)

Backpatch all the way since this bug is ancient.

Per report from Eugen Konkov on irc.

Discussion: https://postgr.es/m/87o8jn50be.fsf@news-spur.riddles.org.uk

src/backend/executor/execAmi.c
src/backend/optimizer/util/plancat.c
src/include/nodes/relation.h

index 93e1e9a691c507b08aa58beddbcb74c66a1a8501..374dd6d8ac93d61e259950011ab4fb8fe6de7aa6 100644 (file)
@@ -388,6 +388,11 @@ ExecSupportsMarkRestore(Path *pathnode)
        {
                case T_IndexScan:
                case T_IndexOnlyScan:
+                       /*
+                        * Not all index types support mark/restore.
+                        */
+                       return castNode(IndexPath, pathnode)->indexinfo->amcanmarkpos;
+
                case T_Material:
                case T_Sort:
                        return true;
index ac57d0f2b89899db210c737b69ea6da4a55e2d13..2299f8af820905d199a16dbc5bb11e52ec30b749 100644 (file)
@@ -230,6 +230,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
                        info->amsearchnulls = indexRelation->rd_am->amsearchnulls;
                        info->amhasgettuple = OidIsValid(indexRelation->rd_am->amgettuple);
                        info->amhasgetbitmap = OidIsValid(indexRelation->rd_am->amgetbitmap);
+                       info->amcanmarkpos = (info->relam == BTREE_AM_OID);
 
                        /*
                         * Fetch the ordering information for the index, if any.
index a35ebe008e6b619771a3a0ffe1a6d530450e858c..9debc364ad9146b6dac5b64db2068ff15253e9af 100644 (file)
@@ -557,6 +557,7 @@ typedef struct IndexOptInfo
        bool            amsearchnulls;  /* can AM search for NULL/NOT NULL entries? */
        bool            amhasgettuple;  /* does AM have amgettuple interface? */
        bool            amhasgetbitmap; /* does AM have amgetbitmap interface? */
+       bool            amcanmarkpos;   /* does AM support mark/restore? */
 } IndexOptInfo;