Skip to content

Commit 018e7d9

Browse files
committed
Properly check index mark/restore in ExecSupportsMarkRestore.
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
1 parent 57b5d84 commit 018e7d9

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/backend/executor/execAmi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ ExecSupportsMarkRestore(Path *pathnode)
413413
{
414414
case T_IndexScan:
415415
case T_IndexOnlyScan:
416+
/*
417+
* Not all index types support mark/restore.
418+
*/
419+
return castNode(IndexPath, pathnode)->indexinfo->amcanmarkpos;
420+
416421
case T_Material:
417422
case T_Sort:
418423
return true;

src/backend/optimizer/util/plancat.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
275275
info->amcanparallel = amroutine->amcanparallel;
276276
info->amhasgettuple = (amroutine->amgettuple != NULL);
277277
info->amhasgetbitmap = (amroutine->amgetbitmap != NULL);
278+
info->amcanmarkpos = (amroutine->ammarkpos != NULL &&
279+
amroutine->amrestrpos != NULL);
278280
info->amcostestimate = amroutine->amcostestimate;
279281
Assert(info->amcostestimate != NULL);
280282

src/include/nodes/relation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ typedef struct IndexOptInfo
809809
bool amhasgettuple; /* does AM have amgettuple interface? */
810810
bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
811811
bool amcanparallel; /* does AM support parallel scan? */
812+
bool amcanmarkpos; /* does AM support mark/restore? */
812813
/* Rather than include amapi.h here, we declare amcostestimate like this */
813814
void (*amcostestimate) (); /* AM's cost estimator */
814815
} IndexOptInfo;

0 commit comments

Comments
 (0)