https://dev.mysql.com/doc/refman/8.0/en/internal-temporary-tables.html
实践
tmp_table_size默认16M。tmp_table_size如果过小,存不下了就会存到磁盘上。对于group by会有性能影响。
下面的sql EXPLAIN 如下,出现了Using temporary。表示查询会利用临时表。
(root@localhost) [dbt3]>EXPLAIN select date_format(o_orderDATE,'%Y-%m'),o_clerk,count(1),sum(o_totalprice),avg(o_totalprice) from orders group by date_format(o_orderDATE,'%Y-%m'),o_clerk
k;
+----+-------------+--------+------------+------+---------------+------+---------+------+---------+----------+---------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+--