Description
With lots and lots of ports, we ended up with the query in polling/ports.inc.php taking 7 minutes!
SELECT *, I.`port_id` AS `port_id` FROM `ports` AS I LEFT JOIN `ports-state` AS S O:qN I.`port_id` = S.`port_id` WHERE `device_id` = '866;
136 rows in set (7 min 23.28 sec)
^^^^^^^^^^^^^^^
Using a subselect instead, we got it down to a still-ridiculous 22 seconds.
SELECT *, I.`port_id` AS `port_id` FROM (SELECT * FROM `ports` WHERE `device_id` = 866) AS I LEFT JOIN `ports-state` AS S ON I.`port_id` = S.`port_id`;
136 rows in set (22.24 sec)
^^^^^^^^^