All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m6s
- 新增 is_standalone 物化列 + 触发器自动维护(迁移 056) - 并行查询拆分:多店铺 IN 查询拆为 per-shop goroutine 并行 Index Scan - 两阶段延迟 Join:深度分页(page≥50)走覆盖索引 Index Only Scan 取 ID 再回表 - COUNT 缓存:per-shop 并行 COUNT + Redis 30 分钟 TTL - 索引优化:删除有害全局索引、新增 partial composite indexes(迁移 057/058) - ICCID 模糊搜索路径隔离:trigram GIN 索引走独立查询路径 - 慢查询阈值从 100ms 调整为 500ms - 新增 30M 测试数据种子脚本和 benchmark 工具
15 lines
736 B
SQL
15 lines
736 B
SQL
-- 优化 tb_iot_card 索引:修复 PG 优化器在 shop_id IN 场景下选错执行计划的问题
|
||
-- 问题:idx_iot_card_global_created_at 导致优化器选择全表扫描+Filter,而不是更高效的 partial 索引
|
||
-- 30M 行场景下 status+carrier_id 过滤查询从 4.5s 降至 <200ms
|
||
|
||
-- 1. 删除全局 created_at 索引(诱导优化器走错计划的元凶)
|
||
DROP INDEX IF EXISTS idx_iot_card_global_created_at;
|
||
|
||
-- 2. 新建 carrier_id 复合 partial 索引(覆盖运营商+排序场景)
|
||
CREATE INDEX IF NOT EXISTS idx_iot_card_standalone_shop_carrier_created
|
||
ON tb_iot_card (shop_id, carrier_id, created_at DESC)
|
||
WHERE deleted_at IS NULL AND is_standalone = true;
|
||
|
||
-- 3. 更新统计信息
|
||
ANALYZE tb_iot_card;
|