src/backend/executor/execScan.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/backend/executor/execScan.c b/src/backend/executor/execScan.c index a96e826..89c75ca 100644 --- a/src/backend/executor/execScan.c +++ b/src/backend/executor/execScan.c @@ -49,8 +49,19 @@ ExecScanFetch(ScanState *node, */ Index scanrelid = ((Scan *) node->ps.plan)->scanrelid; - Assert(scanrelid > 0); - if (estate->es_epqTupleSet[scanrelid - 1]) + if (scanrelid == 0) + { + TupleTableSlot *slot = ExecClearTuple(node->ss_ScanTupleSlot); + + /* Only ForeignScan or CustomScan can have scanrelid==0 */ + Assert(IsA(node, ForeignScanState) || + IsA(node, CustomScanState)); + /* Check if it meets the access-method conditions */ + if (!(*recheckMtd) (node, slot)) + ExecClearTuple(slot); /* ensure an empty slot is returned */ + return slot; + } + else if (estate->es_epqTupleSet[scanrelid - 1]) { TupleTableSlot *slot = node->ss_ScanTupleSlot;