liufumingren a59793daf2 perf(order): 订单分表补列表排序索引,修复配送列表 2 秒慢查询
原因:生产 wms_order_delivery_1000028_dispatch(59.4 万行 / data 1.13GB)没有任何
索引覆盖列表接口的固定形态

  WHERE warehouse_id = ? [AND dispatch_lane = ?] ORDER BY updated_at DESC, id DESC LIMIT 20

导致主查询全表扫 + filesort(实测 1.9s);与之并行执行的同条件 COUNT(*) 因
dispatch_lane 不在索引中需逐行回表(实测 1.5s),单请求合计约 2 秒。

新增 order_delivery_table_schema.buildListSortIndexes():

- current / history / outsourced:(warehouse_id, updated_at, id) 与 (warehouse_id, delivery_time, id)
  (updated_at 为前端实际排序字段,delivery_time 为 deliveryOrder 模块默认排序字段)
- dispatch:把恒定条件列 dispatch_lane 放进前缀
  (warehouse_id, dispatch_lane, updated_at, id) 与 (warehouse_id, dispatch_lane, delivery_time, id);
  缺少该列时 COUNT(*) 仍会退回回表(实测 1.2s),且 dispatch 分支会剔除从 current
  继承来的同名后缀索引,避免同一张表维护两份功能重叠的索引
- 索引统一追加在索引数组末尾,保持既有索引下标顺序不变

验证(开发库,同一张 59.4 万行同规模表 + 应用日志中的真实 SQL):

- 主查询 1511ms(Using filesort)→ 1.0ms(Backward index scan)
- COUNT(*)  1217ms(Using where 回表)→ 197ms(Using index)

生产建议低峰期先手工建同名索引,避免部署后首个请求在建索引期间阻塞。
2026-09-15 16:03:29 +08:00
..
2026-04-17 19:21:57 +08:00
2026-04-17 19:21:57 +08:00
1
2026-05-16 02:44:53 +08:00