Files
nexus/wiki/concepts/Distribution-Key.md
2026-04-28 20:03:11 +08:00

52 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Distribution Key"
type: concept
tags:
- Data-Engineering
- Database
- AWS-Redshift
- Performance-Optimization
last_updated: 2026-04-14
---
## Definition
Distribution Key分布键Dist Key决定数据在分布式数据仓库集群各计算节点间的分布方式。合理的分布键选择是避免数据倾斜Data Skew和最小化跨节点数据传输Data Shuffling的关键。
## Distribution Strategies
### 1. KEY Distribution关键分布
- 按特定列的哈希值分布数据
- 同一键值的数据会落在同一节点
- 适用场景事实表与维度表基于外键的关联Colocation Join
### 2. ALL Distribution全分布
- 将小表完整复制到所有节点
- 消除跨节点传输,但增加存储成本
- 适用场景:小维度表(< 10MB
### 3. EVEN Distribution均匀分布
- 轮询方式均匀分布数据
- 默认策略,适用于无明显热点的情况
- 适用场景:无法确定最佳分布键时的兜底策略
## Key Trade-offs
| 维度 | KEY | ALL | EVEN |
|------|-----|-----|------|
| 存储成本 | 低 | 高 | 低 |
| Join 性能 | 高co-located | 高 | 低(可能 shuffle |
| 数据倾斜风险 | 中(取决于键值分布) | 无 | 无 |
| 适用表规模 | 大表 | 小表 | 通用 |
## Related Concepts
- [[Sort-Key]]:节点内数据排序,与 Distribution Key 共同构成 Redshift 性能优化双核心
- [[Data-Skew]]:分布键选择不当导致的数据倾斜问题
- [[MPP]]:分布键决定数据局部性,影响 MPP 并行效率
- [[Amazon-Redshift]]Distribution Key 是 Redshift 架构的核心概念
## Sources
- [[ctp-topic-68-introduction-to-redshift]]Distribution Key 在 Redshift 集群数据分布中的作用