In order to help the set runtime to optimize queries, the SQL parser should remove objects that are irrelevant from the tree. At this step the parser should also merge together associative expressions. Example: A and (B and C) is same as A and B and C.
The parser should also pre-calculate constant expressions. Pre-calculation can be implemented this way: cascading call for pre-calculation will be send from root of the operation tree to the nodes. Every node will wait for the necessary data (result from a sub-node), and then return calculation result to the parent-node, or null if result can not be pre-evaluated.
At this step, the parser should evaluate operand type’s compatibility, and add necessary conversion rules to the tree. This check-up could be implemented as a cascading call, the same way as pre-calculation.