Ad Widget

Collapse

Add an index on graphs_items(graphid)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kioob
    Junior Member
    • Jan 2009
    • 2

    #1

    Add an index on graphs_items(graphid)

    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 :
    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 | 
    +----+-------------+-------+-------+----------------+----------------+---------+-----------------+---------+-------------+
    So I add the index on graphs_items :
    Code:
    alter table graphs_items add index ( graphid );
    Query OK, 3790 rows affected (2,18 sec)
    And now the explain return that :
    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 | 
    +----+-------------+-------+------+------------------------+---------+---------+------------------+--------+-------------+
    And the query is now "immediate".

    PS : I use the MySQL version.
  • Kioob
    Junior Member
    • Jan 2009
    • 2

    #2
    If it well understand this topic, the problem is already fixed on latest version, so... sorry for noise

    Comment

    Working...