I have a query of the form:
SELECT akey, avalue, expensiveop(akey) FROM atable WHERE avalue < SOME_CONSTANT;
It appears that expensiveop()--which is a user-defined function that takes a fair amount of time to execute--gets called for all rows in the table. For performance reasons I only want it to execute once for each row in the result set.
I tried the following approach, which did not seem to make a difference:
SELECT akey, avalue, expensiveop(akey) FROM (SELECT * FROM atable WHERE avalue < SOME_CONSTANT)
Any ideas?