March/April 2008
Here is a not-so-uncommon scenario: a query is running slowly. Upon investigation, you determine the reason to be a full-table scan and a possible solution to be an index to help speed up the query. As part of this performance-improvement process, you may have to make several changes in the database, including using indexes and statistics, converting to different index types, changing optimizer compatibility, and modifying an initialization parameter. And although these changes may improve the original query, they bring with them a potential for other unforeseen issues, and you certainly want to understand the impact of the changes on all SQL statements—the actual SQL statements issued by the applications. How? You could pull each and every query from the shared pool and manually check the impact of the changes you are about to make, but this task is probably not feasible in a database of any size.
In Oracle Database 11g, however, there's a new tool—SQL performance analyzer—that enables you to replay all your SQL statements before and after any number of changes and compare the results to see the changes' impact. You can gauge the overall impact as well as that on individual SQL statements.
This article demonstrates how to use SQL performance analyzer to gauge the overall impact of creating an index on the STORE_ID column in a table called TRANS and then refreshing the statistics on the table and the index. Download the script to create the sample data for this article.
SQL performance analyzer operates on the SQL statements captured in a SQL tuning set, which can be easily created via the Oracle Enterprise Manager Database Control. To create a SQL tuning set from the existing SQL statements in the shared pool, follow these steps:
![]() |
Figure 1: SQL tuning set creation |
Now run SQL performance analyzer:
![]() |
Figure 2: Guided workflow tasks |
create index in_trans_store_id on trans (store_id);
![]() |
Figure 3: Comparison report after adding index |
Obviously, creating and using the index helped improve performance, as the overall impact (improvement) of 91 percent suggests, but you wonder if it would help even more to gather statistics again. Well, you don't have to speculate. You can perform another replay after another change.
begin dbms_stats.gather_table_stats ( ownname => 'ACME', tabname => 'TRANS', estimate_percent => 100, method_opt => 'FOR ALL COLUMNS SIZE AUTO', cascade => true); end;
![]() |
Figure 4: SQL performance analyzer task screen |
![]() |
Figure 5: Comparison report after gathering stats |
![]() |
Figure 6: Details of SQL statement causing regression |
Note that in a situation in which only one statement has contributed all of the regression to a replay, you can look at that statement and its execution frequency and perhaps disregard that negative impact. Also, the bottom of the SQL statement screen displays the query plan before (the AFTER_INDEX replay) and after (the AFTER_STATS replay) the change, which will help in making a quick diagnosis.
ConclusionRemember that there are three options on the SQL Performance Analyzer main page, from which I chose Guided Workflow . I chose it because it provides the best control over tasks and will help you learn how to use the tool. For assessing the impact of two common changes—to optimizer versions and initialization parameters—the SQL performance analyzer tasks are even simpler, and you can accomplish them by using the other two options listed on the SQL Performance Analyzer main page—optimizer upgrade simulation and parameter change. For an initialization parameter change such as changing db_file_multiblock_read_count from 16 to 32, you can put the two values on one screen and SQL performance analyzer will execute the replay for both values automatically and compare the output.
With SQL performance analyzer, you can make a change and see its impact on all the SQL statements issued by the users in the database. The report shows you clearly how each statement fared under the change as well as the overall impact and whether the plans were changed. SQL performance analyzer replays the actual SQL statements—not synthetic ones—issued against the database, making the impact analysis as accurate as it can be.
READ more about
Oracle Real Application Testing
SQL Performance Analyzer
DOWNLOAD
Oracle Database Performance Tuning Guide
sample data and code for this article
Oracle Database 11g
DISCLAIMER: We've captured these popular historical magazine articles for your reference. Links etc contained within these article possibly won't work. These articles are provided as-is with no guarantee that the information within them is the best advice for current versions of the Oracle Database.