> [!NOTE] SetOp
> <table>
> <tr>
> <td width="25%"><img src="assets/ex_setop.png" style="width: 100%;"></td>
> <td>The <code>SetOp</code> node executes set-based logic on its children. For <code>INTERSECT</code> and <code>EXCEPT</code>, the engine compares rows from two sorted input streams to find matches or differences. This operator ensures that the result set adheres to the specific mathematical rules of the requested set operation.</td>
> </tr>
> </table>
>
> ```sql
> -- Force the sorted SetOp strategy for an auditable INTERSECT example.
> SET enable_hashagg = off;
> EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE)
> SELECT x FROM generate_series(1, 100) AS a(x)
> INTERSECT
> SELECT x FROM generate_series(50, 150) AS b(x);
> ```
>
> 
>
> ```text
> SetOp Intersect (cost=8.70..9.95 rows=100 width=4) (actual time=1.234..1.252 rows=51.00 loops=1)
> Output: a.x
> -> Sort (cost=4.32..4.57 rows=100 width=4) (actual time=1.047..1.053 rows=100.00 loops=1)
> Output: a.x
> Sort Key: a.x
> Sort Method: quicksort Memory: 25kB
> -> Function Scan on pg_catalog.generate_series a (cost=0.00..1.00 rows=100 width=4) (actual time=0.398..0.402 rows=100.00 loops=1)
> Output: a.x
> Function Call: generate_series(1, 100)
> -> Sort (cost=4.37..4.63 rows=101 width=4) (actual time=0.019..0.021 rows=52.00 loops=1)
> Output: b.x
> Sort Key: b.x
> Sort Method: quicksort Memory: 25kB
> -> Function Scan on pg_catalog.generate_series b (cost=0.00..1.01 rows=101 width=4) (actual time=0.007..0.012 rows=101.00 loops=1)
> Output: b.x
> Function Call: generate_series(50, 150)
> Planning:
> Buffers: shared hit=39
> Planning Time: 10.479 ms
> Execution Time: 2.482 ms
> ```
>
> 
>
> <table>
> <tr>
> <td rowspan="2" width="25%"><img src="assets/ex_setop.svg" style="width: 100%;"></td>
> <td><b>Performance</b></td><td>Requires sorted inputs; performance is proportional to the size of the combined result sets.</td>
> </tr>
> <tr><td><b>Cost</b></td><td><code>set operation cost * number of rows</code></td></tr>
> </table>