Properly check index mark/restore in ExecSupportsMarkRestore.
authorAndrew Gierth
Tue, 24 Nov 2020 20:58:32 +0000 (20:58 +0000)
committerAndrew Gierth
Tue, 24 Nov 2020 21:17:02 +0000 (21:17 +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/[email protected]

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

index 1f18e5d3a2f0f14407b50cd2768f5c449c32ab86..4f5fdb0d427ed33de7b42a9e4173a2032907a262 100644 (file)
@@ -414,6 +414,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 40f497660d1e588101e2406c50c903008334e120..bdb2f164295ccc4de8986491c1c7dacfd3f6bce3 100644 (file)
@@ -273,6 +273,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
            info->amhasgettuple = (amroutine->amgettuple != NULL);
            info->amhasgetbitmap = amroutine->amgetbitmap != NULL &&
                relation->rd_tableam->scan_bitmap_next_block != NULL;
+           info->amcanmarkpos = (amroutine->ammarkpos != NULL &&
+                                 amroutine->amrestrpos != NULL);
            info->amcostestimate = amroutine->amcostestimate;
            Assert(info->amcostestimate != NULL);
 
index 441e64eca9a9c3db188541b43786289f683d8902..5de52edda4a6c9e346c21551476ae170d3f067df 100644 (file)
@@ -830,6 +830,7 @@ struct IndexOptInfo
    bool        amhasgettuple;  /* does AM have amgettuple interface? */
    bool        amhasgetbitmap; /* does AM have amgetbitmap interface? */
    bool        amcanparallel;  /* does AM support parallel scan? */
+   bool        amcanmarkpos;   /* does AM support mark/restore? */
    /* Rather than include amapi.h here, we declare amcostestimate like this */
    void        (*amcostestimate) ();   /* AM's cost estimator */
 };