As far as the optimizer is concerned, these common operations are no different from user-defined operations. The optimization of user-defined operations is defined by means of a rule description language. Each of the specifications either restricts what the pattern of the rule matches or indicates that an operator variable ranges over a set of operator symbols. If necessary, the definitions introduce additional variables that represent the result of expressions in the pattern. Pattern and results are abstract algebraic expressions of the source and target language.
Conditions are Boolean expressions over simple conditions and system predicates.
Gral also provides a choice of three control strategies for rule execution. This strategy requires the definition of transformation rules for the operators. Provided the optimization rules are defined by the user, the process consists of five stages. In normalization, a multistep query is changed into a single-step query by replacing the temporary results of each step with their corresponding query expressions. Stage 3, elimination of constant and common subexpressions, converts the optimized single-step query back to a multistep query.