SQL/MX 2.x Query Guide (G06.24+, H06.03+)
Compiling and Executing a Query
HP NonStop SQL/MX Query Guide—523728-003
1-2
How the Compiler Works
•
Modifying the database by adding columns to a table, splitting or merging
partitions, and creating and dropping indexes.
For more information, see Improving Query Performance on page 1-6.
How the Compiler Works
To compile a query, the SQL compiler needs information about the tables listed in the
query and the query environment. The necessary table information is listed in the
schema metadata tables from the SQL/MX catalog. The query environment information
can be influenced by the user in the SYSTEM_DEFAULTS Table. For more
information about the SYSTEM_DEFAULTS Table, see the SQL/MX Reference
Manual.
Compilation Steps
The SQL compiler goes through several steps to compile a query. The corresponding
compiler component performs these steps in this way:
Internally, the query is represented as an operator query tree. Each stage adds
information and might modify the input tree. The tree produced in the last step is called
the query execution plan.
Parser Performs syntax checks and translates the SQL/MX query into a
syntactically correct query tree.
Binder Takes the syntactically correct query tree and translates logical
(ANSI) names to physical names and performs many semantic
checks. The binder also expands views that are listed in the query,
looks up metadata for table information, and produces a
semantically correct query tree.
Normalizer Takes the semantically correct query tree and performs certain
unconditional transformations, such as constant folding, subquery
elimination, and recognizes equivalent expressions by representing
equivalent groups of values. These transformations make the query
representation suitable for optimization. The transformations are not
based on cost. Produces the normalized query tree as input to the
optimizer (semantically correct query tree in canonical form).
Optimizer Takes the normalized query tree and generates cost-based, rules-
driven alternative plans to choose the best execution plan for the
query. Computes the cost of each alternative and chooses the
alternative with the lowest cost as the optimal query execution plan.
Codegen Takes the optimal query execution plan and translates it to
executable code for the executor (see How the Executor Processes
the Plan on page 1-14).