Explain plan changing for the same sql
Hi All,
In a E Business suite application, we have the 10.2.0.4 Database.
One of the program is running a select stmt which is using different explain plan one in a month which is causing issue in the program running for longer time.
Ex : When it uses the index A, it is running fine. When it uses the index B, it is running for longer time.
Can you please advice on the possible reasons for the same sql to choose index B instead of index A some times.
Thanks,
Rakesh
It could be that the SQL is question got aged out of the shared pool and when it came to be reparsed - the values in the bind variables were such that access via index b was more attractive than access via index a.
Could you please send the query and the good and bad plans and all other information that might help diagnose the problem..
Note: we had a similiar case where plans suddenly changed for no apperant reason (on 10.2.0.2) - we found that under certain circumstances the optimizer would not peek into the bind varaibles to derive the execution path.
Similar Messages
-
Different execution plans for the same sql
Hi,
Im testing our new 10gR2 database on Linux and I can't understand why the same query use different plan.
Here are the details.
Table name: invoice_detail
Records: About 10,670,900
Columns:
No
seq (the primary key is No+Seq). Each invoices contains +/- 10 invoice_details.
category ( <- 10 different values )
State ( <- 3 different values )
Basically, I have an index on the primary key and another index on Category + State.
My request:
select *
from invoice_detail
where no=123456 <- Best index to use
and state <> 'CANCEL'
and category = 'INVOICE'
If i run this query from Toad or sql+, that's fine.
The same query (i'm watching it from EM) executed via Forms use the category+state index.
When I first import the database, the last thing I do is to run DBMS_STATS.GATHER_DATABASE_STATS.
At this point, Forms use the right index.
The day after (after the database has been analyzed with the predefined job via EM) Forms use the wrong index.
I re-analyzed everything with exec DBMS_STATS.GATHER_DATABASE_STATS but the problem is still there.
Thanks in advanceI'm already using bind variables.
I changed the "Estimated Percentage" to 100% in "Gather Optimizer Statistics Default Options" and now it seems to use the correct index. I'm stressed because I dont understand why it chooses different plan for the same sql.
Actually, my users test the migration 1 day after I load all the data (drop schema-create schema-load data-analyze database) and at this point everythings go fine. After the second analyze of the database, the DB choose the wrong indexes.
I really cannot migrate until I understand why it happens.
Any ideas?
TIA -
Multiple Executions Plans for the same SQL statement
Dear experts,
awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.
Below is the awrsqrpt's output for your reference.
WORKLOAD REPOSITORY SQL Report
Snapshot Period Summary
DB Name DB Id Instance Inst Num Release RAC Host
TESTDB 2157605839 TESTDB1 1 10.2.0.3.0 YES testhost1
Snap Id Snap Time Sessions Curs/Sess
Begin Snap: 32541 11-Oct-08 21:00:13 248 141.1
End Snap: 32542 11-Oct-08 21:15:06 245 143.4
Elapsed: 14.88 (mins)
DB Time: 12.18 (mins)
SQL Summary DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
Elapsed
SQL Id Time (ms)
51szt7b736bmg 25,131
Module: SQL*Plus
UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(ACCT_DR_BAL,
0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND TEST_ACC_NB = ACCT_ACC_NB(+)) WHERE
TEST_BATCH_DT = (:B1 )
SQL ID: 51szt7b736bmg DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
-> 1st Capture and Last Capture Snap IDs
refer to Snapshot IDs witin the snapshot range
-> UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(AC...
Plan Hash Total Elapsed 1st Capture Last Capture
# Value Time(ms) Executions Snap ID Snap ID
1 2960830398 25,131 1 32542 32542
2 3834848140 0 0 32542 32542
Plan 1(PHV: 2960830398)
Plan Statistics DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
-> % Total DB Time is the Elapsed Time of the SQL statement divided
into the Total Database Time multiplied by 100
Stat Name Statement Per Execution % Snap
Elapsed Time (ms) 25,131 25,130.7 3.4
CPU Time (ms) 23,270 23,270.2 3.9
Executions 1 N/A N/A
Buffer Gets 2,626,166 2,626,166.0 14.6
Disk Reads 305 305.0 0.3
Parse Calls 1 1.0 0.0
Rows 371,735 371,735.0 N/A
User I/O Wait Time (ms) 564 N/A N/A
Cluster Wait Time (ms) 0 N/A N/A
Application Wait Time (ms) 0 N/A N/A
Concurrency Wait Time (ms) 0 N/A N/A
Invalidations 0 N/A N/A
Version Count 2 N/A N/A
Sharable Mem(KB) 26 N/A N/A
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | | | 1110 (100)| |
| 1 | UPDATE | TEST | | | | |
| 2 | TABLE ACCESS FULL | TEST | 116K| 2740K| 1110 (2)| 00:00:14 |
| 3 | TABLE ACCESS BY INDEX ROWID| ACCT | 1 | 26 | 5 (0)| 00:00:01 |
| 4 | INDEX RANGE SCAN | ACCT_DT_ACC_IDX | 1 | | 4 (0)| 00:00:01 |
Plan 2(PHV: 3834848140)
Plan Statistics DB/Inst: TESTDB/TESTDB1 Snaps: 32541-32542
-> % Total DB Time is the Elapsed Time of the SQL statement divided
into the Total Database Time multiplied by 100
Stat Name Statement Per Execution % Snap
Elapsed Time (ms) 0 N/A 0.0
CPU Time (ms) 0 N/A 0.0
Executions 0 N/A N/A
Buffer Gets 0 N/A 0.0
Disk Reads 0 N/A 0.0
Parse Calls 0 N/A 0.0
Rows 0 N/A N/A
User I/O Wait Time (ms) 0 N/A N/A
Cluster Wait Time (ms) 0 N/A N/A
Application Wait Time (ms) 0 N/A N/A
Concurrency Wait Time (ms) 0 N/A N/A
Invalidations 0 N/A N/A
Version Count 2 N/A N/A
Sharable Mem(KB) 26 N/A N/A
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | | | 2 (100)| |
| 1 | UPDATE | TEST | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| TEST | 1 | 28 | 2 (0)| 00:00:01 |
| 3 | INDEX RANGE SCAN | TEST_DT_IND | 1 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| ACCT | 1 | 26 | 4 (0)| 00:00:01 |
| 5 | INDEX RANGE SCAN | INDX_ACCT_DT | 1 | | 3 (0)| 00:00:01 |
Full SQL Text
SQL ID SQL Text
51szt7b736bm UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL, 0) +
NVL(ACCT_DR_BAL, 0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND PB
RN_ACC_NB = ACCT_ACC_NB(+)) WHERE TEST_BATCH_DT = (:B1 )Your input is highly appreciated.
Thanks for taking your time in answering my question.
RegardsOracle Lover3 wrote:
Dear experts,
awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.If you're using bind variables and you've histograms on your columns which can be created by default in 10g due to the "SIZE AUTO" default "method_opt" parameter of DBMS_STATS.GATHER__STATS it is quite normal that you get different execution plans for the same SQL statement. Depending on the values passed when the statement is hard parsed (this feature is called "bind variable peeking" and enabled by default since 9i) an execution plan is determined and re-used for all further executions of the same "shared" SQL statement.
If now your statement ages out of the shared pool or is invalidated due to some DDL or statistics gathering activity it will be re-parsed and again the values passed in that particular moment will determine the execution plan. If you have skewed data distribution and a histogram in place that reflects that skewness you might get different execution plans depending on the actual values used.
Since this "flip-flop" behaviour can sometimes be counter-productive if you're unlucky and the values used to hard parse the statement leading to a plan that is unsuitable for the majority of values used afterwards, 11g introduced the "adaptive" cursor sharing that attempts to detect such a situation and can automatically re-evaluate the execution plan of the statement.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Several plan orders for the same day
Hi SAP Experts,
In my company we have a requirement to produce the same finish material in two work centers, using different BOMs. This was achieved through production versions for production orders. Now we need to plan (Indipendent requirement & Plan orders )the material based on these two BOMs.
We enter the indipendent requirement in MD61. I have given the production version against the requirement (In schedule lines tab). However i am unable to give two different requirements for the same day in different production versions.
Then i tried using different planning versions and assigning the different production versions to different plan versions.
Although my indipendent requirements are taken in different production versions(As I can see in MD04). When i run MRP plan orders are raised as the total of the requirements and in only one production version.
Please, Can some one help me to find a method to raise different plan orders for the same day in different production versions???
regards,
MadhushikaDear All,
I tried quota arrangements as a solution for above mentioned problem. What i require is to devide the PIR for a particular day in to two equal parts in two different production versions so that two plan orders will raise in equal quantities for the same day in two different production versions.
With quota arrangement what i get is alternative plan oders in different versions in diffrent days.
For example If my PIR are
Day 1 = 1000
Day 2 = 1500
Day 3 = 500
Day 4 = 1000
what i get is
Day 1 = 1000 - prd ver1
Day 2 = 1500 - prd ver2
Day 3 = 500 - prd ver1
Day 4 = 1000 - prd ver2
What i want is
Day 1 = 500 -prd ver1
Day 1 = 500 -prd ver2
Day 2 = 750 -prd ver1
Day 2 = 750 -prd ver2
Day 3 = 250 -prd ver1
Day 3 = 250 -prd ver2
Day 4 = 500 -prd ver1
Day 4 = 500 -prd ver2
Hope its clear to you all.
Please advise me how to configure the system according to this reqirement.
Best regards,
Madhushika -
Oracle Incentives, Different plans applicable for the same invoice
Dear Oracle incentive exports,
I need to know how we can apply 2 plans for the same invoice?
Suppose we have ONE plan that says 2% from $0-$750,000 and 4% from $750,000 to $1,000,000. If the sales is $800.000 the 2% will be applied for the 1st 750.000 and the remaining amount (50.000) will be calculated for 4% . This needs to be done without dividing the amount into two invoices.
How can this be applicable???
FADIFadi,
when you define formular, you may use split option to handle this
Regards
Srini -
Different execution plans for the same SQL query
Good afternoon,
My customer is sending an SQL query that goes slower after some time.
He has verified the exection plan, and this seems to change after some time.
At first (when the database has just been restarted), it looks like this:
Rows Row Source Operation
3 TABLE ACCESS BY GLOBAL INDEX ROWID <TABLE1> PARTITION: 1 1
22 NESTED LOOPS
3 VIEW
3 MINUS
14215 SORT UNIQUE
14215 NESTED LOOPS
14215 TABLE ACCESS FULL <TABLE1> PARTITION: 1 1
14215 TABLE ACCESS BY GLOBAL INDEX ROWID <TABLE2> PARTITION: 1 1
14215 INDEX UNIQUE SCAN <INDEX2> (object id 26024)
14212 SORT UNIQUE
14212 REMOTE
18 INDEX RANGE SCAN <INDEX1> (object id 25911)
After a while, this becomes:
Rows Row Source Operation
8 NESTED LOOPS
14218 TABLE ACCESS FULL <TABLE1> PARTITION: 1 1
8 VIEW
113744 MINUS
202151524 SORT UNIQUE
14218 NESTED LOOPS
14218 TABLE ACCESS FULL <TABLE1> PARTITION: 1 1
14218 TABLE ACCESS BY GLOBAL INDEX ROWID <TABLE2> PARTITION: 1 1
14218 INDEX UNIQUE SCAN <INDEX_2> (object id 26024)
202037780 SORT UNIQUE
14210 REMOTE
At regular intervals a "coalesce" of the <INDEX2> is scheduled.
Do you have any idea what might cause this different plans? (it's heavily impacting performance, because the second execution plan takes 5 times more time)
Thanks
Dominique
Edited by: scampsd on May 17, 2011 1:42 PMscampsd wrote:
Good afternoon,
My customer is sending an SQL query that goes slower after some time.
He has verified the exection plan, and this seems to change after some time.
At first (when the database has just been restarted), it looks like this:
At regular intervals a "coalesce" of the <INDEX2> is scheduled.
Do you have any idea what might cause this different plans? (it's heavily impacting performance, because the second execution plan takes 5 times more time)Something on your system is changing. Unfortunately if finding out what were easy you would have done it already
You have isolated a couple of things. What happends of you disable the index maintenance?
It is odd that performance as you described it degrands merely because of time the database has been up -
SCD - source sets where multiple changes exist for the same natural key
I am using the Oracle SCD type2 method (end date old record and insert the new record) which was working fine until my source set contained multiple changes for the same natural key. Does anyone know of a way to handle this?
ThanksHello,
I think, the way of handling multiply changes of NK is totally depend on business requirements for your project.
There could be number of approaches for this. For example:
- all changes but the last are considered active during one day, going subsequently right after previously existed SCD record;
- all changes but the last are considered active depending on its occurrence within fact data (as far as you consider NK change based on some attribute set - probably some of attributes show themselves within fact data)
- etc.
So, make an agreement upon this with your customer and ETL design decision will follow immediately.
Sergey -
Credit limits for the same Customer for different countries.
Hi SAP Gurus,
A customer belongs to 2 different countries, the credit limits are maintained in FD32 for one country.
But basing on the "country" the credit limits should change for the same customer.
So how we need to handle FD32 in this scenario. Is there any option to maintain credit limits basing on the "Country"?
Thanks and Regards
Sunil
Edited by: Sunil.kds on May 27, 2011 9:37 AMHi ,
sales area wise , you can differentiate the credit limit . In this case , you can have one more credit control area and assign it to new sales area. it the same customer comes under diff country , extend the customer to the new sales area . By doing so, you can have 2 credit limits for the same customer.
With Regards
S.Siva -
Performance problem: Query explain plan changes in pl/sql vs. literal args
I have a complex query with 5+ table joins on large (million+ row) tables. In it's most simplified form, it's essentially
select * from largeTable large
join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
join...(other aux tables)
where large.pk_id between 123 and 456;
Its performance was excellent with literal arguments (1 sec per execution).
But, when I used pl/sql bind argument variables instead of 123 and 456 as literals, the explain plan changes drastically, and runs 10+ minutes.
Ex:
CREATE PROCEDURE runQuery(param1 INTEGER, param2 INTEGER){
CURSOR LT_CURSOR IS
select * from largeTable large
join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
join...(other aux tables)
where large.pk_id between param1 AND param2;
BEGIN
FOR aRecord IN LT_CURSOR
LOOP
(print timestamp...)
END LOOP;
END runQuery;
Rewriting the query 5 different ways was unfruitful. DB hints were also unfruitful in this particular case. LargeTable.pk_id was an indexed field as were all other join fields.
Solution:
Lacking other options, I wrote a literal query that concatenated the variable args. Open a cursor for the literal query.
Upside: It changed the explain plan to the only really fast option and performed at 1 second instead of 10mins.
Downside: Query not cached for future use. Perfectly fine for this query's purpose.
Other suggestions are welcome.AmandaSoosai wrote:
I have a complex query with 5+ table joins on large (million+ row) tables. In it's most simplified form, it's essentially
select * from largeTable large
join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
join...(other aux tables)
where large.pk_id between 123 and 456;
Its performance was excellent with literal arguments (1 sec per execution).
But, when I used pl/sql bind argument variables instead of 123 and 456 as literals, the explain plan changes drastically, and runs 10+ minutes.
Ex:
CREATE PROCEDURE runQuery(param1 INTEGER, param2 INTEGER){
CURSOR LT_CURSOR IS
select * from largeTable large
join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
join...(other aux tables)
where large.pk_id between param1 AND param2;
BEGIN
FOR aRecord IN LT_CURSOR
LOOP
(print timestamp...)
END LOOP;
END runQuery;
Rewriting the query 5 different ways was unfruitful. DB hints were also unfruitful in this particular case. LargeTable.pk_id was an indexed field as were all other join fields.
Solution:
Lacking other options, I wrote a literal query that concatenated the variable args. Open a cursor for the literal query.
Upside: It changed the explain plan to the only really fast option and performed at 1 second instead of 10mins.
Downside: Query not cached for future use. Perfectly fine for this query's purpose.
Other suggestions are welcome.Best wild guess based on what you've posted is a bind variable mismatch (your column is declared as a NUMBER data type and your bind variable is declared as a VARCHAR for example). Unless you have histograms on the columns in question ... which, if you're using bind variables is usually a really bad idea.
A basic illustration of my guess
http://blogs.oracle.com/optimizer/entry/how_do_i_get_sql_executed_from_an_application_to_uses_the_same_execution_plan_i_get_from_sqlplus -
Im registerd with Qatar store and now i want to change the same to india store.Do i need a seperate id for the same ? If so how can i do dat ?
you need to be running OSX 10.7 or 10.8 to use iCloud i believe. It shows you are using 10.6.8 which doesn't support iCloud.
-
Ability to open multiple SQL Worksheets for the same connection
Hi,
Please allow the ability to open multiple SQL Worksheets for the same connection, now only one can be opened.
ThanksLogged Bug 9000801 - ea1: otnforum: worksheet launcher does not remember the last/default connection
-Raghu -
I am subscribed to Photoshop only and I want to know if I can change my subscription to have your new offer of Lightroom and Photoshop together for the same price that I am paying for Photoshop alone?
Contact sales support by web chat. They can cancel your current subscription and transfer you to the new one if you are within certain criteria. Otherwise you may need to wait until your subscription runs out and then sign up later.
Mylenium -
Random Number being changed to the same number for all rows
hello all,
first of all I want to mention that this problem start happening after 2.14 instalation of Power Query.
I'm creating new column in my query and setting all values to random numbers. The problem is that next step (doesn't matter what it do itself) somehow changes all those random numbers to the same random number for all lines.
here's code sample:
InsertedCustom = Table.AddColumn(RemovedColumns3, "Random Number", each Number.Random()),
InsertedCustom2 = Table.AddColumn(InsertedCustom, "Analyst Full Name", each [Analyst First Name]&" "&[Analyst Last Name]),
when I'm checking step by step, InsertedCustom creates new column and all values are being set randomly for all lines BUT when going to the next step (InsertedCustom2) all values in the column "Random Number" are being changed to the
same number (no matter that InsertedCustom2 itself should not be doing anything to column named "Random Number") . I even tried moving InsertedCustom step to the bottom of my code but it didn't help and still facing this issue.
p.s. updated my PQ to 2.15 - didn't helpThis is a known issue. Power Query assumes that functions are idempotent (given the same arguments, they produce the same result), which isn't true for Number.Random. Our optimization pipeline is turning Number.Random() into a constant in the scenario you
encountered, which results in all rows having the same value.
There's been some discussion of how to fix this, but that won't help you in the near term. Can you describe a bit more about your scenario and what you're trying to accomplish? Perhaps we can help you find a workaround.
Ehren -
I just upgraded my data plan from 6GB to 10GB for the same rate of $80 per month. Is this a promotion? If yes, when does the promotion end?
In most cases you keep the same plan and promotions even when you upgrade the phone. There are exceptions for very old plans and unlimited data, but essentially mrhelper is correct. You have option to "keep current plan" when upgrading. so in most cases, your statement that you will go back to $100 for 10 GB when upgrading is incorrect. What was your particular circumstance?
-
My account asks me to change my password every week for no reason and i have different security questions for the same account
Does the iPod connect to other networks?
Does the iPod see the network?
Any error messages?
Do other devices now connect?
Did the iPod connect before?
Try the following to rule out a software problem:
- Reset the iOS device. Nothing will be lost
Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
least ten seconds, until the Apple logo appears.
- Power off and then back on the router
- Reset network settings: Settings>General>Reset>Reset Network Settings
- iOS: Troubleshooting Wi-Fi networks and connections
- Wi-Fi: Unable to connect to an 802.11n Wi-Fi network
- iOS: Recommended settings for Wi-Fi routers and access points
- Try changing the security on the router. Start with no securty as a test.
- Restore from backup. See:
iOS: How to back up
- Restore to factory settings/new iOS device.
If still problem make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
Apple Retail Store - Genius Bar
Maybe you are looking for
-
Slow SQL Apply on Logical Standby Database in Oracle10g
Hi, We are using Oracle 10g Logical Standby database in our production farm but whenever there is bulk data load (5-6 GB data) on the primary database, the logical standby seems to be hung. It takes days to apply the 5-6 GB data on the logical standb
-
Update Lion and TV doesn't work
Hi, I have an Imac 24" (Core Duo 2009) and connected with TV (Sony Bravia 40"). When I update OSX Lion, the TV doesnt work. Lions detects the TV displays fine with all resolutions, but doesnt send the image. Sorry form mi english Thanks Igor
-
How to get the list of deployed projects in OSB through commond line
How to get the list of deployed projects in OSB through commond line; as we are able to get in weblogic.
-
Primavera P6 Enterprise Project Portfolio Management performanance issue.
Hi, How to improve Primavera P6 Enterprise Project Portfolio Management performanace? OS= RHEL 5.5 DB= 11.2.0.2 RHEL 5.5 Application Version=P6 R8 No issue noticed at database end. Can someone point documention on EPPM ? Thanks
-
Hi all i am new in Oracle.I had installed Oracle 10g on windows ...can any one explain how to do database level patching (step by step)..its urgent. Thanks in advance.