Auto-sync: 2026-04-28 20:03
This commit is contained in:
40
wiki/concepts/Sort-Key.md
Normal file
40
wiki/concepts/Sort-Key.md
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
title: "Sort Key"
|
||||
type: concept
|
||||
tags:
|
||||
- Data-Engineering
|
||||
- Database
|
||||
- AWS-Redshift
|
||||
- Performance-Optimization
|
||||
last_updated: 2026-04-14
|
||||
---
|
||||
|
||||
## Definition
|
||||
|
||||
Sort Key(排序键)是数据仓库中用于确定数据在存储介质上物理排列顺序的列或列组合。通过预先对数据进行排序,Sort Key 可以显著提升范围查询、过滤和聚合操作的性能。
|
||||
|
||||
## Key Characteristics
|
||||
|
||||
- **物理排序**:数据按 Sort Key 列的值在磁盘上连续存储
|
||||
- **范围查询优化**:对于 `WHERE date BETWEEN ...` 类查询,只需扫描相关数据块
|
||||
- **ZONE MAP**:列式存储系统(如 Redshift)利用 Sort Key 构建 ZONE MAP,快速跳过不包含目标值的数据块
|
||||
- **单一 vs 复合**:
|
||||
- **单一排序键(Compound Sort Key)**:按列顺序联合排序,支持前缀匹配查询
|
||||
- **交错排序键(Interleaved Sort Key)**:各列权重相同,支持更灵活的查询模式,但维护成本更高
|
||||
|
||||
## Use Cases
|
||||
|
||||
- 时间序列数据的日期/时间列排序(典型选择)
|
||||
- 频繁过滤的高基数列
|
||||
- 需要加速 `ORDER BY`、`GROUP BY` 的列
|
||||
|
||||
## Related Concepts
|
||||
|
||||
- [[Distribution-Key]]:数据在集群节点间的分布方式
|
||||
- [[Columnar-Storage]]:列式存储使 Sort Key 优化成为可能
|
||||
- [[MPP]]:Sort Key 优化局部性,提升 MPP 节点内效率
|
||||
- [[Amazon-Redshift]]:Sort Key 是 Redshift 性能优化的核心手段之一
|
||||
|
||||
## Sources
|
||||
|
||||
- [[ctp-topic-68-introduction-to-redshift]]:Sort Key 在 Redshift 架构中的作用
|
||||
Reference in New Issue
Block a user