Table of Contents
This chapter briefly introduces the DBMS_SPH package, and describes how to use the procedures of the package.
DBMS_SPH provides functions required for using SQL Plan History (hereafter SPH). SPH saves and manages history of SQL statements executed on a server.
Tibero manages SQL execution plans. An execution plan can be queried from a dynamic view such as V$SQL_PLAN. Since an execution plan is removed from the memory when it is not used for a long time or the server reboots, it is difficult to detect and trace execution plan changes over a long period of time.
SPH helps users to easily manage execution plan changes over time by saving execution plans in separate tables. However, this package can be used only by SYS users.
This section describes the procedures provided by the DBMS_SPH package, in alphabetical order.
Outputs the change history of the specified SQL execution plans. This procedure provides the same function as the REPORT_PLANS_BY_DATE procedure, but has a different parameter type. The result is displayed on the screen or saved in a file.
The result is saved in the following file when the TO_FILE parameter is set to TRUE.
$TB_HOME/instance/$TB_SID/sph_report.{mthr_pid}.{current_time}
Details about the REPORT_PLANS procedure are as follows:
Prototype
PROCEDURE REPORT_PLANS ( SQL_HASH_VALUE IN NUMBER, DURATION IN PLS_INTEGER DEFAULT 24*365*1000, TO_FILE IN BOOLEAN DEFAULT TRUE );
Parameter
Parameter | Description |
---|---|
SQL_HASH_VALUE | SQL hash value to output. |
DURATION | Time period for which SQL history will be displayed. This value is used to calculate the start time. The end time is always the current time.
|
TO_FILE | Option to save the result in a file.
|
Exception
Exception | Description |
---|---|
PARAMETER_OUT_OF_RANGE | Occurs when the parameter value is out of the specified range. |
Example
SQL> set serveroutput on
SQL> select hash_value from v$sqlarea where sql_text like 'select hash_value%';
HASH_VALUE
----------
3870695416
1 row selected.
SQL> exec dbms_sph.report_plans(3870695416, 24, FALSE);
-- Display all execution plans of the day on screen.
+-------------------------+
| SQL_PLAN_HISTORY REPORT |
+-------------------------+
FROM: 1997/05/29 17:29:41
TO: 1997/05/30 17:29:41
... Omitted ...
Outputs the change history of the specified SQL execution plans. This procedure provides the same function as the REPORT_PLANS procedure, but has a different parameter type. The result is displayed on the screen or saved in a file.
The result is saved in the following file when the TO_FILE parameter is set to TRUE.
$TB_HOME/instance/$TB_SID/sph_report.{mthr_pid}.{current_time}
Details about the REPORT_PLANS_BY_DATE procedure are as follows:
Prototype
PROCEDURE REPORT_PLANS_BY_DATE ( SQL_HASH_VALUE IN NUMBER, START_DATE IN DATE DEFAULT SYSDATE - 365*1000, TO_FILE IN BOOLEAN DEFAULT TRUE );
Parameter
Parameter | Description |
---|---|
SQL_HASH_VALUE | SQL hash value to output. |
START_DATE | Start time of the time period for which SQL history will be displayed. The end time is always the current time.
|
TO_FILE | Option to save the result in a file.
|
Exception
Exception | Description |
---|---|
PARAMETER_OUT_OF_RANGE | Occurs when the parameter value is out of the specified range. |
Example
SQL> set serveroutput on
SQL> select hash_value from v$sqlarea where sql_text like 'select hash_value%';
HASH_VALUE
----------
3870695416
1 row selected.
SQL> exec dbms_sph.report_plans_by_date(3870695416, sysdate - 1, FALSE);
-- Display all execution plans of the day on screen.
+-------------------------+
| SQL_PLAN_HISTORY REPORT |
+-------------------------+
FROM: 1997/05/29 17:49:11
TO: 1997/05/30 17:49:11
... Omitted ...
Outputs the change history of all SQL execution plans that meet the specified condition. This procedure provides the same function as the REPORT_PLAN_HISTORY_BY_DATE procedure, but has a different parameter type. The result is displayed on the screen or saved in a file.
The result is saved in the following file when the TO_FILE parameter is set to TRUE.
$TB_HOME/instance/$TB_SID/sph_report.{mthr_pid}.{current_time}
Details about the REPORT_PLAN_HISTORY procedure are as follows:
Prototype
PROCEDURE REPORT_PLAN_HISTORY ( DURATION IN PLS_INTEGER DEFAULT 24*365*1000, MIN_PLAN_COUNT IN PLS_INTEGER DEFAULT 1, TO_FILE IN BOOLEAN DEFAULT TRUE );
Parameter
Parameter | Description |
---|---|
DURATION | Time period for which SQL history will be displayed. This value is used to calculate the start time. The end time is always the current time.
|
MIN_PLAN_COUNT | Minimum number of execution plans that a SQL to output can have. For example, if the value is 2, only SQL statements with 2 or more execution plans are saved or displayed.
|
TO_FILE | Option to save the result in a file.
|
Exception
Exception | Description |
---|---|
PARAMETER_OUT_OF_RANGE | Occurs when the parameter value is out of the specified range. |
Example
SQL> set serveroutput on
SQL> exec dbms_sph.report_plan_history(24, 1, FALSE);
-- Display all execution plans of SQL
statements executed during the day on screen.
+-------------------------+
| SQL_PLAN_HISTORY REPORT |
+-------------------------+
FROM: 1997/05/29 17:49:11
TO: 1997/05/30 17:49:11
... Omitted ...
Outputs the change history of all SQL execution plans that meet the specified condition. This procedure provides the same function as the REPORT_PLAN_HISTORY procedure, but has a different parameter type. The result is displayed on the screen or saved in a file.
The result is saved in the following file when the TO_FILE parameter is set to TRUE.
$TB_HOME/instance/$TB_SID/sph_report.{mthr_pid}.{current_time}
Details about the REPORT_PLAN_HISTORY_BY_DATE procedure are as follows:
Prototype
PROCEDURE REPORT_PLAN_HISTORY_BY_DATE ( START_DATE IN DATE DEFAULT SYSDATE - 365*1000, MIN_PLAN_COUNT IN PLS_INTEGER DEFAULT 1, TO_FILE IN BOOLEAN DEFAULT TRUE );
Parameter
Parameter | Description |
---|---|
START_DATE | Start time of the time period for which SQL history will be displayed. The end time is always the current time.
|
MIN_PLAN_COUNT | Minimum number of execution plans that a SQL to output can have. For example, if the value is 2, only SQL statements with 2 or more execution plans are saved or displayed.
|
TO_FILE | Option to save the result in a file.
|
Exception
Exception | Description |
---|---|
PARAMETER_OUT_OF_RANGE | Occurs when the parameter value is out of the specified range. |
Example
SQL> set serveroutput on
SQL> exec dbms_sph.report_plan_history_by_date(sysdate - 1, 1, FALSE);
-- Display all execution plans of SQL
statements executed during the day on screen.
+-------------------------+
| SQL_PLAN_HISTORY REPORT |
+-------------------------+
FROM: 1997/05/29 17:49:11
TO: 1997/05/30 17:49:11
... Omitted ...
Deletes the change history of execution plans saved in SPH. This procedure provides the same function as the TRUNCATE_PLAN_HISTORY_BY_DATE procedure, but has a different DURATION parameter type.
Details about the TRUNCATE_PLAN_HISTORY procedure are as follows:
Prototype
PROCEDURE TRUNCATE_PLAN_HISTORY ( RETENTION_PERIOD IN PLS_INTEGER DEFAULT 24*365*1000 MAX_COUNT IN PLS_INTEGER DEFAULT 1000000 );
Parameter
Parameter | Description |
---|---|
RETENTION_PERIOD | Time period for which SQL history will be deleted. All execution plans that are not executed during this time period are deleted.
|
MAX_COUNT | Number of SQL statements whose execution plans will not be removed. If both RETENTION_PERIOD and MAX_COUNT are specified, only statements that meet both conditions are maintained.
|
Exception
Exception | Description |
---|---|
PARAMETER_OUT_OF_RANGE | Occurs when the parameter value is out of the specified range. |
Example
SQL> exec dbms_sph.truncate_plan_history(24);
-- Delete all execution plans that have not been
executed for a day.
PSM completed.
Deletes the change history of execution plans saved in SPH. This procedure provides the same function as the TRUNCATE_PLAN_HISTORY procedure, but has a different DURATION parameter type.
Details about the TRUNCATE_PLAN_HISTORY_BY_DATE procedure are as follows:
Prototype
PROCEDURE TRUNCATE_PLAN_HISTORY_BY_DATE ( START_DATE IN DATE DEFAULT SYSDATE - 365*1000 MAX_COUNT IN PLS_INTEGER DEFAULT 1000000 );
Parameter
Parameter | Description |
---|---|
START_DATE | Start time of the time period for which SQL history will be deleted. All execution plans that are executed before this time period are removed.
|
MAX_COUNT | Number of SQL statements whose execution plans will not be removed. If both START_DATE and MAX_COUNT are specified, only statements that meet both conditions will be maintained.
|
Exception
Exception | Description |
---|---|
PARAMETER_OUT_OF_RANGE | Occurs when the parameter value is out of the specified range. |
Example
SQL> exec dbms_sph.truncate_plan_history_by_date(sysdate - 1);
-- Delete all execution plans that have not been
executed for a day.
PSM completed.
Saves execution plans in the library cache to SPH.
Details about the UPDATE_PLAN_HISTORY procedure are as follows:
Prototype
PROCEDURE UPDATE_PLAN_HISTORY ( MIN_EXEC_COUNT IN PLS_INTEGER DEFAULT 1 );
Parameter
Parameter | Description |
---|---|
MIN_EXEC_COUNT | Execution plans that have been executed this many times or less are saved to SPH. Execution plans that are executed less than this number of times are not saved.
|
Exception
Exception | Description |
---|---|
PARAMETER_OUT_OF_RANGE | Occurs when the parameter value is out of the specified range. |
Example
SQL> exec dbms_sph.update_plan_history(2);
-- Save execution plans executed two or more times to SPH.
PSM completed.