建表语句:create table t1(id int primary key, a int, b int, index(a));
分析语句:select id%10 as m, count(*) as c from t1 group by m;
该语句的逻辑:把表 t1 里的数据,按照 id%10 进行分组统计,并按照 m 的结果排序后输出。
explain结果分析
Using index,表示这个语句使用了覆盖索引,选择了索引 a,不需要回表
Using temporary,表示使用了临时表
Using filesort,表示需要排序
具体流程
order by nullUsing temporary 和 Using filesorttmp_table_size参数,来避免用到磁盘临时表SQL_BIG_RESULT这个提示,来告诉优化器直接使用排序算法得到 group by 的结果原文:https://www.cnblogs.com/weiweng/p/12491037.html