liufumingren
18f258014f
perf(backend): 扫码记录列表补覆盖索引,count(*) 不再逐行回表
/api/web/records 是 findAndCountAll,列表本身走 idx_scan_time 只要 0.5ms,
慢的是后面那条 count(id):MySQL 只能选 (subject_id, barcode),索引里没有
scanner_id,于是按主键逐行回表判断 —— 线上 16.5 万条时 Rows_examined ≈ 33 万,
慢查询日志里 3.2s~9.9s(冷缓存时走磁盘)。
补 (subject_id, scanner_id, scan_time) 后 count 变成纯索引扫描(Using index),
实测 0.45s(热)/9.9s(冷) → 0.09s。
- 新增迁移 20261116200000-add-scan-record-list-index.js(幂等,已在生产执行)
- sql/schema.sql 基线同步该索引
- README 补索引用途与实测数字
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>