MySQL optimized sentence

Posted by Ivan on Stack Overflow See other posts from Stack Overflow or by Ivan
Published on 2010-03-23T12:36:21Z Indexed on 2010/03/23 12:43 UTC
Read the original article Hit count: 364

Filed under:
|
|
|

I have a simple table where I have to extract some records. The problem is that the evaluation function is a very time-consuming stored procedure so I shouldn't to call it twice like in this sentence:

SELECT *, slow_sp(row) FROM table WHERE slow_sp(row)>0 ORDER BY dist DESC LIMIT 10

First I thought in optimize like this:

SELECT *, slow_sp(row) AS value FROM table WHERE value>0 ORDER BY dist DESC LIMIT 10

But it doesn't works due "value" is not processed when the WHERE clause is evaluated.

Any idea to optimize this sentence? Thanks.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql