MariaDB [zabbix]> show profile for query 1; +--------------------------------+-----------+ | Status | Duration | +--------------------------------+-----------+ | starting | 0.000043 | | Waiting for query cache lock | 0.000012 | | init | 0.000011 | | checking query cache for query | 0.000160 | | checking permissions | 0.000015 | | checking permissions | 0.000010 | | checking permissions | 0.000011 | | checking permissions | 0.000010 | | checking permissions | 0.000010 | | checking permissions | 0.000011 | | checking permissions | 0.000011 | | checking permissions | 0.000013 | | Opening tables | 0.000046 | | After opening tables | 0.000020 | | System lock | 0.000018 | | Table lock | 0.000014 | | After table lock | 0.000011 | | mysql_lock_tables(): unlocking | 0.000011 | | exit mysqld_lock_tables() | 0.000015 | | Waiting for query cache lock | 0.000011 | | exit mysqld_lock_tables() | 0.000060 | | init | 0.000107 | | optimizing | 0.000116 | | statistics | 0.000427 | | preparing | 0.000129 | | optimizing | 0.000036 | | statistics | 0.000133 | | preparing | 0.000079 | | executing | 0.000019 | | Copying to tmp table | 0.000048 | | Copying to tmp table | 0.000215 | | executing | 0.000016 | | Sending data | 23.415251 | | Sorting result | 0.000228 | | Sending data | 0.000290 | | end | 0.000007 | | removing tmp table | 0.000016 | | end | 0.000006 | | removing tmp table | 0.000207 | | end | 0.000010 | | query end | 0.000008 | | closing tables | 0.000024 | | freeing items | 0.000008 | | removing tmp table | 0.001854 | | freeing items | 0.000986 | | removing tmp table | 0.000009 | | freeing items | 0.000012 | | updating status | 0.000013 | | logging slow query | 0.000023 | | cleaning up | 0.000007 | +--------------------------------+-----------+ 50 rows in set (0.00 sec) MariaDB [zabbix]> explain SELECT DISTINCT t.triggerid,t.lastchange FROM triggers t,functions f,items i,hosts_groups hg WHERE hg.hostid=i.hostid AND f.triggerid=t.triggerid AND f.itemid=i.itemid AND hg.groupid='295' AND NOT EXISTS (SELECT NULL FROM functions f,items i,hosts h WHERE t.triggerid=f.triggerid AND f.itemid=i.itemid AND i.hostid=h.hostid AND (i.status<>0 OR h.status<>0)) AND t.status=0 AND EXISTS (SELECT NULL FROM events e WHERE t.triggerid=e.objectid AND e.source=0 AND e.object=0 AND e.value=1 AND e.acknowledged=0) AND t.flags IN ('0','4') AND ((t.value=1) OR ((t.value=0) AND (t.lastchange>1424442236))) ORDER BY t.lastchange DESC; +------+--------------+-------------+--------+-----------------------------------------------------------+----------------+---------+--------------------+---------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+--------------+-------------+--------+-----------------------------------------------------------+----------------+---------+--------------------+---------+---------------------------------+ | 1 | PRIMARY | hg | ref | hosts_groups_1,hosts_groups_2 | hosts_groups_2 | 8 | const | 2059 | Using temporary; Using filesort | | 1 | PRIMARY | i | ref | PRIMARY,items_1 | items_1 | 8 | zabbix.hg.hostid | 39 | Using index | | 1 | PRIMARY | f | ref | functions_1,functions_2 | functions_2 | 8 | zabbix.i.itemid | 1 | Using where | | 1 | PRIMARY | t | eq_ref | PRIMARY,triggers_1,triggers_2 | PRIMARY | 8 | zabbix.f.triggerid | 1 | Using where | | 1 | PRIMARY | | eq_ref | distinct_key | distinct_key | 8 | func | 1 | Distinct | | 3 | MATERIALIZED | e | ref | events_1,events_2 | events_1 | 8 | const,const | 3782356 | Using where; Distinct | | 2 | MATERIALIZED | h | index | PRIMARY,hosts_1,hosts_2,hosts_3,hosts_4,hosts_5,c_hosts_3 | hosts_2 | 4 | NULL | 5597 | Using index | | 2 | MATERIALIZED | i | ref | PRIMARY,items_1,items_3,items_4,items_5,items_6 | items_1 | 8 | zabbix.h.hostid | 39 | Using where | | 2 | MATERIALIZED | f | ref | functions_1,functions_2 | functions_2 | 8 | zabbix.i.itemid | 1 | | +------+--------------+-------------+--------+-----------------------------------------------------------+----------------+---------+--------------------+---------+---------------------------------+ 9 rows in set (0.00 sec)