P
P
pcdesign2015-11-22 13:01:44
MySQL
pcdesign, 2015-11-22 13:01:44

How to speed up a query with two dates?

Here is a table:
a64b4507b8474fdeb65153c575c4fdf4.png
And here is a slow query:

SELECT * FROM `domain` WHERE `date_expire` < NOW() ORDER BY `last_check` ASC limit 0,10

Result:
Display rows 0 - 9 (10 in total, Query took 3.4408 seconds)
[last_check: 2015-11-20 14:30:03 - 2015-11-20 14:34:35]
3-4 seconds on average.
PS
update

And what's interesting, but the same query with DESC sorting takes 0.0003 sec.
SELECT * FROM `domain` WHERE `date_expire` < NOW() ORDER BY `domain`.`last_check` DESC limit 0 , 10
Display rows 0 - 9 (10 total, Query took 0.0003 sec) [last_check: 2015-11- 22 14:00:04 - 2015-11-22 14:00:03]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Max, 2015-11-22
@pcdesign

recipe

I
IceJOKER, 2015-11-22
@IceJOKER

before the request, enter a word - EXPLAINas a result, you will see which keys were used, etc. generally useful team

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question