perf(search): 浏览路径部分复合索引 (0012) #27
Reference in New Issue
Block a user
Delete Branch "devin/1782279211-search-indexes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
可扩展性路线图「阶段0」首个落地项:为最常见的浏览检索路径补部分复合索引(新增迁移 0012,纯附加,不改 API/代码/schema 结构)。
搜索查询恒带
WHERE status='active';无关键词时ORDER BY quality_score DESC, name。此前没有能同时满足"过滤 active + 按该顺序"的索引,深翻页(大 OFFSET)需对全部 active 行做 Seq Scan + Sort。新增:部分索引只覆盖 active 行(体积更小)。规划器在数据量大时改走 索引顺序扫描 + 对 LIMIT 行 nested-loop join brand/category 主键,省掉全表排序——这正是深翻页的瓶颈。
验证:本地起 postgres:16,顺序跑完 0001→0012 全部 up;0012 down/re-up 可逆;
EXPLAIN确认浏览查询命中idx_product_active_quality(排序代价高时走 Index Scan + Nested Loop,小数据量仍按代价回退 seqscan,符合预期)。