问题:线上平台某功能,查询当日数据列表,表数据量60万,针对时间字段已添加索引,但是查询时长6s,不指定任何where条件查询时长也是6s,说明该条sql全表查询,并未触发索引;
查询指定数据库各表容量分析数据
select
table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',
truncate(data_length/1024/1024, 2) as '数据容量(MB)',
truncate(index_length/1024/1024, 2) as '索引容量(MB)'
from information_schema.tables
where table_schema='jeecg-boot'
order by data_length desc, index_length desc;
查询结果
全表执行结果
使用to_days查询当日数据
EXPLAIN
注:通过Explain进行sql分析type=ALL全表筛选,并未触发corss_time条件索引
优化后SQL
EXPLAIN