SQL/MX 3.2 Query Guide (H06.25+, J06.14+)
Compiling and Executing a Query
HP NonStop SQL/MX Release 3.2 Query Guide—663851-002
1-2
How the Compiler Works
Modifying the database (metadata) 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/MX 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/MX 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. The normalizer 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. The optimizer 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-21).
TP663851.fm Page 2 Thursday, August 2, 2012 4:47 PM










