using index :使用覆盖索引的时候就会出现
using where:在查找使用索引的情况下,需要回表去查询所需的数据
using index condition:查找使用了索引,但是需要回表查询数据
using index & using where:查找使用了索引,但是需要的数据都在索引列中能找到,所以不需要回表查询数据
查慢查询记录
# Time: 181020 11:53:11
# User@Host: zabbix[zabbix] @ localhost []
# Thread_id: 117743 Schema: zabbix QC_hit: No
# Query_time: 2.857652 Lock_time: 0.000108 Rows_sent: 576 Rows_examined: 1728
SELECT itemid,COUNT(*) AS count,AVG(value) AS avg,MIN(value) AS min,MAX(value) AS max,round(1786* MOD(CAST(clock AS UNSIGNED)+158820,172800)/(172800),0) AS i,MAX(clock) AS clock FROM history_uint WHERE itemid='59886' AND clock>='1539834780' AND clock<='1540007580' GROUP BY itemid,round(1786* MOD(CAST(clock AS UNSIGNED)+158820,172800)/(172800),0);
对zabbix的history_uint表进行优化,优化前结果是
优化后是
MariaDB [zabbix]> explain SELECT itemid,COUNT(*) AS count,AVG(value) AS avg,MIN(value) AS min,MAX(value) AS max,round(1746* MOD(CAST(clock AS UNSIGNED)+67286,86400)/(86400),0) AS i,MAX(clock) AS clock FROM history_uint WHERE itemid='42794' AND clock>='1531199914' AND clock<='1531286314' GROUP BY itemid,round(1746* MOD(CAST(clock AS UNSIGNED)+67286,86400)/(86400),0);
+------+-------------+--------------+-------+----------------+----------------+---------+------+------+--------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+--------------+-------+----------------+----------------+---------+------+------+--------------------------------------------------------+
| 1 | SIMPLE | history_uint | range | history_uint_1 | history_uint_1 | 12 | NULL | 285 | Using index condition; Using temporary; Using filesort |
+------+-------------+--------------+-------+----------------+----------------+---------+------+------+--------------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [zabbix]&g