hyapp-server/scripts/mysql/052_wallet_entries_asset_user_time_index.sql
2026-07-02 10:53:44 +08:00

13 lines
640 B
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.

USE hyapp_wallet;
-- 金币流水和统计回放按 app/asset/user/time 顺序读取 wallet_entries
-- 这个索引让单资产余额回放和用户金币流水命中同一条有序访问路径,避免全表扫描后排序。
SET @ddl := IF(
(SELECT COUNT(*) FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'wallet_entries' AND INDEX_NAME = 'idx_wallet_entries_asset_user_time') = 0,
'ALTER TABLE wallet_entries ADD INDEX idx_wallet_entries_asset_user_time (app_code, asset_type, user_id, created_at_ms, entry_id)',
'SELECT 1'
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;