SQL Optimization

[This is preliminary documentation and subject to change.]

The WBEM ODBC adapter does not provide any traditional SQL query optimization. However, it does support decomposition of ODBC Minimum Level SQL queries into WBEM Level 1 queries. The data provider can then specify optimizations on single tables.

For the grammar of WBEM Level 1 queries, see The SQL Grammar. To summarize, a Level 1 query is an ODBC minimum-level query that can only act on a single table. The adapter decomposes an arbitrary ODBC minimum SQL into a number of these queries and sends them to the gateway.

During the SQLPrepare phase, the adapter examines the WHERE predicate tree. If no WHERE predicate tree exists, no optimization is performed. It then attempts to decompose the SQL statement into Level 1 queries. If successful, each Level 1 query is sent to the gateway server via an ExecQuery call. If query decomposition is unsuccessful, the adapter enumerates the whole row of instances as before.

The generation of the Level 1 query is handled by two classes. First, the PredicateParser class generates the WHERE predicate for the desired table. It does this by scanning the parse tree for the current SQL statement. It then converts the WHERE predicate portion of the parse tree into an ASCII text string for the desired table. The next phase is to generate the select list in the WBEM Level 1 query for the columns required for the desired table. This is handled by the TableColumnInfo class, which manages associations between tables and their associated columns. The TableColumnInfo class scans the parse tree for the current SQL statement and extracts any column names for the currently chosen table. It can then generate an ASCII select list text string from these column names.

Another optimization is also performed during the adapter's Parse phase. In the following SQL statement,

SELECT c1t1 FROM t1, t2

t2 is redundant. The adapter attempts to identify these redundancies and remove them from the parse tree.

This optimization is handled by the TableColumnInfo class. The TableColumnInfo class will scans the parse tree for the current SQL statement, and generates associations between tables and columns. It highlights any tables that do not have any associated columns. Once the tables have been identified, they can be removed from the parse tree.