yumi-golang/migrations/057_game_lucky_gift_count_ctime_index.sql
hy001 a1114fbbf5 docs: 存档 game_lucky_gift_count 时间窗口索引迁移
dashboard-cdc-worker 的 24h 窗口查询缺 create_time 可用索引,
每 5 分钟 examined ~18 万行;(sys_origin, create_time) 索引
已于 2026-07-10 在生产在线应用。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 16:12:16 +08:00

21 lines
1.2 KiB
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.

-- dashboard-cdc-worker 每 5 分钟按 create_time 24 小时窗口回读 game_lucky_gift_count1400 万行),
-- 原有索引均以 sys_origin,user_id 开头,无法按时间窗口定位,只能从 user_base_info 反向驱动全量探测
-- (单次 examined ~18 万行,是线上 MySQL CPU 波动来源之一)。
-- 本索引已于 2026-07-10 通过 ALGORITHM=INPLACE, LOCK=NONE 在生产手工应用(耗时 19s此文件用于存档与新环境初始化。
SET @current_schema := DATABASE();
SET @add_game_lucky_gift_count_sorigin_ctime_sql := IF(
NOT EXISTS (
SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
WHERE table_schema = @current_schema
AND table_name = 'game_lucky_gift_count'
AND index_name = 'idx_game_lucky_gift_count_sorigin_ctime'
),
'ALTER TABLE `game_lucky_gift_count` ADD INDEX `idx_game_lucky_gift_count_sorigin_ctime` (`sys_origin`, `create_time`), ALGORITHM=INPLACE, LOCK=NONE',
'SELECT 1'
);
PREPARE add_game_lucky_gift_count_sorigin_ctime_stmt FROM @add_game_lucky_gift_count_sorigin_ctime_sql;
EXECUTE add_game_lucky_gift_count_sorigin_ctime_stmt;
DEALLOCATE PREPARE add_game_lucky_gift_count_sorigin_ctime_stmt;