I have a SQL-query like
SELECT somefields
FROM T1
INNER JOIN T2 ON T1.x=T2.x
LEFT JOIN (SELECT somefields FROM T3 WHERE y=123 GROUP BY z)X ON T1.a=X.a
WHERE t1.m=4 AND t1.n>0 AND t1.date1 >CURRENT_TIMESTAMP
ORDER BY t1.date1 DESC
LIMIT 25;
The query takes about 1.5 seconds sometimes, eg when t1.m=4 has many rows, and the result is empty. So far so good. But if I just eliminate the LIMIT 25 the execution time of the same query is about 0.05 seconds.
Can someone explain to me why this is? I would think that LIMIT 25 would at least be as fast as the query without LIMIT 25.