Try OpenEdge Now
skip to main content
SQL Development
Optimizing Query Performance : Understanding optimization : Optimizer phases : Early evaluation of constant expressions
 
Early evaluation of constant expressions
This is the first phase of optimization (introduced from 11.6). In this phase query tree is iterated over recursively to find the constant expressions. If the expression can be evaluated then values for the constants are peeked and the expression is evaluated. The expression is replaced with the result of the constant expression. This reduces execution time considerably as it eliminates the evaluation of expression for each row during the execution.
The following example shows evaluation of constant expression in peek_evaluate_consts phase. Assuming that the Where condition is as follows:
Select * from sales where (‘yearly’ = ‘yearly’ and sales_date between ’01-01-2001’ and ’10-10-2012’)
OR
(‘yearly’ = ‘Monthly’ and sales_date between ’01-01-2002’ and ’10-10-2012’)
OR
(‘yearly’ = ‘daily’ and sales_date between ’01-01-2009’ and ’10-10-2012’)
After evaluating the constant expressions, the Where condition is transformed as shown below.
Select * from sales where sales_date between ’01-01-2001’ and ’10-10-2012’;
Note: If any of the constant expressions are evaluated for a query, the query plan is marked as not re-usable. Due to the evaluation of constant expressions the query plan has become valid only for a set of constants hence it cannot be re-used for another set of constant values.