The DBMS_SPD
package provides subprograms for managing SQL plan directives (SPD).
See Also:
Oracle Database SQL Tuning Guide regarding SQL plan directives
This chapter contains the following topics:
Overview
Security Model
Views
This package provides subprograms for managing SQL plan directives (SPD). SPD are objects generated automatically by Oracle. For example, if Oracle detects that the single table cardinality estimated made by the optimizer is different from the actual number of rows returned when accessing the table, it will automatically create a directive to perform dynamic statistics for the table. When any SQL statement referencing the table is compiled, the optimizer will perform dynamic statistics for the table to get a more accurate estimate.
Table 147-1 DBMS_SPD Package Subprograms
Subprogram | Description |
---|---|
Changes different attributes of a SQL plan directive |
|
Creates a staging table into which to pack (export) SQL plan directives. |
|
Drops a SQL plan directive |
|
Allows for manual flushing of the SQL plan directives that are automatically recorded in SGA memory while executing SQL statements. |
|
Gets the values for preferences for SQL plan directives |
|
Packs (exports) SQL plan directives into a staging table. |
|
Allows the setting of different preferences for SQL plan directives |
|
Unpacks (imports) SQL plan directives from a staging table. |
This procedure changes different attributes of a SQL plan directive.
DBMS_SPD.ALTER_SQL_PLAN_DIRECTIVE ( directive_id IN NUMBER, attribute_name IN VARCHAR2, attribute_value IN VARCHAR2);
Table 147-2 ALTER_SQL_PLAN_DIRECTIVE Procedure Parameters
Parameter | Description |
---|---|
|
SQL plan directive ID |
|
|
|
Possible values:
|
ORA-38171 INSUFFICIENT_PRIVILEGE
: The user does not have proper privilege to perform the operation.
ORA-28104 INVALID_INPUT
: The input value is not valid.
ORA-13158 OBJECT_DOES_NOT_EXIST
: The specified object does not exist.
This procedure creates a staging table into which to pack (export) SQL plan directives.
DBMS_SPD.CREATE_STGTAB_DIRECTIVE ( table_name IN VARCHAR2, table_owner IN VARCHAR2 := USER, tablespace_name IN VARCHAR2 := NULL);
ORA-38171 INSUFFICIENT_PRIVILEGE
: The user does not have proper privilege to perform the operation.
ORA-28104 INVALID_INPUT
: The input value is not valid.
ORA-44001 INVALID_SCHEMA
: The input schema does not exist.
ORA-13159 TABLE_ALREADY_EXISTS
: The specified table already exists.
ORA-29304 TABLESPACE_MISSING
: The specified tablespace does not exist.
This procedure drops a SQL plan directive.
ORA-38171 INSUFFICIENT_PRIVILEGE
: The user does not have proper privilege to perform the operation.
ORA-28104 INVALID_INPUT
: The input value is not valid.
ORA-13158 OBJECT_DOES_NOT_EXIST
: The specified object does not exist.
This procedure allows for manual flushing of the SQL plan directives that are automatically recorded in SGA memory while executing SQL statements. The information recorded in the SGA is periodically flushed by an Oracle background process. This procedure provides a way to flush the information manually.
ORA-38171 INSUFFICIENT_PRIVILEGE
: The user does not have proper privilege to perform the operation.
This function returns the value for the specified preferences for SQL plan directives.
ORA-38171 INSUFFICIENT_PRIVILEGE
: The user does not have proper privilege to perform the operation.
ORA-28104 INVALID_INPUT
: The input value is not valid.
The ADMINISTER SQL MANAGEMENT OBJECT
privilege is required to execute this procedure.
SPD_RETENTION_WEEKS
- SQL plan directives are purged if not used for more than the value set for this preference.
This function packs (exports) SQL plan directives into a staging table.
DBMS_SPD.PACK_STGTAB_DIRECTIVE ( table_name IN VARCHAR2, table_owner IN VARCHAR2 := USER directive_id IN NUMBER := NULL, obj_list IN OBJECTTAB := NULL) RETURN NUMBER
Table 147-6 PACK_STGTAB_DIRECTIVE Function Parameters
Parameter | Description |
---|---|
|
Name of staging table |
|
Name of schema owner of staging table. Default is current schema. |
|
SQL plan directive ID. Default |
|
Used to filter the directives to be packed based on the objects used in directives. If |
ORA-38171 INSUFFICIENT_PRIVILEGE
: The user does not have proper privilege to perform the operation.
ORA-28104 INVALID_INPUT
: The input value is not valid.
ORA-44001 INVALID_SCHEMA
: The input schema does not exist.
ORA-29304 INVALID_STGTAB
: The specified staging table is invalid or does not exist.
ORA-13158 OBJECT_DOES_NOT_EXIST
: The specified object does not exist.
-- Pack all directives in the system SELECT DBMS_SPD.PACK_STGTAB_DIRECTIVE('mydirtab') FROM DUAL; SET SERVEROUTPUT ON; -- Pack directives relevant to objects in SH schema DECLARE my_list DBMS_SPD.OBJECTTAB := DBMS_SPD.ObjectTab(); dir_cnt NUMBER; BEGIN my_list.extend(1); my_list(1).owner := 'SH'; -- schema name my_list(1).object_name := NULL; -- all tables in SH my_list(1).object_type := 'TABLE'; -- type of object dir_cnt := DBMS_SPD.PACK_STGTAB_DIRECTIVE('mydirtab', obj_list => my_list); DBMS_OUTPUT.PUT_LINE('dir_cnt = ' || dir_cnt); END; -- Pack directives relevant to tables SALES and CUSTOMERS in SH schema DECLARE my_list DBMS_SPD.OBJECTTAB := DBMS_SPD.ObjectTab(); dir_cnt NUMBER; BEGIN my_list.extend(2); -- SALES table my_list(1).owner := 'SH'; my_list(1).object_name := 'SALES'; my_list(1).object_type := 'TABLE'; -- CUSTOMERS table my_list(2).owner := 'SH'; my_list(2).object_name := 'CUSTOMERS'; my_list(2).object_type := 'TABLE'; dir_cnt := DBMS_SPD.PACK_STGTAB_DIRECTIVE('mydirtab', obj_list => my_list); DBMS_OUTPUT.PUT_LINE('dir_cnt = ' || dir_cnt); END;
This procedure allows the setting of different preferences for SQL plan directives.
Table 147-7 SET_PREFS Procedure Parameters
Parameter | Description |
---|---|
|
Preference name. The procedure supports the preference |
|
Preference value.
|
ORA-38171 INSUFFICIENT_PRIVILEGE
: The user does not have proper privilege to perform the operation.
ORA-28104 INVALID_INPUT
: The input value is not valid.
The ADMINISTER SQL MANAGEMENT OBJECT
privilege is required to execute this procedure.
SPD_RETENTION_WEEKS
- SQL plan directives are purged if not used for more than the value set for this preference.
This procedure unpacks (imports) SQL plan directives from a staging table.
DBMS_SPD.UNPACK_STGTAB_DIRECTIVE ( table_name IN VARCHAR2, table_owner IN VARCHAR2 := USER, directive_id IN NUMBER := NULL, obj_list IN OBJECTTAB := NULL) RETURN NUMBER
Table 147-8 UNPACK_STGTAB_DIRECTIVE Function Parameters
Parameter | Description |
---|---|
|
Name of staging table |
|
Name of schema owner of staging table. Default is current schema. |
|
SQL plan directive ID. Default |
|
Used to filter the directives to be unpacked based on the objects used in directives. If |
ORA-38171 INSUFFICIENT_PRIVILEGE
: The user does not have proper privilege to perform the operation.
ORA-28104 INVALID_INPUT
: The input value is not valid.
ORA-44001 INVALID_SCHEMA
: The input schema does not exist.
ORA-29304 INVALID_STGTAB
: The specified staging table is invalid or does not exist.
ORA-13158 OBJECT_DOES_NOT_EXIST
: The specified object does not exist.
-- Unack all directives in the staging table SELECT DBMS_SPD.UNPACK_STGTAB_DIRECTIVE('mydirtab') FROM DUAL; SET SERVEROUTPUT ON; -- Unpack directives relevant to objects in SH schema DECLARE my_list DBMS_SPD.OBJECTTAB := DBMS_SPD.ObjectTab(); dir_cnt number; BEGIN my_list.extend(1); my_list(1).owner := 'SH'; -- schema name my_list(1).object_name := null; -- all tables in SH my_list(1).object_type := 'TABLE'; -- type of object dir_cnt := DBMS_SPD.UNPACK_STGTAB_DIRECTIVE('mydirtab', obj_list => my_list); DBMS_OUTPUT.PUT_LINE('dir_cnt = ' || dir_cnt); END; -- Unpack directives relevant to tables SALES and CUSTOMERS in SH schema DECLARE my_list DBMS_SPD.OBJECTTAB := DBMS_SPD.ObjectTab(); dir_cnt NUMBER; begin my_list.extend(2); -- SALES table my_list(1).owner := 'SH'; my_list(1).object_name := 'SALES'; my_list(1).object_type := 'TABLE'; -- CUSTOMERS table my_list(2).owner := 'SH'; my_list(2).object_name := 'CUSTOMERS'; my_list(2).object_type := 'TABLE'; dir_cnt := DBMS_SPD.UNPACK_STGTAB_DIRECTIVE('mydirtab', obj_list => my_list); DBMS_OUTPUT.PUT_LINE('dir_cnt = ' || dir_cnt); END;