> [!NOTE] Redistribute > <table> > <tr> > <td width="25%"><img src="assets/ex_redistribute.png"></td> > <td>A distributed execution node (often in Citus or other distributed extensions) that reshuffles data across the network. Rows are moved between worker nodes so that they can be joined or aggregated locally by their distribution keys.</td> > </tr> > </table> > > > [!NOTE] > > **Distributed Feature**: Redistribute nodes are found in distributed extensions like Citus. They do not appear in standard single-node PostgreSQL plans. > > ```sql > -- Conceptual plan for a large distributed Join > -- (Both tables are reshuffled by the join key) > EXPLAIN SELECT * FROM animals a > JOIN order_items oi ON a.id = oi.animal_id; > ``` > > ```text > Custom Scan (Citus Adaptive) (cost=1.00..1.00 rows=0 width=0) > -> Distributed Subplan 1 > -> Redistribute (Hash) (cost=1.00..348.00 rows=20000 width=27) > -> Seq Scan on animals a (...) > -> Distributed Subplan 2 > -> Redistribute (Hash) (cost=1.00..500.00 rows=50000 width=32) > -> Seq Scan on order_items oi (...) > ``` > > <table> > <tr> > <td rowspan="5" width="25%"><img src="assets/ex_redistribute_motion.svg"></td> > <td><b>Performance</b></td><td>Extremely network and CPU-intensive; often the primary bottleneck in large-scale distributed joins.</td> > </tr> > <tr><td><b>Factors</b></td><td>Amount of data, network bandwidth, number of nodes, and the efficiency of the hashing/shuffling mechanism.</td></tr> > <tr><td><b>Cost</b></td><td><code>network_transfer_cost * data_size + cpu_cost * data_size</code></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/IPC/MessageQueue/MessageQueueSend">IPC: MessageQueueSend</a>, <a href="Workloads/IPC/MessageQueue/MessageQueueReceive">IPC: MessageQueueReceive</a>, <a href="Workloads/LWLock/Parallel/ParallelQueryDSA">LWLock: ParallelQueryDSA</a></td></tr> > <tr><td colspan="3"><b>Description</b>: Redistributes data across nodes based on a specific key. This ensures that related data is colocated on the same node for more efficient join and aggregate operations.</td></tr> > </table>