user38032
user38032

Reputation: 133

Mysql Query is so slow

So I have Mysql like this

SELECT `A`.`ID`, 
IFNULL((SELECT * FROM `B` WHERE `B`.`To` = `A`.`ID`),0)
FROM `A` 
ORDER BY (LOG10(IF(ABS(`X`)>=1,ABS(`X`),1))+(SIGN(`X`)*((`A`.`Date`)-1410530785))/45000) DESC

The B table has about 20k rows.

Why is it so slow, It takes more than 10 seconds.

Upvotes: 0

Views: 44

Answers (1)

jeroen
jeroen

Reputation: 91792

That's quite an ORDER BY clause. Storing that value fixed in an additional, indexed, row will probably solve your problem.

What you are doing now, is calculating that value for every row every time you run that query. And that takes time.

Upvotes: 2

Related Questions