Beruflich Dokumente
Kultur Dokumente
execution plans for SQL statements and this repository can be used to
display details about the frequency of usage for table and indexes. This
article will expore these AWR tables and expose their secrets.
We have the following AWR tables for SQL tuning (Figure 1).
o dba_hist_sqlstat
o dba_hist_sql_summary
o dba_hist_sql_workarea
o dba_hist_sql_plan
o dba_hist_sql_workarea_histogram
dba_hist_sqlstat
This view is very similar to the v$sql view but it contains important
SQL metrics for each snapshot. These include important delta (change)
information on disk reads and buffer gets, as well as time-series delta
information on application, I/O and concurrency wait times.
1
col c5 heading 'Disk|Reads|Delta' format 9,999
col c6 heading 'IO Wait|Delta' format 9,999
col c7 heading 'Application|Wait|Delta' format 9,999
col c8 heading 'Concurrency|Wait|Delta' format 9,999
break on c1 skip 2
break on c2 skip 2
select begin_interval_time c1, sql_id c2, executions_delta c3,
buffer_gets_delta c4, disk_reads_delta c5, iowait_delta c6,
apwait_delta c7, ccwait_delta c8 from dba_hist_sqlstat natural join
dba_hist_snapshot order by c1, c2;
dba_hist_sql_plan
The query below will show the main predicates involved for each object
component in a SQL execution plan:
2
But there is lots more information in dba_hist_sql_plan that is useful.
The query below will extract importing costing information for all
objects involved in each query.
Now that we see the important table structures lets examine how we can
get spectacular reports from this AWR data.
One of the problems in Oracle9i was the single bit-flag that was used to
monitor index usage. You could set the flag with the "alter index xxx
monitoring usage" command, and see if the index was accessed by querying
the v$object_usage view.
The goal of any index access is to use the most selective index for a
query, the one that produces the smallest number of rows. The Oracle
data dictionary is usually quite good at this, but it is up to you to
define the index. Missing function-based indexes are a common source of
sub-optimal SQL execution because Oracle will not use an indexed column
unless the WHERE clause matches the index column exactly.
3
col c7 heading 'Rows|Processed' format 999,999
break on c1 skip 2
break on c2 skip 2
select begin_interval_time c1, sql_id c2, object_name c3,
search_columns c4, cardinality c5, disk_reads_delta c6,
rows_processed_delta c7 from dba_hist_sql_plan natural join
dba_hist_snapshot natural join dba_hist_sqlstat;
You can also use the dba_hist_sql_plan table to gather counts about the
frequency of participation of objects inside queries.
Here we can see the average SQL invocations for every database object,
averaged by hour-of-the day or day-of-the-week. Understanding the SQL
signature can be extremely useful for determining what objects to place
in your KEEP pool, and to determining the most active tables and indexes
in your database.
4
break on c1 skip 2
select begin_interval_time c1, object_name c2, search_columns c3,
disk_reads_delta c4, rows_processed_delta c5, access_predicates c6,
filter_predicates c7 from dba_hist_sql_plan natural join
dba_hist_snapshot natural join dba_hist_sqlstat;
In Oracle10g we can easily see what indexes are used, when they are used
and the context where they are used. Here is a simple AWR query to plot
index usage:
index_usage_hr.sql
This will produce an output like this, showing a summary count of all
indexes used during the snapshot interval.
Conclusion
5
6