Home > database >  Where, order by, limit 1 mixed use of query is slow
Where, order by, limit 1 mixed use of query is slow

Time:09-29

Today to a situation, the statement
The SELECT event_time AS checkInTime FROM bt_agent_event
WHERE
Agent_id='300300'
AND create_time & gt; '2018-02-23'
AND ` status `=1
AND skill_id IS NOT NULL
The ORDER BY
Event_time
LIMIT 1;
Database data about 10 million or so, with the index, query slowly reached 400 seconds, but if you remove limit 1 or order by or the where, when the query is very fast, is zero seconds,





To solve!

CodePudding user response:

Remove the limit in which index
With this index