Skip to content

Commit 59ed45e

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 ded7db4 commit 59ed45e

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/backend/executor/execAmi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ ExecSupportsMarkRestore(Path *pathnode)
388388
{
389389
case T_IndexScan:
390390
case T_IndexOnlyScan:
391+
/*
392+
* Not all index types support mark/restore.
393+
*/
394+
return castNode(IndexPath, pathnode)->indexinfo->amcanmarkpos;
395+
391396
case T_Material:
392397
case T_Sort:
393398
return true;

src/backend/optimizer/util/plancat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
230230
info->amsearchnulls = indexRelation->rd_am->amsearchnulls;
231231
info->amhasgettuple = OidIsValid(indexRelation->rd_am->amgettuple);
232232
info->amhasgetbitmap = OidIsValid(indexRelation->rd_am->amgetbitmap);
233+
info->amcanmarkpos = (info->relam == BTREE_AM_OID);
233234

234235
/*
235236
* Fetch the ordering information for the index, if any.

src/include/nodes/relation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ typedef struct IndexOptInfo
557557
bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
558558
bool amhasgettuple; /* does AM have amgettuple interface? */
559559
bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
560+
bool amcanmarkpos; /* does AM support mark/restore? */
560561
} IndexOptInfo;
561562

562563

0 commit comments

Comments
 (0)