先为访问模式(access pattern)设计,再选择 partition + 合适的 index/PK,使任何单次查询只触及一个小而有界的切片——绝不扫描 100 亿行。在 100 亿条记录上做到亚 100 毫秒,靠的不是更快的磁盘;而是把工作集(working set)变得极小。
Query ─▶ Router ──▶ Partition (by tenant/time) ──▶ Index/PK lookup ─▶ ~thousands of rows
│ (prune 99.9% of data) (B-tree / sort key)
└─▶ Cache (Redis) ─▶ hit? return in <5ms
miss ▼
Columnar store (ClickHouse) for aggregates / scans
访问模式主导一切
在选择技术前,先问:"获取用户 X 最近 20 个订单"是点查/范围查询——你希望 partition 和 sort key 恰好与之匹配。"按地区汇总本月营收"是分析型扫描——行式存储是错误的工具。先对查询建模,才是区分"可行的设计"与"看似合理却全表扫描的设计"的关键。
