| Using the New Optimizer Statistics |
Oracle determines at compile time whether a query would benefit from dynamic sampling.
Depending on the value of the OPTIMIZER_DYNAMIC_SAMPLING initialization parameter, a certain number of blocks are read by the dynamic sampling query to estimate statistics.
OPTIMIZER_DYNAMIC_SAMPLING takes values from zero (OFF) to 10 (default is 2).
If you use either the GATHER AUTO or STALE settings when you use the DBMS_STATS package, you don抰 need to explicitly enable table monitoring in Oracle Database 10g; the MONITORING and NO MONITORING keywords are deprecated.
Oracle uses the DBA_TAB_MODIFICATIONS view to determine which objects have stale statistics.
Setting the STATISTICS_LEVEL to BASIC turns off the default table monitoring feature.
You can gather fixed object statistics by using the GATHER_DATABASE_STATS procedure and setting the GATHER_FIXED argument to TRUE (the default is FALSE).
You can also use the new procedure:
DBMS_STATS.GATHER_FIXED_OBJECTS_STATS('ALL')
You must have the SYSDBA or ANALYZE ANY DICTIONARY system privilege to analyze any dictionary objects or fixed objects.
To collect statistics for the real dictionary tables:
| Using the SQL Tuning Advisor |
Providing SQL Statements to the SQL Tuning Advisor
How the SQL Tuning Advisor Works
The optimizer will work in the new tuning mode wherein it conducts an in-depth analysis to come up with a set of recommendations, the rationale for them and the expected benefit if you follow the recommendations.
When working in tuning mode, the optimizer is referred to as the Automatic Tuning Optimizer (ATO).
The ATO performs the following tuning tasks:
Statistics Analysis
ATO recommends collecting new statistics for specific objects, if required.
SQL Profiling
The ATO抯 goal at this stage is to verify that its own estimates of factors like column selectivity and cardinality of database objects are valid.
Using a sample of the data, the ATO can check if its own estimates for the statement in question are significantly off the mark.
The ATO may partially execute a SQL statement, so it can check if whether a plan derived purely from inspection of the estimated statistics is actually the best plan.
The ATO may also use any existing history of the SQL statement抯 execution to determine appropriate settings for parameters like OPTIMIZER_MODE.
The output of this phase is a SQL Profile of the concerned SQL statement. If you create that SQL profile, it will be used later by the optimizer when it executes the same SQL statement in the normal mode. A SQL profile is simply a set of auxiliary or supplementary information about a SQL statement.
Access Path Analysis
The ATO analyzes the potential impact of using improved access methods, such as additional or different indexes.
SQL Structure Analysis
The ATO may also make recommendations to modify the structure, both the syntax and semantics, in your SQL statements.
SQL Tuning Advisor Recommendations
The SQL Tuning Advisor can recommend that you do the following:
Using the SQL Tuning Advisor
Using the DBMS_SQLTUNE Package
The DBMS_SQLTUNE package is the main Oracle Database 10g interface to tune SQL statements.
Following are the required steps:
execute :v_task := DBMS_SQLTUNE.CREATE_TUNING_TASK(sql_text=>'select count(*) from hr.employees,hr.dept')
SET LONG 1000
SET LONGCHUNKSIZE 1000
SET LINESIZE 100
SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK( :v_task) FROM DUAL;
Managing SQL Profiles
Use the DBMS_SQLTUNE.ACCEPT_SQL_PROFILE procedure to create a SQL profile based on the recommendations of the ATO.
Managing SQL Tuning Categories
ALTER SYSTEM SET SQLTUNE_CATEGORY = PROD
ALTER SESSION SET SQLTUNE_CATEGORY = DEV
You may also use the DBMS_SQLTUNE.ALTER_SQL_PROFILE procedure to change the SQL tuning category.
Using the Database Control to Run the SQL Tuning Advisor
Under the Performance tab, click the Advisor Central link and then click the SQL Tuning Advisor link.
There are several possible sources for the tuning advisor抯 SQL Tuning Set (STS) input:
| Using the SQL Access Advisor |
The SQL Access Advisor primarily provides advice regarding the creation of indexes, materialized views, and materialized view logs, in order to improve query performance.
Providing Input for the SQL Access Advisor
There are four main sources of input for the advisor: SQL cache, user-defined workload, hypothetical workload, and STS from the AWR.
Modes of Operation
You can operate the SQL Access Advisor in two modes:
Limited (partial)
In this mode, the advisor will concern itself with only problematic or high cost SQL statements ignoring statements with a cost below a certain threshold.
Comprehensive (full)
In this mode, the advisor will perform. a complete and exhaustive analysis of all SQL statements in a representative set of SQL statements, after considering the impact on the entire workload.
You can also use workload filters to specify which kinds of SQL statements the SQL Access Advisor should select for analysis.
Managing the SQL Access Advisor
Using the DBMS_ADVISOR Package
You can also use the QUICK_TUNE procedure to quickly analyze a single SQL statement:
VARIABLE task_name VARCHAR2(255);
VARIABLE sql_stmt VARCHAR2(4000);
sql_stmt := 'SELECT COUNT(*) FROM customers WHERE cust_region=''TX''';
task_name := 'MY_QUICKTUNE_TASK';
DBMS_ADVISOR.QUICK_TUNE(DBMS_ADVISOR.SQLACCESS_ADVISOR, task_name, sql_stmt);
Using the Database Control to Run the SQL Access Advisor
Under the Performance tab, click the Advisor Central link and then click the SQL Access Advisor link.
Note: Oracle creates the new indexes in the schema and tablespaces of the table on which they are created. If a user issues a query that leads to a recommendation to create a materialized view, Oracle creates the materialized view in that user抯 schema and tablespace.
| Performance Pages in the Database Control |
The Database Home Page
Three major tuning areas the OEM Database Control will show you: CPU and wait classes, top SQL statements, and top sessions in the instance.
The Database Performance Page
This page shows the three main items:
Host
The Host part of the page shows two important graphs:
Sessions waiting and working
The sessions graph shows which active sessions are on the CPU and which are waiting for resources like locks, disk I/O, and so on.
Instance throughput
If your instance throughput is decreasing, along with an increasing amount of contention within the database, you should start looking into tuning your database.
| Indexing Enhancements |
Skipping Unusable Indexes
In Oracle Database 10g, the SKIP_UNUSABLE_INDEXES parameter is a dynamic initialization parameter and its default value is TRUE. This setting disables error reporting of indexes and index partitions marked as UNUSABLE.
Note: This setting does not disable error reporting for unusable indexes that are unique because allowing insert and update operations on the table might violate the corresponding constraint.
Note: The database still records an alert message in the alert.log file whenever an index is marked as unusable.
Using Hash-Partitioned Global Indexes
CREATE INDEX sales_hash
on sales_items (sales_id) GLOBAL
PARTITION BY HASH (sales_id) (
partition p1 tablespace tbs_1,
partition p2 tablespace tbs_2,
partition p3 tablespace tbs_3)
CREATE INDEX sales_hash
on sales_items (sales_id) GLOBAL
PARTITION BY HASH (sales_id)
partitions 4
store in (tbs_1,tbs_2,tbs_3,tbs_4)
ALTER INDEX sales_hash ADD PARTITION p4
TABLESPACE tbs_4 [PARALLEL]
Notice the following for the previous command:
ALTER INDEX sales_hash COALESCE PARTITION PARALLEL
Using the New UPDATE INDEXES Clause
Using the new UPDATE INDEXES clause during a partitioned table DDL command will help you do two things:
ALTER TABLE MY_PARTS
MOVE PARTITION my_part1 TABLESPACE new_tbsp
UPDATE INDEXES
(my_parts_idx
(PARTITION my_part1 TABLESPACE my_tbsp))
Bitmap Index Storage Enhancements
Oracle Database 10g provides enhancements for handling DML operations involving bitmap indexes. These improvements eliminate the slowdown of bitmap index performance, which occurs under certain DML situations. Bitmap indexes now perform. better and are less likely to be fragmented when subjected to large volumes of single-row DML operations.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/611609/viewspace-683742/ ,如需转载,请注明出处,否则将追究法律责任。