Hello everyone, hope you all doing good. It’s been too long I haven’t updated new post on my blog due to my busy schedule.
So here I will be sharing very interesting post of creating sql baseline and force query to use better execution plan (plan hash value).
Most of us have come across this scenario where query which was running fine till yesterday now suddenly running long.
So there could be many reasons why query performance has been changed suddenly, so one of the reason is change in query plan.
In such situation we need to find out best execution plan (Plan_hash_value) and force query to use that plan.
Below are the steps to create and fix bad query by creating sql baseline.
STEP 1: GENERATE ALL PREVIOUS HISTORY RUN DETAILS OF SQL_ID FROM AWR
Enter value for sql_id: 7hgwdax4mn20v
/*In this scenario sql_id=7hgwdax4mn20v and plan_hash_value for good plan that we want to force is 1355798266.*/
Follow the below steps to create sql baseline for sql_id
STEP 2: DROP SQL TUNING SET (STS) IF EXISTS
STEP 3: CREATE SQL TUNING SET
/* Populate STS from AWR by specifying snapshot for desired plan which we found using above query.
In this scenario snap id's are 23483 and 23484 and change plan_hash_value accordingly.*/
STEP 4: CHECK SQL SET DETAILS
STEP 5: LOAD THE DESIRED PLAN FROM STS AS SQL PLAN BASELINE
STEP 6: CHECK SQL PLAN BASELINE INFORMATION
STEP 7: ENABLE FIXED=YES
STEP 8: Check the SQL baseline details
Use the plan name received from the STEP 6 output to get the baseline details
STEP 9: PURGE OLD EXECUTION PLAN FROM SHARED POOL
Find below two parameters required to purge specific sql from the shared pool.
Now use the below command to purge sql from the shared pool.
I hope this article helped you. Your suggestions/feedback are most welcome.
Keep learning... Have a great day!!!
Thank you,
Amit Pawar
Email: amitpawar.dba@gmail.com
WhatsApp No: +91-8454841011