Plan nodes · Scans

Subquery Scan

Reads the output of a subquery that could not be flattened into the outer query.

Most subqueries in FROM are merged into the outer query. When one cannot be (it has a LIMIT, a DISTINCT, a window function…), its plan runs as a unit and this node reads its rows, applying any outer conditions that could not be pushed down.

Example

SELECT * FROM (SELECT * FROM tracks ORDER BY plays DESC LIMIT 10) s WHERE s.genre = 'pop'

4 nodes

Run with EXPLAIN (ANALYZE, BUFFERS, TIMING OFF, SUMMARY OFF) on the sample database, PostgreSQL 19.0. Open it in the EXPLAIN visualizer →

Related

Seq Scan · Index Scan · Index Only Scan · Bitmap Index Scan · Bitmap Heap Scan · BitmapAnd · BitmapOr · Tid Scan · Tid Range Scan · Sample Scan · Function Scan · Table Function Scan · Values Scan · CTE Scan · WorkTable Scan · Named Tuplestore Scan · Foreign Scan · Custom Scan