diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c index b8119face43..87420e60dc9 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -63,17 +63,6 @@ SeqNext(SeqScanState *node) direction = estate->es_direction; slot = node->ss.ss_ScanTupleSlot; - if (scandesc == NULL) - { - /* - * We reach here if the scan is not parallel, or if we're serially - * executing a scan that was planned to be parallel. - */ - scandesc = table_beginscan(node->ss.ss_currentRelation, - estate->es_snapshot, - 0, NULL); - node->ss.ss_currentScanDesc = scandesc; - } /* * get the next tuple from the table @@ -258,6 +247,21 @@ ExecInitSeqScan(SeqScan *node, EState *estate, int eflags) scanstate->ss.ps.qual = ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate); + /* + * Build the TableScanDesc unless we're just doing an EXPLAIN without + * ANALYZE. Parallel SeqScan's TableScanDesc is built by + * ExecSeqScanInitializeDSM or ExecSeqScanInitializeWorker. + */ + if ((eflags & EXEC_FLAG_EXPLAIN_ONLY) == 0 && + node->scan.plan.parallel_aware == false) + { + scanstate->ss.ss_currentScanDesc = + table_beginscan(scanstate->ss.ss_currentRelation, + estate->es_snapshot, + 0, + NULL); + } + /* * When EvalPlanQual() is not in use, assign ExecProcNode for this node * based on the presence of qual and projection. Each ExecSeqScan*()