> [!NOTE] Subquery Scan > <table> > <tr> > <td width="25%"><img src="assets/ex_subqueryscan.png"></td> > <td>A wrapper node used when the planner needs to treat a subquery as a standalone relation. It passes the results of the subquery up the execution tree, often used to bridge different scopes of visibility or filtering.</td> > </tr> > </table> > > ```sql > -- Conceptual plan for a non-inlinable subquery > EXPLAIN SELECT * FROM ( > SELECT id FROM animals > OFFSET 0 -- Prevents pull-up in some versions/cases > ) s; > ``` > > ```text > Subquery Scan on s (cost=1.00..548.00 rows=20000 width=4) > -> Seq Scan on animals (cost=1.00..348.00 rows=20000 width=4) > ``` > > <table> > <tr> > <td rowspan="5" width="25%"><img src="assets/ex_subplan.svg"></td> > <td><b>Performance</b></td><td>High performance; essentially a pass-through node for subqueries that the optimizer cannot flatten into the outer query.</td> > </tr> > <tr><td><b>Factors</b></td><td>Subquery complexity and the total number of rows processed.</td></tr> > <tr><td><b>Cost</b></td><td>Equivalent to the cost of the child subquery plan.</td></tr> > <tr><td><b>Operates on</b></td><td><a href="Structures/Result Set">Result Set</a></td></tr> > <tr><td><b>Workloads</b></td><td><a href="Workloads/LWLock/Buffers/BufferContent">LWLock: BufferContent</a></td></tr> > <tr><td colspan="3"><b>Description</b>: Scans the result of a subquery.</td></tr> > </table>