Files
youzan-datahub/sql/performance_indexes.sql

34 lines
1.5 KiB
SQL
Raw Permalink 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.
-- =============================================
-- 性能优化: 补全关键查询索引
-- 执行方式: 在 MySQL 中直接执行IF NOT EXISTS 保证幂等
-- =============================================
-- 1. 订单表: pay_time (大盘总览/趋势图/订货建议 的 WHERE 条件)
-- DDL 中已定义,此处兜底确保存在
CREATE INDEX idx_pay_time ON dwd_trade_order_detail(pay_time);
-- 如果已存在会报错,可忽略。或使用以下方式:
-- ALTER TABLE dwd_trade_order_detail ADD INDEX idx_pay_time(pay_time);
-- 2. 订单表: status (数据截止时间查询 WHERE status = 'TRADE_SUCCESS')
ALTER TABLE dwd_trade_order_detail ADD INDEX idx_status(status);
-- 3. 订单表: etl_update_time (客户聚合增量检测)
ALTER TABLE dwd_trade_order_detail ADD INDEX idx_etl_update_time(etl_update_time);
-- 4. 订单表: outer_item_id (商品洞察/订货建议 GROUP BY)
ALTER TABLE dwd_trade_order_detail ADD INDEX idx_outer_item_id(outer_item_id);
-- 5. 退款表: created_time (大盘总览退款额统计)
ALTER TABLE dwd_trade_refund_detail ADD INDEX idx_created_time(created_time);
-- 6. 退款表: etl_update_time (增量检测)
ALTER TABLE dwd_trade_refund_detail ADD INDEX idx_etl_update_time(etl_update_time);
-- 7. 客户表: etl_update_time (客户聚合增量检测)
ALTER TABLE dim_customer_info ADD INDEX idx_etl_update_time(etl_update_time);
-- 验证索引:
-- SHOW INDEX FROM dwd_trade_order_detail;
-- SHOW INDEX FROM dwd_trade_refund_detail;
-- SHOW INDEX FROM dim_customer_info;