2022-02-18

ORDER BY clause slows down query

I have these two tables.

Products:

enter image description here

Assets:

enter image description here

Result with ORDER BY clause return in 44 seconds.

SELECT p.id, i.filepath, p.TotalDownloads 
FROM products p 
INNER JOIN assets i ON i.hash=p.product_id 
WHERE p.Name like '%rar%' AND i.format='ico' 
ORDER by p.TotalDownloads DESC 
LIMIT 0, 10

Showing rows 0 - 9 (10 total, Query took 44.0769 seconds.) [TotalDownloads: 164554096... - 724290...]

AND without ORDER BY clause, results return in 1 second.

SELECT p.id, i.filepath, p.TotalDownloads 
FROM products p 
INNER JOIN assets i ON i.hash=p.product_id 
WHERE p.Name like '%rar%' AND i.format='ico' 
LIMIT 0, 10

Showing rows 0 - 9 (10 total, Query took 1.0668 seconds.)

Indexes: enter image description here enter image description here



from Recent Questions - Stack Overflow https://ift.tt/ohbKCOy
https://ift.tt/FBsij7f

No comments:

Post a Comment