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)

EXAMPLE:

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

2. Go through the profile recommendation part of the report:

DBMS_SQLTUNE.report_tuning_task will generate the completed output of the advisory. If you go through the profile recommendation part, it will be as below.

2. Accept profile:

3. Find the name of the sql_profile:

in the accept_sql_profile package we didn’t specify a sql_profile name, So we need to find the sql_profile from the task_name.
Use the below query.

4. Alter a profile,

You can disable a sql_profile using steps.

5. Dropping an SQL profile: