admin/sql/migrate_kpi_area_info_area_id_index.sql
zzh a9f8373ec3
All checks were successful
Build and Deploy / deploy (push) Successful in 1m1s
fix: 分区明细全量查询去掉 ORDER BY,避免查价 sort_buffer 溢出
大分区表全量 ORDER BY Id 会打满 MySQL sort_buffer;组包仍在内存排序,并补充 (AreaId, Id) 索引脚本。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-07 18:42:41 +08:00

19 lines
555 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 分区明细按 AreaId 全量/分页查询时避免 filesort 打满 sort_buffer(查价 LIVE 路径易踩)
SET @db := DATABASE();
SET @idx := (
SELECT COUNT(1)
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = @db
AND TABLE_NAME = 't_kpi_area_info'
AND INDEX_NAME = 'idx_kpi_info_area_id'
);
SET @sql := IF(
@idx = 0,
'ALTER TABLE `t_kpi_area_info` ADD KEY `idx_kpi_info_area_id` (`AreaId`, `Id`)',
'SELECT ''idx_kpi_info_area_id already exists'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;