diff --git a/src/backend/executor/execScan.c b/src/backend/executor/execScan.c index a96e826..5c4a4f4 100644 --- a/src/backend/executor/execScan.c +++ b/src/backend/executor/execScan.c @@ -26,6 +26,32 @@ static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, Index varno, TupleDesc tupdesc); +static Index +get_proxy_scanrelid(ScanState *node) +{ + Scan *scan = (Scan *) node->ps.plan; + + Assert(scan->scanrelid == 0); + + switch (nodeTag(scan)) + { + case T_ForeignScan: + { + ForeignScan *fs = (ForeignScan *) scan; + return bms_first_member(fs->fs_relids); + } + + case T_CustomScan: + { + CustomScan *cs = (CustomScan *) scan; + return bms_first_member(cs->custom_relids); + } + + default: + elog(FATAL, "unexpected node type: %d", (int) nodeTag(scan)); + } +} + /* * ExecScanFetch -- fetch next potential tuple * @@ -49,6 +75,8 @@ ExecScanFetch(ScanState *node, */ Index scanrelid = ((Scan *) node->ps.plan)->scanrelid; + if (scanrelid == 0) + scanrelid = get_proxy_scanrelid(node); Assert(scanrelid > 0); if (estate->es_epqTupleSet[scanrelid - 1]) { @@ -347,6 +375,8 @@ ExecScanReScan(ScanState *node) { Index scanrelid = ((Scan *) node->ps.plan)->scanrelid; + if (scanrelid == 0) + scanrelid = get_proxy_scanrelid(node); Assert(scanrelid > 0); estate->es_epqScanDone[scanrelid - 1] = false;