Files
RuoYi-Vue/sql/dashboard_statistics_indexes.sql

47 lines
1.5 KiB
MySQL
Raw Normal View History

-- 首页统计查询索引(可重复执行)
SET @dashboard_index_sql = (
SELECT IF(
COUNT(1) = 0,
'ALTER TABLE app_virtual_order ADD INDEX idx_virtual_order_create_time (create_time)',
'SELECT 1'
)
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'app_virtual_order'
AND index_name = 'idx_virtual_order_create_time'
);
PREPARE dashboard_index_stmt FROM @dashboard_index_sql;
EXECUTE dashboard_index_stmt;
DEALLOCATE PREPARE dashboard_index_stmt;
SET @dashboard_index_sql = (
SELECT IF(
COUNT(1) = 0,
'ALTER TABLE app_pay_order ADD INDEX idx_pay_order_status_pay_time (status, pay_time)',
'SELECT 1'
)
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'app_pay_order'
AND index_name = 'idx_pay_order_status_pay_time'
);
PREPARE dashboard_index_stmt FROM @dashboard_index_sql;
EXECUTE dashboard_index_stmt;
DEALLOCATE PREPARE dashboard_index_stmt;
SET @dashboard_index_sql = (
SELECT IF(
COUNT(1) = 0,
'ALTER TABLE app_virtual_order ADD INDEX idx_virtual_order_status_pay_time (status, pay_time)',
'SELECT 1'
)
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'app_virtual_order'
AND index_name = 'idx_virtual_order_status_pay_time'
);
PREPARE dashboard_index_stmt FROM @dashboard_index_sql;
EXECUTE dashboard_index_stmt;
DEALLOCATE PREPARE dashboard_index_stmt;