Files
LabelChange-server/add_indexes.sql
2026-06-01 16:30:29 +08:00

42 lines
1.5 KiB
SQL

-- =====================================================
-- 索引优化SQL脚本
-- 执行前请先备份数据库
-- 执行时间:建议在系统低峰期执行
-- =====================================================
SET NAMES utf8mb4;
-- =====================================================
-- label_replace_requests 表索引优化
-- =====================================================
-- 添加 CustomerId 索引
ALTER TABLE `label_replace_requests`
ADD INDEX `idx_customer_id` (`CustomerId` ASC);
-- 添加 FinalMileTrackingNumber 索引
ALTER TABLE `label_replace_requests`
ADD INDEX `idx_final_mile_tracking_number` (`FinalMileTrackingNumber` ASC);
-- 添加组合索引 (CustomerId, CreatedAt)
ALTER TABLE `label_replace_requests`
ADD INDEX `idx_customer_id_created_at` (`CustomerId` ASC, `CreatedAt` DESC);
-- =====================================================
-- label_scan_history 表索引优化
-- =====================================================
-- 添加组合索引 (CustomerId, NeutralWaybillNumber)
ALTER TABLE `label_scan_history`
ADD INDEX `idx_customer_id_neutral_waybill_number` (`CustomerId` ASC, `NeutralWaybillNumber` ASC);
-- =====================================================
-- 验证索引是否添加成功
-- =====================================================
-- 查看 label_replace_requests 表的索引
SHOW INDEX FROM `label_replace_requests`;
-- 查看 label_scan_history 表的索引
SHOW INDEX FROM `label_scan_history`;