Optimize functions in SQL statements

The optimizer by itself cannot evaluate the cost of executing a function in an SQL statement because of the possibility of complex logic, user-defined types, and so on. Because some functions can be expensive to execute, the creator of the function should provide information about the cost and selectivity of the function to help in optimizing the SQL statement.

For example, the following SQL statement includes two functions:
SELECT * FROM T WHERE expensive(t1) and cheap(t2);

If the cheap() function is less expensive to execute than the expensive() function, the optimizer should place the cheap() function first in the execution plan.

The UDRs discussed in the following topics appear in the WHERE or HAVING clause of an SQL statement. These UDRs return a value of TRUE or FALSE.