Hello,
maybe it's fixed on the recent versions, but it was not on mine. On my logs I saw this "slow query" :
# Query_time: 6.187004 Lock_time: 0.000033 Rows_sent: 1 Rows_examined: 3307405
SELECT MIN(t.clock) as clock FROM graphs_items gi, trends t WHERE gi.graphid=709 AND t.itemid = gi.itemid;
So, explain return that :
So I add the index on graphs_items :
And now the explain return that :
And the query is now "immediate".
PS : I use the MySQL version.
maybe it's fixed on the recent versions, but it was not on mine. On my logs I saw this "slow query" :
# Query_time: 6.187004 Lock_time: 0.000033 Rows_sent: 1 Rows_examined: 3307405
SELECT MIN(t.clock) as clock FROM graphs_items gi, trends t WHERE gi.graphid=709 AND t.itemid = gi.itemid;
So, explain return that :
Code:
+----+-------------+-------+-------+----------------+----------------+---------+-----------------+---------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+----------------+----------------+---------+-----------------+---------+-------------+ | 1 | SIMPLE | t | index | PRIMARY | PRIMARY | 12 | NULL | 2424217 | Using index | | 1 | SIMPLE | gi | ref | graphs_items_1 | graphs_items_1 | 8 | zabbix.t.itemid | 1 | Using where | +----+-------------+-------+-------+----------------+----------------+---------+-----------------+---------+-------------+
Code:
alter table graphs_items add index ( graphid ); Query OK, 3790 rows affected (2,18 sec)
Code:
+----+-------------+-------+------+------------------------+---------+---------+------------------+--------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+------------------------+---------+---------+------------------+--------+-------------+ | 1 | SIMPLE | gi | ref | graphs_items_1,graphid | graphid | 8 | const | 3 | | | 1 | SIMPLE | t | ref | PRIMARY | PRIMARY | 8 | zabbix.gi.itemid | 132205 | Using index | +----+-------------+-------+------+------------------------+---------+---------+------------------+--------+-------------+
PS : I use the MySQL version.
Comment