An optimizer/normalizer is used to generate optimized intermediate
language representation of an input query, such as an XML input query. A
method of optimization of an input query in intermediate language form
includes receiving the input query, examining the nodes in a left-depth
first manner to identify code patterns and node types which are subjects
for optimization, tagging the identified code patterns until the
intermediate language representation of the input query has been examined
in its entirety, searching from the top of the intermediate language
representation for tagged code patterns, and adjusting the tagged code
patterns with improved code patterns to form an optimal representation
for an input query. The input to the optimizer/normalizer is assumed to
be an input query transformed into an intermediate language
representation containing code patterns and nodes, each node having a
respective node type.