PL/SQL Packages and Types Reference 10g Release 1 (10.1) Part Number B10802-01 |
|
|
View PDF |
The DBMS_SQLTUNE package provides the interface to tune SQL statements.
The chapter contains the following topics:
SQL Tuning Sets is a new object for capturing SQL workload information. SQL Tuning Sets provide a common infrastructure for dealing with SQL workloads and simplify tuning of a large number of SQL statements.
SQL Tuning Sets store SQL statements along with
SQL Tuning Sets can be created by filtering or ranking SQL statements from several sources:
This defines a cursor type for SQL statements with their related data. This type is mainly used by the LOAD_SQLSET
procedure as an argument to populate a SqlSet from a possible data source. See the LOAD_SQLSET Procedure for more details.
It is important to keep in mind that this cursor is weakly defined.
Under normal mode, the Cost Based Optimizer (CBO) produces the best possible execution plan with whatever information is currently available for the query. It does not have time to gather additional information that might improve the plan because the CBO has to generate an execution plan in a fraction of a second under normal mode. However, in the Plan Tuning Analysis mode, the CBO has time to gather additional information for the query, in the form of a SQL Profile, and this profile allows the generation of a superior execution plan that is well tuned.
In the Plan Tuning Analysis mode, the CBO collects the SQL Profile for the query automatically and the DBA can then decide whether to activate the profile or not. Once activated, the CBO uses the SQL Profile under normal mode to generate the well-tuned plan, that is superior to the original.
Note that SQL Profile is stored persistently in data dictionary, and hence this form of tuning does not require any application code changes.
This procedure accepts a SQL Profile recommended by the SQL Tuning Advisor. The SQL text is normalized for matching purposes though it is stored in the data dictionary in de-normalized form for readability. SQL text is provided through a reference to the SQL Tuning task. If the referenced SQL statement doesn't exist, an error is reported.
DBMS_SQLTUNE.ACCEPT_SQL_PROFILE ( task_name IN VARCHAR2, object_id IN NUMBER := NULL, name IN VARCHAR2 := NULL, description IN VARCHAR2 := NULL, category IN VARCHAR2 := NULL);
The "CREATE
ANY
SQL PROFILE
" privilege is required.
This procedure adds a new reference to an existing SqlSet to indicate its use by a client.
DBMS_SQLTUNE.ADD_SQLSET_REFERENCE ( sqlset_name IN VARCHAR2, description IN VARCHAR2 := NULL) RETURN NUMBER;
Parameter | Description |
---|---|
|
The SqlSet name. |
|
The description of the usage of SqlSet. |
The identifier of the added reference.
This procedure alters specific attributes of an existing SQL Profile object. The following attributes can be altered (using these attribute names):
STATUS
" can be set to "ENABLED
" or "DISABLED
"NAME
" can be reset to a valid name which must be a valid Oracle identifier and must be unique.DESCRIPTION
" can be set to any string of size no more than 500 charactersCATEGORY
" can be reset to a valid category name which must be a valid Oracle identifier and must be unique when combined with normalized SQL text)DBMS_SQLTUNE.ALTER_SQL_PROFILE ( name IN VARCHAR2, attribute_name IN VARCHAR2, value IN VARCHAR2);
Requires the "ALTER
ANY
SQL PROFILE
" privilege.
This procedure cancels the currently executing tuning task. All intermediate result data is deleted.
DBMS_SQLTUNE.CANCEL_TUNING_TASK( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The identifier of the task to execute. |
This procedure creates a SqlSet object in the database.
DBMS_SQLTUNE.CREATE_SQLSET ( sqlset_name IN VARCHAR2, description IN VARCHAR2 := NULL);
Parameter | Description |
---|---|
|
The SqlSet name. |
|
The description of the SqlSet. |
You can use different forms of this function to:
In all cases, the function mainly creates an advisor task and sets its parameters.
DBMS_SQLTUNE.CREATE_TUNING_TASK( sql_text IN CLOB, bind_list IN sql_binds := NULL, user_name IN VARCHAR2 := NULL, scope IN VARCHAR2 := SCOPE_COMPREHENSIVE, time_limit IN NUMBER := TIME_LIMIT_DEFAULT, task_name IN VARCHAR2 := NULL, description IN VARCHAR2 := NULL) RETURN VARCHAR2; DBMS_SQLTUNE.CREATE_TUNING_TASK( sql_id IN VARCHAR2, plan_hash_value IN NUMBER := NULL, scope IN VARCHAR2 := SCOPE_COMPREHENSIVE, time_limit IN NUMBER := TIME_LIMIT_DEFAULT, task_name IN VARCHAR2 := NULL, description IN VARCHAR2 := NULL) RETURN VARCHAR2; DBMS_SQLTUNE.CREATE_TUNING_TASK( begin_snap IN NUMBER, end_snap IN NUMBER, sql_id IN VARCHAR2, plan_hash_value IN NUMBER := NULL, scope IN VARCHAR2 := SCOPE_COMPREHENSIVE, time_limit IN NUMBER := TIME_LIMIT_DEFAULT, task_name IN VARCHAR2 := NULL, description IN VARCHAR2 := NULL) RETURN VARCHAR2; DBMS_SQLTUNE.CREATE_TUNING_TASK( sqlset_name IN VARCHAR2, basic_filter IN VARCHAR2 := NULL, object_filter IN VARCHAR2 := NULL, rank1 IN VARCHAR2 := NULL, rank2 IN VARCHAR2 := NULL, rank3 IN VARCHAR2 := NULL, result_percentage IN NUMBER := NULL, result_limit IN NUMBER := NULL, scope IN VARCHAR2 := SCOPE_COMPREHENSIVE, time_limit IN NUMBER := TIME_LIMIT_DEFAULT, task_name IN VARCHAR2 := NULL, description IN VARCHAR2 := NULL) RETURN VARCHAR2;
A SQL tune task identifier.
This procedure deletes a set of SQL statements from a SqlSet.
DBMS_SQLTUNE.DELETE_SQLSET ( sqlset_name IN VARCHAR2, basic_filter IN VARCHAR2 := NULL);
This procedure drops the named SQL Profile from the database.
DBMS_SQLTUNE.DROP_SQL_PROFILE ( name IN VARCHAR2, ignore IN BOOLEAN := FALSE);
Parameter | Description |
---|---|
|
The (mandatory) name of SQL Profile to be dropped. The name is case sensitive. |
|
Ignores errors due to object not existing. |
Requires the "DROP
ANY
SQL PROFILE
" privilege.
This procedure drops a SqlSet if it is not active.
DBMS_SQLTUNE.DROP_SQLSET ( sqlset_name IN VARCHAR2;
Parameter | Description |
---|---|
|
The SqlSet name. |
You cannot drop a SqlSet when it is referenced by one or more clients (for example, SQL tune advisor).
This procedure drops a SQL tuning task.The task and all its result data are deleted.
DBMS_SQLTUNE.DROP_TUNING_TASK( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The identifier of the current task. |
This procedures executes a previously created tuning task.
DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The identifier of the task to execute. |
This procedure interrupts the currently executing tuning task and access intermediate result data.
DBMS_SQLTUNE.INTERRUPT_TUNING_TASK( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The identifier of the current task. |
This procedure populates the SqlSet with a set of selected SQL.
DBMS_SQLTUNE.LOAD_SQLSET ( sqlset_name IN VARCHAR2, populate_cursor IN SqlSet_cursor);
Parameter | Description |
---|---|
|
The SqlSet name. |
|
The cursor reference from which to populate. |
This procedure returns an error when sqlset_name
is invalid, or a corresponding SqlSet does not exist, or the populate_cursor
is incorrect and cannot be executed.
This procedure deactivates a SqlSet to indicate it is no longer used by the client.
DBMS_SQLTUNE.REMOVE_SQLSET_REFERENCE ( sqlset_name IN VARCHAR2, reference_id IN NUMBER);
Parameter | Description |
---|---|
|
The SqlSet name. |
|
The identifier of the reference to remove. |
This procedure displays the results of a tuning task.
DBMS_SQLTUNE.REPORT_TUNING_TASK( task_name IN VARCHAR2 := NULL, object_id IN NUMBER := NULL, result_limit IN NUMBER := NULL, plan_format IN VARCHAR2 := FORMAT_TYPICAL, rec_format IN VARCHAR2 := FORMAT_TYPICAL) RETURN CLOB;
A text report.
This procedure resets the currently executing tuning task to its initial state. All intermediate result data is deleted.
DBMS_SQLTUNE.RESET_TUNING_TASK( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The identifier of the current task. |
This procedure resumes a previously interrupted tuning task.
DBMS_SQLTUNE.RESUME_TUNING_TASK( task_name IN VARCHAR2);
Parameter | Description |
---|---|
|
The identifier of the current task. |
This function collects SQL statements from the cursor cache.
DBMS_SQLTUNE.SELECT_SQLSET ( sqlset_name IN VARCHAR2, basic_filter IN VARCHAR2 := NULL, object_filter IN VARCHAR2 := NULL, ranking_measure1 IN VARCHAR2 := NULL, ranking_measure2 IN VARCHAR2 := NULL, ranking_measure3 IN VARCHAR2 := NULL, result_percentage IN NUMBER := 1, result_limit IN NUMBER := NULL) RETURN sys.sqlset PIPELINED;
This function returns a sqlset object.
This function collects SQL statements from the workload repository. The overloaded forms let you:
begin_snap
and end_snap
.DBMS_SQLTUNE.SELECT_WORKLAOD_REPOSITORY ( begin_snap IN NUMBER, end_snap IN NUMBER, basic_filter IN VARCHAR2 := NULL, object_filter IN VARCHAR2 := NULL, ranking_measure1 IN VARCHAR2 := NULL, ranking_measure2 IN VARCHAR2 := NULL, ranking_measure3 IN VARCHAR2 := NULL, result_percentage IN NUMBER := 1, result_limit IN NUMBER := NULL) RETURN sys.sqlset PIPELINED; DBMS_SQLTUNE.SELECT_WORKLAOD REPOSITORY ( begin_snap IN NUMBER, end_snap IN NUMBER, basic_filter IN VARCHAR2 := NULL, object_filter IN VARCHAR2 := NULL, ranking_measure1 IN VARCHAR2 := NULL, ranking_measure2 IN VARCHAR2 := NULL, ranking_measure3 IN VARCHAR2 := NULL, result_percentage IN NUMBER := 1, result_limit IN NUMBER := NULL) RETURN sys.sqlset PIPELINED;
This function returns a sqlset object.
There are two forms of this procedure:
MODULE
and ACTION
fields.PRIORITY
and PARSING_SCHEMA_ID
.DBMS_SQLTUNE.UPDATE_SQLSET ( sqlset_name IN VARCHAR2, sql_id IN VARCHAR2, attribute_name IN VARCHAR2, attribute_value IN VARCHAR2 := NULL); DBMS_SQLTUNE.UPDATE_SQLSET ( sqlset_name IN VARCHAR2, sql_id IN VARCHAR2, attribute_name IN VARCHAR2, attribute_value IN NUMBER := NULL);