Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/backend/executor/execAmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,16 @@ ExecSupportsBackwardScan(Plan *node, List *rtable)
((Scan *) node)->scanrelid <= list_length(rtable));

rte = rt_fetch(((Scan *) node)->scanrelid, rtable);

/*
* Subqueries and other non-table RTEs won't have a relid. They
* are already materialized or validated at this point, so
* assume backward scan is allowed and avoid calling
* TableSupportsBackwardScan with InvalidOid.
*/
if (!OidIsValid(rte->relid))
return true;

return TableSupportsBackwardScan(rte->relid);
}

Expand Down Expand Up @@ -648,7 +658,7 @@ TableSupportsBackwardScan(Oid tableid)
Form_pg_class tabrelrec;
const TableAmRoutine *amroutine;

/* Fetch the pg_class tuple of the index relation */
/* Fetch the pg_class tuple of the table relation */
ht_tabrel = SearchSysCache1(RELOID, ObjectIdGetDatum(tableid));
if (!HeapTupleIsValid(ht_tabrel))
elog(ERROR, "cache lookup failed for relation %u", tableid);
Expand Down