The SQL Rewrite function analyzes the input SQL statement and uses an Artificial Intelligence Engine to produce a group of semantically equivalent versions of the statement, known as SQL alternatives. You can then test run these alternatives in the SQL Optimizer window to determine the best-performing version of the SQL.
Tip: After you run SQL Rewrite, run the Generate Indexes function to add alternatives that incorporate virtual indexes. You can then test run the SQL alternatives along with index-set alternatives to measure performance. See Generate Index-Set Alternatives for more information.
The SQL Rewrite process includes these phases:
Retrieves the access plan and the DB2 optimized text that the DB2 LUW optimizer has chosen for the specific SQL alternative. SQL Rewrite classifies the SQL statement according to characteristics that cause performance problems.
Rewrites the original SQL statement to produce a list of semantically equivalent versions, or SQL alternatives.
Allows the users to test run the original and the SQL alternatives to select which SQL version gives the best performance. For each alternative, Batch Run provides the run time for retrieving all records and for retrieving only the first record. You can use this information to identify which alternative is most suitable for your application.
Executes alternatives against the original SQL and displays the returned data for comparison in the SQL Optimizer window.