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.