> [!NOTE] Append > <table> > <tr> > <td width="25%"><img src="assets/ex_append.png"></td> > <td>Concatenates the results of multiple subqueries into a single output stream. It is the core mechanism behind <code>UNION ALL</code> and is also used to scan partitioned tables by appending the results of scanning each individual partition.</td> > </tr> > </table> > > ```sql > -- Combining two targeted lookups with UNION ALL > EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE) > SELECT * FROM animals WHERE id = 1 > UNION ALL > SELECT * FROM animals WHERE id = 2; > ``` > > ![Append Plan Tree](assets/plan_tree_op_append.svg) > > ```text > Append (cost=0.29..16.62 rows=2 width=27) (actual time=0.005..0.008 rows=2 loops=1) > Buffers: shared hit=6 > -> Index Scan using animals_pkey on public.animals (cost=0.29..8.30 rows=1 width=27) (actual time=0.005..0.005 rows=1 loops=1) > Output: animals.id, animals.name, animals.species_id, animals.created_at > Index Cond: (animals.id = 1) > Buffers: shared hit=3 > -> Index Scan using animals_pkey on public.animals animals_1 (cost=0.29..8.30 rows=1 width=27) (actual time=0.003..0.003 rows=1 loops=1) > Output: animals_1.id, animals_1.name, animals_1.species_id, animals_1.created_at > Index Cond: (animals_1.id = 2) > Buffers: shared hit=3 > Planning: > Buffers: shared hit=83 > Planning Time: 0.226 ms > Execution Time: 0.029 ms > ``` > > ![Append measured plan performance signature](assets/trace_op_append.svg) > > <table> > <tr> > <td rowspan="2" width="25%"><img src="assets/ex_append.svg"></td> > <td><b>Performance</b></td><td>High performance; simply iterates through child nodes sequentially.</td> > </tr> > <tr><td><b>Cost</b></td><td><code>Sum of subquery costs.</code></td></tr> > </table>