### Redistribute
![[assets/ex_redistribute.png|256]]
### The Explain Trace
> [!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 (...)
```
---
- **Description**: 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.
- **Performance**: Extremely network and CPU-intensive; often the primary bottleneck in large-scale distributed joins.
- **Factors**: Amount of data, network bandwidth, number of nodes, and the efficiency of the hashing/shuffling mechanism.
- **Cost**: `network_transfer_cost * data_size + cpu_cost * data_size`
![[assets/ex_redistribute_motion.svg|256]]
- **Operates on**: [[Structures/Result Set]]
- **Workloads**:
- [[Workloads/IPC/MessageQueue/MessageQueueSend|IPC: MessageQueueSend]]
- [[Workloads/IPC/MessageQueue/MessageQueueReceive|IPC: MessageQueueReceive]]
- [[Workloads/LWLock/Parallel/ParallelQueryDSA|LWLock: ParallelQueryDSA]]