【TiDB 使用环境】生产环境
【TiDB 版本】v7.5.6
【遇到的问题:问题现象及影响】
近期升级的新集群版本为v7.5.6,该版本执行一些聚合查询或者大范围统计查询时,更加偏爱走全表扫描。而低版本v4.x、5.x集群,会根据统计信息选择走合适的索引
表结构
CREATE TABLE `merchant_assessment_day_warn_detail` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`index_key` varchar(128) NOT NULL DEFAULT '',
`merchant_id` bigint(20) NOT NULL DEFAULT '0' ,
`cycle_date` int(8) NOT NULL DEFAULT '0' ,
`statistics_date` int(8) NOT NULL DEFAULT '0' ,
`index_code` bigint(20) NOT NULL DEFAULT '0' ,
`overall_score` bigint(20) NOT NULL DEFAULT '0' ,
`avg_indicator` bigint(20) NOT NULL DEFAULT '0' ,
`indicator_detail` varchar(1024) NOT NULL DEFAULT '' ,
`category_indicator_detail` varchar(8192) NOT NULL DEFAULT ' ',
`extend_detail` varchar(1024) NOT NULL DEFAULT '' ,
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`merchant_type` int(4) NOT NULL DEFAULT '0' ,
`data_version` varchar(8) NOT NULL DEFAULT '' ,
PRIMARY KEY (`id`),
KEY `idx_create_time` (`create_time`),
KEY `idx_update_time` (`update_time`),
UNIQUE KEY `uk_merchant_id_statistics_date_cycle_date_index_code` (`merchant_id`,`statistics_date`,`cycle_date`,`index_code`),
KEY `idx_index_key` (`index_key`)
);
执行SQL
select statistics_date,count(1) from merchant_assessment_day_warn_detail where create_time between '2025-08-20 00:00:00' and '2025-09-09 00:00:00' group by statistics_date order by statistics_date;
v4.0.11集群
执行耗时:12秒
执行计划
v7.5.6集群
健康度
执行耗时:2分32.78秒
执行计划








