Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ae5aa26

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 888fa2b commit ae5aa26

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
@@ -414,6 +414,11 @@ ExecSupportsMarkRestore(Path *pathnode)
414414
{
415415
case T_IndexScan:
416416
case T_IndexOnlyScan:
417+
/*
418+
* Not all index types support mark/restore.
419+
*/
420+
return castNode(IndexPath, pathnode)->indexinfo->amcanmarkpos;
421+
417422
case T_Material:
418423
case T_Sort:
419424
return true;

src/backend/optimizer/util/plancat.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
273273
info->amhasgettuple = (amroutine->amgettuple != NULL);
274274
info->amhasgetbitmap = amroutine->amgetbitmap != NULL &&
275275
relation->rd_tableam->scan_bitmap_next_block != NULL;
276+
info->amcanmarkpos = (amroutine->ammarkpos != NULL &&
277+
amroutine->amrestrpos != NULL);
276278
info->amcostestimate = amroutine->amcostestimate;
277279
Assert(info->amcostestimate != NULL);
278280

src/include/nodes/pathnodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ struct IndexOptInfo
830830
bool amhasgettuple; /* does AM have amgettuple interface? */
831831
bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
832832
bool amcanparallel; /* does AM support parallel scan? */
833+
bool amcanmarkpos; /* does AM support mark/restore? */
833834
/* Rather than include amapi.h here, we declare amcostestimate like this */
834835
void (*amcostestimate) (); /* AM's cost estimator */
835836
};

0 commit comments

Comments
 (0)