|
Re: XML/XPath rewrites and plan baselines [message #599850 is a reply to message #599848] |
Tue, 29 October 2013 09:08 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Hi,
I think more information is needed. I am a bit confused. Did you apply the baseline from hinted query to this non-hinted one? If yes, did it not work? Can you please post the steps you followed.
Ideally it should work as documented. I learnt this technique from Jonathan Lewis' and Randolf's blogs. I remember when Jonathan stated that with cursor_sharing being set to force or similar might create a mess.
[Updated on: Tue, 29 October 2013 09:13] Report message to a moderator
|
|
|
Re: XML/XPath rewrites and plan baselines [message #599860 is a reply to message #599850] |
Tue, 29 October 2013 10:07 |
Roachcoach
Messages: 1576 Registered: May 2010 Location: UK
|
Senior Member |
|
|
The queries are horrendous, so I'll truncate for readability.
alter system flush shared_pool
/
--bad query
select ......
/
--good version
select /*+ leading (sys_alias...) */ .....
/
Pull the "good" and "bad" sql_ids and plans from v$sql - easy to find as the pools had been purged.
--From http://jonathanlewis.wordpress.com/2011/01/12/fake-baselines/
DECLARE
m_clob CLOB;
BEGIN
SELECT st.sql_fulltext
INTO m_clob
FROM v$sql st
WHERE sql_id = '7jpk22cstfttk' -- original (slow) query sql_id
;
dbms_output.put_line(m_clob);
dbms_output.put_line(
dbms_spm.load_plans_from_cursor_cache(
sql_id => 'brz69t0254gf9', -- hinted (fast) query sql_id
plan_hash_value => 561479308, -- plan hash of the hinted (fast) query
sql_text => m_clob, -- clob of the original (slow) query
fixed => 'YES',
enabled => 'YES'
)
);
END;
/
This code above returns 1 - the baseline is added and can be seen in dba_sql_plan_baselines. It is accepted, enabled...but doesnt show as working either in explain plan, auto trace or in v$sql.
Enter value for sql_stmt: SELECT * FROM DBA_SQL_PLAN_BASELINES
SIGNATURE : 6735181605168109909
SQL_HANDLE : SQL_5d782bfc41ca5955
SQL_TEXT : select .......
PLAN_NAME : SQL_PLAN_5uy1bzj0wnqapc80ef354
CREATOR : SYS
ORIGIN : MANUAL-LOAD
PARSING_SCHEMA_NAME : SYS
DESCRIPTION :
VERSION : 11.2.0.4.0
CREATED : 29-OCT-13 14.26.34.000000
LAST_MODIFIED : 29-OCT-13 14.26.34.000000
LAST_EXECUTED :
LAST_VERIFIED :
ENABLED : YES
ACCEPTED : YES
FIXED : YES
REPRODUCED : YES
AUTOPURGE : YES
OPTIMIZER_COST : 17
MODULE : sqlplus@machine (TNS V1-V3)
ACTION :
EXECUTIONS : 1
ELAPSED_TIME : 125783
CPU_TIME : 124981
BUFFER_GETS : 1495
DISK_READS : 1
DIRECT_WRITES : 0
ROWS_PROCESSED : 0
FETCHES : 1
END_OF_FETCH_COUNT : 1
So....I appear to be able to create and load a baseline....which is "accepted", yet it is steadfastly not used by the code.
As I say, I strongly suspect I'm trying the impossible but I've struggled to find anything around this online anywhere - seems to be something just not done, which is usually a bad sign
[Updated on: Tue, 29 October 2013 10:10] Report message to a moderator
|
|
|
Re: XML/XPath rewrites and plan baselines [message #599865 is a reply to message #599860] |
Tue, 29 October 2013 10:32 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
So, this is what you did step-by-step :
1. Flushed shared pool.
2. Executed non-hinted query to generate the bad execution plan.
3. Executed hinted query to generate the good execution plan.
4. Captured sql_id and plan_hash_value for both the plans.
5. Created a baseline to associate the good plan with the bad query.
6. Checked the SQL Baseline and confirmed by looking into dba_sql_plan_baselines.
7. Executed the non-hinted query.
Observations :
1. In step 5, you did not consider the child number for the child cursor to associate with the sql id while creating the baseline.
2. After step 6, i.e. after creating the baseline, did you flush the shared pool? Else, the original child cursor could still be used.
You did not post the cursor_sharing parameter details. It is important with bind variables.
Regards,
Lalit
|
|
|
Re: XML/XPath rewrites and plan baselines [message #599868 is a reply to message #599865] |
Tue, 29 October 2013 10:39 |
Roachcoach
Messages: 1576 Registered: May 2010 Location: UK
|
Senior Member |
|
|
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cursor_sharing string EXACT
I'd not have expected children as it's an idle instance after a pool flush and two distinct sqls.
Yes, I also (later) tried flushing the pool after creating the baselines to no avail.
|
|
|
|
Re: XML/XPath rewrites and plan baselines [message #599922 is a reply to message #599848] |
Wed, 30 October 2013 04:12 |
Roachcoach
Messages: 1576 Registered: May 2010 Location: UK
|
Senior Member |
|
|
Thanks
I'm trying to work on a generic test case that can replicate the issue, unfortunately our system the data for each rows xml column is huge and absolutely packed with stuff, loads of paths indexed - it's not your 'usual' easy to create a generic mapping with fake data. Maybe if I was better at XML
DDL is easy, it's inserts that are the real headache.
[Updated on: Wed, 30 October 2013 04:13] Report message to a moderator
|
|
|