If you have run sql tunning advisor as mentioned in this doc and get recommendation to accept sql profile
https://dbatracker.com/2021/02/04/run-sql-tunning-advisor-for-sql_id/
then perform below steps
Setp 1: accept profile using the statement which came in your advisory
i received below advisory
Recommendation (estimated benefit: 81.25%)
------------------------------------------
- Consider accepting the recommended SQL profile.
execute dbms_sqltune.accept_sql_profile(task_name =>
'SQL_TUNNING_TASK_SQL_ID', task_owner => 'SYS', replace => TRUE);
Recommendation (estimated benefit: 98.51%)
------------------------------------------
- Consider accepting the recommended SQL profile to use parallel execution
for this statement.
execute dbms_sqltune.accept_sql_profile(task_name =>
'SQL_TUNNING_TASK_SQL_ID', task_owner => 'SYS', replace => TRUE,
profile_type => DBMS_SQLTUNE.PX_PROFILE);
i am accepting the first one
SQL> execute dbms_sqltune.accept_sql_profile(task_name =>'SQL_TUNNING_TASK_SQL_ID', task_owner => 'SYS', replace => TRUE);
PL/SQL procedure successfully completed.
check explain plan after accepting the profile it will say sql profile is used
SQL> select *from table (sys.dbms_xplan.display);
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 4118786896
---------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 7084 | 6722 (1)| 00:01:21 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 14 | 7084 | 6722 (1)| 00:01:21 |
|* 3 | TABLE ACCESS FULL | CC_CIRC_PATH_INST | 2 | 60 | 6716 (1)| 00:01:21 |
|* 4 | INDEX RANGE SCAN | CC_OMM_SERVICE_ID_INDEX1 | 1 | | 2 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID| CC_SIESEL_OMM_ORDERS | 7 | 3332 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter(SYS_OP_C2C("B"."ORDER_NUM") LIKE U'%183331823%')
4 - access("A"."SERVICE_ID"=SYS_OP_C2C("B"."ORDER_NUM"))
filter("SERVICE_ID" LIKE U'%183331823%' AND "SERVICE_ID" IS NOT NULL)
Note
-----
- SQL profile "SYS_SQLPROF_017770a849300999" used for this statement
23 rows selected.
step 2: Find the name of the sql_profile:
set pagesize 299
set lines 299
col name for a45
select name,status,force_matching from dba_sql_profiles where task_id in ( select task_id from DBA_ADVISOR_TASKS where task_name ='SQL_TUNNING_TASK_SQL_ID');
NAME STATUS FOR
------------------------------ -------- ---
SYS_SQLPROF_017770a849300999 ENABLED NO
Setp 3: Alter a profile – You can disable a sql_profile using steps.
#### To enable change the value from DISABLED to ENABLED.
SQL> BEGIN
DBMS_SQLTUNE.ALTER_SQL_PROFILE(
name => 'SYS_SQLPROF_017770a849300999',
attribute_name => 'STATUS',
value => 'DISABLED');
END;
/ 2 3 4 5 6 7
PL/SQL procedure successfully completed.
SQL> select name,status,force_matching from dba_sql_profiles where task_id in ( select task_id from DBA_ADVISOR_TASKS where task_name ='SQL_TUNNING_TASK_SQL_ID');
NAME STATUS FOR
------------------------------ -------- ---
SYS_SQLPROF_017770a849300999 DISABLED NO
BEGIN
DBMS_SQLTUNE.ALTER_SQL_PROFILE(
name => 'SYS_SQLPROF_017770a849300999',
attribute_name => 'STATUS',
value => 'ENABLED');
END;
/
SQL> select name,status,force_matching from dba_sql_profiles where task_id in ( select task_id from DBA_ADVISOR_TASKS where task_name ='SQL_TUNNING_TASK_SQL_ID');
NAME STATUS FOR
------------------------------ -------- ---
SYS_SQLPROF_017770a849300999 ENABLED NO
Step 4: drop sql profile
begin
DBMS_SQLTUNE.DROP_SQL_PROFILE(name => 'SYS_SQLPROF_017770a849300999');
end;
/
step 5: you can accept the second profile without disabling the first one
SQL> execute dbms_sqltune.accept_sql_profile(task_name =>'SQL_TUNNING_TASK_SQL_ID', task_owner => 'SYS', replace => TRUE,profile_type => DBMS_SQLTUNE.PX_PROFILE);
PL/SQL procedure successfully completed.
SQL> select name,status,force_matching from dba_sql_profiles where task_id in ( select task_id from DBA_ADVISOR_TASKS where task_name ='SQL_TUNNING_TASK_SQL_ID');
NAME STATUS FOR
--------------------------------------------- -------- ---
SYS_SQLPROF_017770a849300999 ENABLED NO
you can see the explain plan changed again
SQL> select *from table (sys.dbms_xplan.display);
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2412986615
----------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
----------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 7084 | 466 (0)| 00:00:06 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM) | :TQ10000 | | | | | Q1,00 | P->S | QC (RAND) |
| 3 | NESTED LOOPS | | | | | | Q1,00 | PCWP | |
| 4 | NESTED LOOPS | | 14 | 7084 | 466 (0)| 00:00:06 | Q1,00 | PCWP | |
| 5 | PX BLOCK ITERATOR | | | | | | Q1,00 | PCWC | |
|* 6 | TABLE ACCESS FULL | CC_CIRC_PATH_INST | 2 | 60 | 466 (1)| 00:00:06 | Q1,00 | PCWP | |
|* 7 | INDEX RANGE SCAN | CC_OMM_SERVICE_ID_INDEX1 | 1 | | 0 (0)| 00:00:01 | Q1,00 | PCWP | |
| 8 | TABLE ACCESS BY INDEX ROWID| CC_SIESEL_OMM_ORDERS | 7 | 3332 | 0 (0)| 00:00:01 | Q1,00 | PCWP | |
----------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
6 - filter(SYS_OP_C2C("B"."ORDER_NUM") LIKE U'%180101823%')
7 - access("A"."SERVICE_ID"=SYS_OP_C2C("B"."ORDER_NUM"))
filter("SERVICE_ID" LIKE U'%183331823%' AND "SERVICE_ID" IS NOT NULL)
Note
-----
- automatic DOP: skipped because of IO calibrate statistics are missing
- SQL profile "SYS_SQLPROF_017770a849300999" used for this statement