MariaDB [zabbix]> describe select distinct i2.key_ from items i join item_discovery id on id.itemid=i.itemid j oin items i2 on id.parent_itemid=i2.itemid join functions f on i.itemid=f.itemid and f.triggerid=13272 where i. flags=2; +------+-------------+-------+--------+-----------------------------------+------------------+---------+------- ---------------------------+------+------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-------+--------+-----------------------------------+------------------+---------+------- ---------------------------+------+------------------------------------+ | 1 | SIMPLE | i | ALL | PRIMARY | NULL | NULL | NULL | 1 | Using where; Using temporary | | 1 | SIMPLE | i2 | ALL | PRIMARY | NULL | NULL | NULL | 1 | Using join buffer (flat, BNL join) | | 1 | SIMPLE | f | ref | functions_1,functions_2 | functions_1 | 8 | const | 1 | Using where; Distinct | | 1 | SIMPLE | id | eq_ref | item_discovery_1,item_discovery_2 | item_discovery_1 | 16 | zabbix .i.itemid,zabbix.i2.itemid | 1 | Using index; Distinct | +------+-------------+-------+--------+-----------------------------------+------------------+---------+------- ---------------------------+------+------------------------------------+ 4 rows in set (0.002 sec) MariaDB [zabbix]> explain select distinct i2.key_ from items i join item_discovery id on id.itemid=i.itemid join items i2 on id.parent_itemid=i2.itemid join functions f on i.itemid=f.itemid and f.triggerid=13272 where i.flags=2; +------+-------------+-------+--------+-----------------------------------+------------------+---------+----------------------------------+------+------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-------+--------+-----------------------------------+------------------+---------+----------------------------------+------+------------------------------------+ | 1 | SIMPLE | i | ALL | PRIMARY | NULL | NULL | NULL | 1 | Using where; Using temporary | | 1 | SIMPLE | i2 | ALL | PRIMARY | NULL | NULL | NULL | 1 | Using join buffer (flat, BNL join) | | 1 | SIMPLE | f | ref | functions_1,functions_2 | functions_1 | 8 | const | 1 | Using where; Distinct | | 1 | SIMPLE | id | eq_ref | item_discovery_1,item_discovery_2 | item_discovery_1 | 16 | zabbix.i.itemid,zabbix.i2.itemid | 1 | Using index; Distinct | +------+-------------+-------+--------+-----------------------------------+------------------+---------+----------------------------------+------+------------------------------------+ 4 rows in set (0.001 sec)