What is SQL PROFILE in oracle?

You might have heard of SQL profile and SQL baselines in performance tuning chapters. Lets today go through details about sql profile.

What is SQL profile:

SQL profile is a collection of additional statistical information stored in the data dictionary that helps the optimizer to generate the best plan for the query. SQL profile is managed through SQL_TUNE package of SQL tuning advisor. i.e when we run SQL tuning advisor against a query, The tuning optimizer creates a profile for an SQL statement called SQL profile which consists additional statistical information about that statement, and it gives the recommendation to accept that profile.

NOTE – It is important to note that the SQL Profile does not freeze the execution plan of a SQL statement, as done by stored outlines. As tables grow or indexes are created or dropped, the execution plan can change with the same SQL Profile. The information stored in it continues to be relevant even as the data distribution or access path of the corresponding statement change.

SQL PROFILE can be applied to below statements.

SELECT statements
UPDATE statements
INSERT statements (only with a SELECT clause)
DELETE statements
CREATE TABLE statements (only with the AS SELECT clause)
MERGE statements (the update or insert operations)


In this example, first we will run SQL tuning advisor against an sql_id , and then will do different operations on sql profile.

1. Run sql tuning advisor for sql_id=5dkrnbx1z8gcb

Recommendation (estimated benefit: 96.57%)
- Consider accepting the recommended SQL profile.

execute dbms_sqltune.accept_sql_profile(task_name => '5dkrnbx1z8gcb_tuning_task_1', task_owner => 'SYS', replace =>TRUE);

2. Accept profile:

execute dbms_sqltune.accept_sql_profile(task_name => '5dkrnbx1z8gcb_tuning_task_1', task_owner => 'SYS', replace =>TRUE);

3. Find the name of the sql_profile:

select name,status,force_matching from dba_sql_profiles where task_id in ( select task_id from DBA_ADVISOR_TASKS where task_name ='5dkrnbx1z8gcb_tuning_task_1')

set pagesize 299
set lines 299
col name for a45
---------------------------------- -------- ---
SYS_SQLPROF_01601b64332e0000 ENABLED NO

4. Alter a profile,

name => 'SYS_SQLPROF_01601b64332e0000',
attribute_name => 'STATUS',
value => 'DISABLED');

To enable to changed the value from DISABLED to ENABLED.

5. Dropping an SQL profile:

DBMS_SQLTUNE.DROP_SQL_PROFILE(name => 'SYS_SQLPROF_01601b64332e0000');