feat: 归档旧迁移文件,创建初始化数据迁移和重置脚本
This commit is contained in:
14
migrations/archive/000057_optimize_iot_card_indexes.up.sql
Normal file
14
migrations/archive/000057_optimize_iot_card_indexes.up.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- 优化 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;
|
||||
Reference in New Issue
Block a user