liveBook · Manning

Parallel sequential scan

As explained in Just Use Postgres!

A parallel sequential scan divides a table scan among a leader process and one or more parallel worker processes.

A parallel sequential scan divides a table or partition into ranges and scans them concurrently. A leader process drives execution while parallel workers scan assigned data and return partial results. section 9.7

Inspecting a time-series query

Running EXPLAIN (ANALYZE, costs off) on an hourly walking-heart-rate query reveals a Parallel Seq Scan because the measurements table has no indexes. Workers scan alongside the leader; Gather Merge combines partial aggregates into the final fourteen-row result. section 9.7

Execution-plan clues include:

  • Workers Planned and Workers Launched show parallel participation. section 9.7
  • loops=2 on the scan indicates the leader and one worker scanned the partition. section 9.7
  • An index-aware spatial predicate can avoid a parallel full-table scan; ST_Distance does not, while ST_DWithin uses the GiST index. section 10.6.2
EXPLAIN (analyze, costs off)
SELECT 
  time_bucket('1 hour', recorded_at) AS period,
  AVG(heart_rate)::int AS avg_rate
FROM watch.heart_rate_measurements
WHERE activity = 'walking' AND watch_id = 1
  AND recorded_at >= '2025-03-15 00:00' 
  AND recorded_at < '2025-03-16 00:00'
GROUP BY period ORDER BY period;

Use the executable EXPLAIN query to inspect the plan for the parallel scan. section 9.7

How Just Use Postgres! covers it

How deep it goes
Explains range distribution, leader-worker roles, plan nodes, and loop counts, but stops short of configuration guidance.
Examples
Demonstrates hourly heart-rate aggregation and a spatial distance query that falls back to a parallel full-table scan.
What it assumes
Assumes SQL querying and basic execution-plan reading while illustrating those ideas through concrete PostgreSQL queries.
What you can do after
Diagnose parallel scan behavior with EXPLAIN by reading worker counts, scan loops, and aggregation nodes.
How it connects
Connects sequential scans with query execution plans, aggregation, indexes, GiST indexes, ST_Distance, and ST_DWithin.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.