↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Plan Nodes / Scan

Seq Scan

SeqScan

Reads a relation through a sequential scan and applies its scan qualifications.

Reading PostgreSQL 18.6.

Description

Reads a relation through a sequential scan and applies its scan qualifications.

Core node tag
T_SeqScan
Structured EXPLAIN Node Type
Seq Scan
Inputs
A relation
Output
Qualified relation tuples
Executor initializer
ExecInitSeqScan
Memory mechanism
unclassified

EXPLAIN names and attributes

Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.

Text names recorded by this source: Seq Scan.

Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node.

Memory and temporary storage

This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider.

Parallel execution and instrumentation

The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.

Callbacks in this build: ExecSeqScanEstimate, ExecSeqScanInitializeDSM, ExecSeqScanInitializeWorker, ExecSeqScanReInitializeDSM.

Same-version manual discussion

Notice that the EXPLAIN output shows the WHERE clause being applied as a “ filter ” condition attached to the Seq Scan plan node. This means that the plan node checks the condition for each row it scans, and outputs only the ones that pass the condition. The estimate of output rows has been reduced because of the WHERE clause. However, the scan will still have to visit all 10000 rows, so the cost hasn't decreased; in fact it has gone up a bit (by 10000 * cpu_operator_cost , to be exact) to reflect the extra CPU time spent checking the WHERE condition.

Examples from this manual build

Example copied from the PostgreSQL 18.6 manual; it was not executed for this collection.

Here is a trivial example, just to show what the output looks like:

EXPLAIN SELECT * FROM tenk1;

                         QUERY PLAN
-------------------------------------------------------------
 Seq Scan on tenk1  (cost=0.00..445.00 rows=10000 width=244)

Example copied from the PostgreSQL 18.6 manual; it was not executed for this collection.

Now let's modify the query to add a WHERE condition:

EXPLAIN SELECT * FROM tenk1 WHERE unique1 < 7000;

                         QUERY PLAN
------------------------------------------------------------
 Seq Scan on tenk1  (cost=0.00..470.00 rows=7000 width=244)
   Filter: (unique1 < 7000)

Executor implementation notes

nodeSeqscan.c Support routines for sequential scans of relations.

ExecSeqScanEstimate estimates DSM space needed for parallel scan ExecSeqScanInitializeDSM initialize DSM for parallel scan ExecSeqScanReInitializeDSM reinitialize DSM for fresh parallel scan ExecSeqScanInitializeWorker attach to DSM info in parallel worker

We reach here if the scan is not parallel, or if we're serially executing a scan that was planned to be parallel.

SeqRecheck -- access method routine to recheck a tuple in EvalPlanQual

Note that unlike IndexScan, SeqScan never use keys in heap_beginscan (and this is very bad) - so, here we do not check are keys ok or not.

EXPLAIN identity in core source

case T_SeqScan:
			pname = sname = "Seq Scan";
			break;

EXPLAIN labels in this source build

Text-format labelStructured node identity
Seq ScanSeq Scan

Related entries

Documentation and source

Source build
Version
18.6
Build
PostgreSQL 18.6 source archive
Source fingerprint
555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

Compare versions

PostgreSQL 18 → 19: changed.

--- PostgreSQL 18
+++ PostgreSQL 19
@@ -6,7 +6,9 @@
     "ExecSeqScanEstimate",
     "ExecSeqScanInitializeDSM",
     "ExecSeqScanInitializeWorker",
-    "ExecSeqScanReInitializeDSM"
+    "ExecSeqScanInstrumentEstimate",
+    "ExecSeqScanReInitializeDSM",
+    "ExecSeqScanRetrieveInstrumentation"
   ],
   "partial_modes": [],
   "strategies": [],

Compares recorded interfaces and attributes. Source fingerprints and build metadata are excluded; an absent sample is not proof of the introduction or removal release.

Related entries

Export JSON · Back to Plan Nodes · Recorded in PostgreSQL 10 through 20; the first sample is not necessarily its introduction.