I am getting an entry in my slow query log (see code) which is being called from a nodejs application. However if I enter the same query at the mysql command line it is not slow at all and uses indexes.
Any ideas why this should occur and how I can make sure that my nodejs application does not generate slow queries?
The application is on another server but in the same location so the query is going via the network and not directly on the same server. However I don't think that should affect the query speed.. Unless the slow log is also taking into account transfer time. Does anyone know if this is the case?
Slow Log
# Time: 190726 9:49:02
# User@Host: root[root] @ elaine_master [192.168.202.146]
# Thread_id: 18 Schema: cfc QC_hit: No
# Query_time: 1.552237 Lock_time: 0.000030 Rows_sent: 874 Rows_examined: 1694
SET timestamp=1564134542;
select * from applications where status !='deleted'
and shotgun_status = ''
and assignedto > 0
and lo_assistant = 0;
Command line
-------------------------+
874 rows in set (0.05 sec)
Explain
MariaDB [cfc]> explain select * from applications where status !='deleted' and shotgun_status = '' and assignedto > 0 and lo_assistant = 0;
+------+-------------+--------------+------+------------------------------------------------------------------------------------------------------------------+-------------------------------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+--------------+------+------------------------------------------------------------------------------------------------------------------+-------------------------------+---------+-------+------+-------------+
| 1 | SIMPLE | applications | ref | applications_idx_status,applications_idx_shotgunstatus,applications_idx_assignedto,applications_idx_lo_assistant | applications_idx_lo_assistant | 4 | const | 1693 | Using where |
+------+-------------+--------------+------+------------------------------------------------------------------------------------------------------------------+-------------------------------+---------+-------+------+-------------+
1 row in set (0.00 sec)
Indexes
PRIMARY KEY (`id`),
KEY `applications_idx_status` (`status`),
KEY `applications_idx_leaders` (`leaders`),
KEY `applications_idx_shotgunstatus` (`shotgun_status`),
KEY `applications_idx_assignedto` (`assignedto`),
KEY `applications_idx_lo_assistant` (`lo_assistant`)
) ENGINE=InnoDB AUTO_INCREMENT=2038 DEFAULT CHARSET=latin1 |