Regarding explain plan
hi all,
i am using database 10g.
i have explain as below
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
PLAN_TABLE_OUTPUT
Plan hash value: 2715695103
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
| 0 | SELECT STATEMENT | | 8 | 568 | 6 (17)| 00:00:
01 |
| 1 | HASH UNIQUE | | 8 | 568 | 6 (17)| 00:00:
01 |
| 2 | NESTED LOOPS | | 8 | 568 | 5 (0)| 00:00:
01 |
|* 3 | TABLE ACCESS FULL | COMMON_PURCHASE_HEADER | 8 | 232 | 3 (0)| 00:00:
PLAN_TABLE_OUTPUT
01 |
| 4 | TABLE ACCESS BY INDEX ROWID| CUSTOMER_MASTER | 1 | 42 | 1 (0)| 00:00:
01 |
|* 5 | INDEX UNIQUE SCAN | CUM_PK | 1 | | 0 (0)| 00:00:
01 |
----how we can analyse the query based on this plan.
Thanks..
What do you think an execution plan is? I think you think that this tells you all by itself how "good" the query is. No that's wrong. You can compare it with the advise a GPS system gives you to go from A to B. Some GPS system give better advices than others, some even know the current traffic situation. But, without any knowledge about the location you are in, you have to trust that plan.
But, if you live in that area, you might know that another path might me faster than the suggested one,etc.
All ORACLE tells you with this execution plan, is that it will read table COMMON_PURCHASE_HEADER completely and will join CUSTOMER_MASTER in a nested loop over the PK index.
WE do now know a lot about your DB, if there are other indexes (e.g. on C_STATUS) and what the cardinality on it is. If there would be an index, and the value A would just occur once, an INDEX lookup might be faster if you would have MUCH moire data!
On 8 rows....as the optimizer believes all data is on the same block and is read by 1 IO and that's the fastest access.
So, basically you need to learn what ORACLE tries to do.
Then you ask yourself, as you know the DB, if that's a clever idea.
If it's not, ask yourself why ORACLE does not agree with you. It might still be right. So test your access methods with hints, and you will see and learn.
As I said it's like the advice a GPS system gives you. Only a local can really tell you how clever that suggestion is. (And the local can be wrong) ;-)
Similar Messages
-
Hi,
I have a query regarding explain plan. While we gather the statistics then optimize choose the best possible plan out of the explain plans available. If we do not gather statistics on a table for a long time then which plan it choose:
If it will continue to use the same plan as it use in the starting when statistics were gathered or will change the plan as soon as dml activities performed and statistics getting old.
Thanks
GKHi,
Aman.... wrote:
Gulshan wrote:
Hi,
I have a query regarding explain plan. While we gather the statistics then optimize choose the best possible plan out of the explain plans available. If we do not gather statistics on a table for a long time then which plan it choose:The same plan which it has chosen in the starting with the previous statistics. The plan won't change automatically as long as you won't refresh the statistics. This is wrong even for Oracle 9i. Here are couple of examples when a plan might change with the same optimizer statistics:
* when you have a histogram on a column and are not a bright person to use bind variables, you might get a completely different execution plan because of a different incoming value. All that is needed to fall into this habit - a soft parse, which might be due to different reasons, for instance, due to session parameter modification (which also might change a plan even without a histogram)
* Starting with 10g, CBO makes adjustments to cardinality estimates for out of range values appeared in predicates -
General queries regarding explain plan and query
Hello Oracle buddies,
I have few badly formed queries with plenty of nested loops, merge join cartesian , plenty of sorting and in the query so many sub queries and all.. The cost of the queries are high like anything.
some even has 130Crore of cost .
When I got the chance to look into those quries I test them in Non Prod systems and which almost have 90-95% similar data as it was refresh by PROD few weeks back.
I found few queries are having the same explain plan but cost is less like anything. for example 5000 or 6000.
When I check for the possibilities of wrong statistics I found they just collect with default setting...
In Non prod I saw only the auto stat job is ran and most of the tables are having the stats which are of last analyzed on the day of refresh.
Now what could be so differentiating factor that drives a queries' cost lesser than Prod systems, when the data is almost same. Also if prod ssystem is gather by only gather_schema_stat('SCHEMA_NAME') then it should carry the same stat in non prod while refreshing. I know ppl do not gather stat on test only auto job is running ...
I need to have clear prove before I can have a clear understanding..
Please help me to know what factors could be differentiating?
-Regards,
J_DBA_Souravj_DBA_sourav wrote:
Hello Jonathan,
Thanks for the reply. The team refreshed it, by expdp/impdp method where by default statistics are included. In that case?
Is this problem probable to happen due to statistics only or anything else is also responsible. Even the explain plan is same.
Please through some light on it.
Auto job is on as I stated earlier but in test systems most of the tables are showing refreshed date as last_analyzed
-Regards
JDS
Anything that puts the stats out of sync with each other may be sufficient to cause problems. Any queries that depend on sysdate may cause a problem.
As a simple check: select table_name, last_analyzed from user_tables on the two systems, with some order by clause (e.g. table_name), and see how many tables were analysed at different times - anything on either system after the exp/imp could be part of your problem.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
Now on Twitter: @jloracle -
Query Regarding Explain Plan on Query
Hello,
I have one big query which shows report of 50000 daily records from @ 20,00,000 records.
I have two databases UAT and PROD.when i do Explain Plan on the query is these different database i get the different plan where everything is same in both database.
In UAT it is doing Index scan where as in PROD it is doing Full TableScan. Below are the results.
In production it is not using any of the indexes present but in UAT it is.What could be the reasong behind this?Sure.
UAT Explain Plan (Please copy in Textpad for better View)
SELECT STATEMENT, GOAL = HINT: ALL_ROWS Cost=371 Cardinality=238 Optimizer=HINT: ALL_ROWS Bytes=134470
VIEW Object owner=SWNET1 Cost=371 Cardinality=238 Bytes=134470
COUNT STOPKEY
VIEW Object owner=SWNET1 Cost=371 Cardinality=238 Bytes=131376
SORT ORDER BY STOPKEY Cost=371 Cardinality=238 Bytes=54026
FILTER
HASH JOIN RIGHT ANTI Cost=370 Cardinality=238 Bytes=54026
INLIST ITERATOR
TABLE ACCESS BY INDEX ROWID Object owner=SWNET1 Object name=IS_TB_END_POINT Cost=1 Cardinality=1 Optimizer=ANALYZED Bytes=31
INDEX RANGE SCAN Object owner=SWNET1 Object name=IS_UK_EP_NAME Cost=1 Cardinality=1 Optimizer=ANALYZED
TABLE ACCESS BY INDEX ROWID Object owner=SWNET1 Object name=IS_TB_TRANSACTION Cost=368 Cardinality=253 Optimizer=ANALYZED Bytes=49588
INDEX FULL SCAN Object owner=SWNET1 Object name=IS_IX_T_DESTINATION_EP Cost=18 Cardinality=13909 Optimizer=ANALYZED
PRODUCTION Explain Plan
SELECT STATEMENT, GOAL = HINT: ALL_ROWS Cost=65702 Cardinality=1000 Optimizer=HINT: ALL_ROWS Bytes=565000
VIEW Object owner=SWNET1 Cost=65702 Cardinality=1000 Bytes=565000
COUNT STOPKEY
VIEW Object owner=SWNET1 Cost=65702 Cardinality=38739 Bytes=21383928
SORT ORDER BY STOPKEY Cost=65702 Cardinality=38739 Bytes=9646011
FILTER
HASH JOIN RIGHT ANTI Cost=63616 Cardinality=38739 Bytes=9646011
INLIST ITERATOR
TABLE ACCESS BY INDEX ROWID Object owner=SWNET1 Object name=IS_TB_END_POINT Cost=1 Cardinality=2 Optimizer=ANALYZED Bytes=64
INDEX UNIQUE SCAN Object owner=SWNET1 Object name=IS_UK_EP_NAME Cost=1 Cardinality=2 Optimizer=ANALYZED
TABLE ACCESS FULL Object owner=SWNET1 Object name=IS_TB_TRANSACTION Cost=63614 Cardinality=44697 Optimizer=ANALYZED Bytes=9699249
Index Query (Same on both places)
create index IS_IX_T_DESTINATION_EP on IS_TB_TRANSACTION (T_DESTINATION_EP)
tablespace IS_XML_IND
pctfree 10
initrans 2
maxtrans 255
storage
initial 128M
next 128K
minextents 1
maxextents unlimited
pctincrease 0
); -
How i can obtain explain plan without run the query
Hello,
i need to know the result of explain of a query without run the query, it's this possible?
Thanks and best regards.explain plan for <your query>;
select * from table(dbms_xplan.display);Regards,
Rob. -
Will a explain plan consider a function in a select statement.
Hi gurus,
I have a question regarding explain plan.
I ran a query, which returns me explain plan with multiple CPU costs around 300K.
now i use a function, and the number of lines displayed in explain plan reduces from 12 to 8 lines.
What i dont understand is.. Is the explain plan considering the function in the select statement ?
ex.
explain plan for
select column1,
column2,
function(value1)
from case
where case_no = 1will a explain plan consider the functions in a select statement ?
Thank you.What i dont understand is.. Is the explain plan considering the function in the select statement ?Maybe there are tweaks which reveal more information from the explain plan, but a straightforward way won't necessarily expose any function call:
SQL> create or replace function get_dname (i_deptno integer)
return varchar2
as
l_dname dept.dname%type;
begin
select dname
into l_dname
from dept
where deptno = i_deptno;
return l_dname;
end get_dname;
Function created.
SQL> explain plan
for
select ename, deptno, get_dname (deptno) dname
from emp
where deptno = 10
Explain complete.
SQL> select * from table (dbms_xplan.display ())
PLAN_TABLE_OUTPUT
Plan hash value: 3956160932
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5 | 45 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP | 5 | 45 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("DEPTNO"=10)
13 rows selected.
SQL> truncate table plan_table
Table truncated.
SQL> explain plan
for
select ename, deptno
from emp
where deptno = 10
Explain complete.
SQL> select * from table (dbms_xplan.display ())
PLAN_TABLE_OUTPUT
Plan hash value: 3956160932
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5 | 45 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| EMP | 5 | 45 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("DEPTNO"=10)
13 rows selected. -
Query regarding Partition table Explain plan
Hello,
We are amidst a tuning activity, wherein a large table has been partitioned for better administration. During testing, I was analyzing the explain plans for long running sql's and found a piece that I was unable to understand. The PSTART and PSTOP columns show ROWID as its value, which in normal partition pruning scenario be the Partition number or the KEY. I tried to look around for this issue but did not get enough information. Can anybody help me of what it means? Also, if there is a good explanation of the same, it will be extremely helpful.
The snippet from explain plan looks like:
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
7 | TABLE ACCESS BY GLOBAL INDEX ROWID| XXXXXXXXXXXXXXXXXXXX | 43874 | 9083K| | 1386 (1)| 00:00:17 | ROWID | ROWID |
On another similar query it looks like:
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 6 | TABLE ACCESS BY GLOBAL INDEX ROWID| XXXXXXXXXXXXXX | 22455 | 4648K| | 456 (1)| 00:00:06 | 9 | 9 |
I have another query with regards to the Partition tables. Does it, require/benefit if, the Indexes to be in partitioned mode? I tried to read about it but did not get a conclusive evidence. I am trying to test it and post here the outcome, but if anybody has experience of working with it, it would be great to have some advice.
Oracle Version:- 10.2.0.4
Regards,
Purvesh.Hi Purvesh.
Great explanation and example on this this topic...
Ask Tom &quot;explain plan on range-partitioned table&quot;
Hope this help. -
Question regarding using of Explain Plan
Hi. I'm new with Oracle Queries so I have a little obstacles about understanding. I want to learn how to use Explain Plan feature from Oracle
I am using Oracle 9i as back end .
Please tell me how can i use feature of Explain Plan Feature for the below query.
SELECT * FROM emp WHERE empno = 7369
Thanks in advance.[email protected] wrote:
Hi. I'm new with Oracle Queries so I have a little obstacles about understanding. I want to learn how to use Explain Plan feature from Oracle
I am using Oracle 9i as back end .
Please tell me how can i use feature of Explain Plan Feature for the below query.
SELECT * FROM emp WHERE empno = 7369
Kiran,
Firstly , before anything else, I would suggest to change your handle to anything else and remove the email id from it. Its not good to have the id displayed in any public forum.
About the question, unfortunately, its not that easy to answer. To understand explain plan and how to use it, you need to understand that algorithm/mechanism, whatever you feel like saying, that generates it. Because, explain plan is just the outcome of that mechanism, a final product, its the result of some inputs given by you in the form of your query, predicates, joins and their types and that all bring up the explain plan. Explain plan is basically the constitution of some steps which are used /fixed by optimizer to run the query. I would suggest that you read this page from cover to cover to understand some of the steps and their meanings which are shown to you in the plan. I am giving 10g link as this is a more better version of optimizer than the previous ones and I would suggest you to do experiments on 10g only.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#i21299
And I would suggest that you collect these following books and start reading them. I haven't yet found any thing better than these books.
[Cost Based Oracle Fundamentals (Jonathan Lewis)|http://www.amazon.com/Cost-Based-Oracle-Fundamentals-Experts-Voice/dp/1590596366]
[Troubleshooting Oracle Performance(Christian Antognini )|http://www.amazon.com/Troubleshooting-Oracle-Performance-Christian-Antognini/dp/1590599179/ref=sr_1_1?ie=UTF8&s=books&qid=1240078634&sr=1-1]
[Effectuve Oracle By Design(Tom Kyte)|http://www.amazon.com/Effective-Oracle-Design-Osborne-ORACLE/dp/0072230657/ref=sr_1_1?ie=UTF8&s=books&qid=1240078698&sr=1-1]
It would be real long journey before the mazes of optimizer and explain would be clear so make sure you have patience as well.
HTH
Aman.... -
Query tunning in Oracle using Explain Plan
Adding to my below question: I have now modified the query and the path shownby 'Explain plan' has reduced. The 'Time' column of plan_table is also showing much lesser value. However, some people are suggesting me to consider the time required by the query to execute on Toad. Will it be practical? Please help!!
Hi, I am using Oracle 11g. I need to optimize a Select query(Need to minimize the execution time). I need to know how 'Explain Plan' would help me. I know how to use Explain Plan command. I refer Plan_table table to see the details of the plan. Please guide me regarding which columns of the Plan_table should be considered while modifying the query for optimization. Some people say, 'Time' column should be considered, some say 'Bytes' etc. Some suggest on minimizing the full table scans, while some people say that I should minimize the total no. operations (less no. of rows should be displayed in Plan_table). As per an experienced friend of mine, full table scans should be reduced (for e.g. if there are 5 full table scans in the plan, then try to reduce them to less than 5. ). However, if I consider any full table scan operation in the plan_table, its shows value of 'time' column as only 1 which is very very less. Does this mean the full scan is actually taking very less time?? If yes, then this means full table scans are very fast in my case and no need to work on them. Some articles suggest that plan shown by 'Explain Plan' command is not necessarily followed while executing the query. So what should I look for then? How should I optimize the query and how will I come to know that it's optimized?? Please help!!...
Edited by: 885901 on Sep 20, 2011 2:10 AM885901 wrote:
Hi, I am using Oracle 11g. I need to optimize a Select query(Need to minimize the execution time). I need to know how 'Explain Plan' would help me. I know how to use Explain Plan command. I refer Plan_table table to see the details of the plan. Please guide me regarding which columns of the Plan_table should be considered while modifying the query for optimization. Some people say, 'Time' column should be considered, some say 'Bytes' etc. Some suggest on minimizing the full table scans, while some people say that I should minimize the total no. operations (less no. of rows should be displayed in Plan_table). As per an experienced friend of mine, full table scans should be reduced (for e.g. if there are 5 full table scans in the plan, then try to reduce them to less than 5. ). However, if I consider any full table scan operation in the plan_table, its shows value of 'time' column as only 1 which is very very less. Does this mean the full scan is actually taking very less time?? If yes, then this means full table scans are very fast in my case and no need to work on them. Some articles suggest that plan shown by 'Explain Plan' command is not necessarily followed while executing the query. So what should I look for then? How should I optimize the query and how will I come to know that it's optimized?? Please help!!...how fast is fast enough? -
Problems with explain plan and statement
Hi community,
I have migrated a j2ee application from DB2 to Oracle.
First some facts of our application and database instance:
We are using oracle version 10.2.0.3 and driver version 10.2.0.3. It runs with charset Unicode 3.0 UTF-8.
Our application is using Tomcat as web container and jboss as application server. We are only using prepared statements. So if I talk about statements I always mean prepared statements. Also our application is setting the defaultNChar property to true because every char and varchar field has been created as an nchar and nvarchar.
We have some jsp sites that contains lists with search forms. Everytime I enter a value to the form that returns a filled resultset, the lists are performing great. But everytime I enter a value that returns an empty resultset, the lists are 100 times slower. The jsp sites are running in the tomcat environment and submitting their statements directly to the database. The connections are pooled by dbcp. So what can cause this behaviour??
To anaylze this problem I started logging all statements and filled-in search field values and combinations that are executed by the lists described above. I also developed a standalone helper tool that reads the logged statements, executes them to the database and generates an explain plan for every statement. But now there appears a strange situation. Every statement, that performs really fast within our application, is now executed by the helper tool extremely slow. So I edited some jsp pages within our application to force an explain plan from there (tomcat env). So when I'm executing the same statement I'm getting with the exactly same code two completely different explain plans.
First the statement itself:
select LINVIN.BBASE , INVINNUM , INVINNUMALT , LINVIN.LSUPPLIERNUM , LSUPPLIERNUMEXT , LINVIN.COMPANYCODE , ACCOUNT , INVINTXT , INVINSTS , INVINTYP , INVINDAT , RECEIPTDAT , POSTED , POSTINGDATE , CHECKCOSTCENTER , WORKFLOWIDEXT , INVINREFERENCE , RESPONSIBLEPERS , INVINSUM_V , INVINSUMGROSS_V , VOUCHERNUM , HASPOSITIONS , PROCESSINSTANCEID , FCURISO_V , LSUPPLIER.AADDRLINE1 from LINVIN, LSUPPLIER where LINVIN.BBASE = LSUPPLIER.BBASE and LINVIN.LSUPPLIERNUM = LSUPPLIER.LSUPPLIERNUM and LINVIN.BBASE = ? order by LINVIN.BBASE, INVINDAT DESC
Now the explain plan from our application:
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 101 | 28583 | 55 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 101 | 28583 | 55 (0)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| LINVIN | 93709 | 12M| 25 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | LINV_INVDAT | 101 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| LSUPPLIER | 1 | 148 | 1 (0)| 00:00:01 |
|* 5 | INDEX UNIQUE SCAN | PK_177597 | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - access("LINVIN"."BBASE"=:1)
filter("LINVIN"."BBASE"=:1)
5 - access("LSUPPLIER"."BBASE"=:1 AND "LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
Now the one from the standalone tool:
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 93773 | 25M| | 12898 (1)| 00:02:35 |
| 1 | SORT ORDER BY | | 93773 | 25M| 61M| 12898 (1)| 00:02:35 |
|* 2 | HASH JOIN | | 93773 | 25M| 2592K| 7185 (1)| 00:01:27 |
| 3 | TABLE ACCESS BY INDEX ROWID| LSUPPLIER | 16540 | 2390K| | 332 (0)| 00:00:04 |
|* 4 | INDEX RANGE SCAN | LSUPPLIER_HAS_BASE_FK | 16540 | | | 11 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID| LINVIN | 93709 | 12M| | 6073 (1)| 00:01:13 |
|* 6 | INDEX RANGE SCAN | LINVOICE_BMDT_FK | 93709 | | | 84 (2)| 00:00:02 |
Predicate Information (identified by operation id):
2 - access("LINVIN"."BBASE"="LSUPPLIER"."BBASE" AND "LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
4 - access("LSUPPLIER"."BBASE"=:1)
6 - access("LINVIN"."BBASE"=:1)
The size of the tables are: LINVIN - 383.692 Rows, LSUPPLIER - 115.782 Rows
As you can see the one executed from our application is much faster than the one from the helper tool. So why picks oracle a completely different explain plan for the same statement? An why is a hash join much slower than a nested loop? Because If I'm right a nested loop should only be used when the tables are pretty small..
I also tried to play with some parameters:
I set optimizer_index_caching to 100 and optimizer_index_cost_adj to 30. I also changed optimizer_mode to FIRST_ROWS_100.
I would really appreciated, if somebody can help me with this issue, because I'm really getting more and more distressed...
Thanks in advance,
Tobias
Edited by: tobiwan on Sep 3, 2008 11:49 PM
Edited by: tobiwan on Sep 3, 2008 11:50 PM
Edited by: tobiwan on Sep 4, 2008 12:01 AM
Edited by: tobiwan on Sep 4, 2008 12:02 AM
Edited by: tobiwan on Sep 4, 2008 12:04 AM
Edited by: tobiwan on Sep 4, 2008 12:06 AM
Edited by: tobiwan on Sep 4, 2008 12:06 AM
Edited by: tobiwan on Sep 4, 2008 12:07 AMtobiwan wrote:
Hi again,
Here ist the answer:
The problem, because I got two different explain plans, was that the external tool uses the NLS sesssion parameters coming from the OS which are in my case "de/DE".
Within our application these parameters are changed to "en/US"!! So if I'm calling in my external tool the java function Locale.setDefault(new Locale("en","US")) before connecting to the database the explain plans are finally equal.That might explain why you got two different execution plan, because one plan was obviously able to avoid a SORT ORDER BY operation, whereas the second plan required to run SORT ORDER BY operation, obviously because of the different NLS_SORT settings. An index by default uses the NLS_SORT = 'binary' order whereas ORDER BY obeys the NLS_SORT setting, which probably was set to 'GERMAN' in your "external tool" case. You can check the "NLS_SESSION_PARAMETERS" view to check your current NLS_SORT setting.
For more information regarding this issue, see my blog note I've written about this some time ago:
http://oracle-randolf.blogspot.com/2008/09/getting-first-rows-of-large-sorted.html
Now let me make a guess why you observe the behaviour that it takes so long if your result set is empty:
The plan avoiding the SORT ORDER BY is able to return the first rows of the result set very quickly, but could take quite a while until all rows are processed, since it requires potentially a lot of iterations of the loop until everything has been processed. Your front end probably by default only display the first n rows of the result set and therefore works fine with this execution plan.
Now if the result set is empty, depending on your data, indexes and search criteria, Oracle has to work through all the data using the inefficient NESTED LOOP approach only to find out that no data has been found, and since your application attempts to fetch the first n records, but no records will be found, it has to wait until all data has been processed.
You can try to reproduce this by deliberately fetching all records of a query that returns data and that uses the NESTED LOOP approach... It probably takes as long as in the case when no records are found.
Note that you seem to use bind variables and 10g, therefore you might be interested that due to the "bind variable peeking" functionality you might potentially end up with "unstable" plans depending on the values "peeked" when the statement is parsed.
For more information, see this comprehensive description of the issue:
http://www.pythian.com/blogs/867/stabilize-oracle-10gs-bind-peeking-behaviour-by-cutting-histograms
Note that this changes in 11g with the introduction of the "Adaptive Cursor Sharing".
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/ -
Cpu time is not getting displayed in explain plan
Hi All,
I am trying to analyze one query using explain plan .like below
1) explain plan for
SELECT /*+ parallel(tsp,8) use_hash( tsp tp) */ count(1)
FROM router tp,
receiver tsp
WHERE tp.rs = tsp.rp
AND creater_date >=to_date('04032009000000','ddmmyyyyhh24miss')
and tsp.XVF is not null
and tp.XVF is not null
and tp.role_name='BR';
2)@$ORACLE_HOME/rdbms/admin/utlxpls.sql
But i am getting only following columns in result .
| Id | Operation | Name | Rows | Bytes | Cost |
No Cpu time preset .
How can i extimate CPU time ?
Pls help
Thanksam_73798 wrote:
I am trying to analyze one query using explain plan .like below
But i am getting only following columns in result .
| Id | Operation | Name | Rows | Bytes | Cost |
No Cpu time preset .
How can i extimate CPU time ?You need to mention your database version (4-digits, e.g. 9.2.0.8).
In Oracle 9i CPU costing is disabled by default, you need to gather WORKLOAD system statistics to enable the CPU costing.
In 10g CPU costing is enabled by default and uses default NOWORKLOAD system statistics if no WORKLOAD system statistics have been gathered. It can only be disabled by setting an undocumented parameter or by changing the OPTIMIZER_FEATURES_ENABLE parameter back to 9i compatibility.
You can check the status of your system statistics by running the following query in SQL*Plus:
column sname format a20
column pname format a20
column pval2 format a20
select
sname
, pname
, pval1
, pval2
from
sys.aux_stats$;Can you show us the actual (complete) output you get from "utlxpls.sql"? Use the \ tag to preserve formatting here:
\output
\will show asoutput
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/ -
Filter(NULL IS NOT NULL) in Explain Plan ??
Hi All,
Can someone please explain what this explain plan statement means? I see a filter(NULL IS NOT NULL) as the first statement - could not figure out why it came up so from googling.
My Query Used:
EXPLAIN PLAN FOR
MERGE INTO summary_bysrccd
USING
(SELECT LAST_DAY(TRUNC(to_timestamp(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS SUMMARY_DATE,
os.acctnum,
ol.sourcecode AS sourcecode,
ol.sourcename AS sourcename,
count(1) cnt_articleview
FROM article_views os , master_sourcecode ol
where os.sourcecode = ol.sourcecode
AND os.acctnum IS NOT NULL
AND ol.sourcecode IS NOT NULL
AND os.requestdatetime IS NOT NULL
AND UPPER(os.success_ind) = 'S'
AND (
('INCR' = 'FULL'
AND (get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('23-AUG-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('27-AUG-2011 23:59:59','DD-MON-YYYY HH24:MI:SS')
AND os.entry_CreatedDate BETWEEN TO_DATE('22-AUG-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('28-AUG-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
OR ('INCR' = 'FULL'
AND os.entry_createddate BETWEEN TO_DATE('23-AUG-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('27-AUG-2011 23:59:59','DD-MON-YYYY HH24:MI:SS') )
group by LAST_DAY(TRUNC(to_timestamp(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))),
os.acctnum,ol.sourcecode,ol.sourcename) mrg_query
ON (ods_av_summary_bysrccd.acctnum = mrg_query.acctnum AND
ods_av_summary_bysrccd.summary_date=mrg_query.summary_date AND
ods_av_summary_bysrccd.sourcecode=mrg_query.sourcecode)
WHEN NOT MATCHED THEN
INSERT (SUMMARY_date,ACCTNUM,SOURCECODE,SOURCENAME,CNT_ARTICLEVIEW,ENTRY_LASTUPDATEDDATE)
VALUES(mrg_query.summary_date,mrg_query.acctnum,mrg_query.sourcecode,mrg_query.sourcename,
mrg_query.cnt_articleview,sysdate)
WHEN MATCHED THEN
UPDATE SET ods_av_summary_bysrccd.cnt_articleview=
CASE WHEN NVL('INCR','INCR') = 'FULL' THEN mrg_query.cnt_articleview
ELSE ods_av_summary_bysrccd.cnt_articleview+mrg_query.cnt_articleview
END,
ods_av_summary_bysrccd.entry_lastupdateddate=sysdate;My Explain Plan:
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 268591246
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 0 | MERGE STATEMENT | | 1 | 456 | | 3 (0)| 00:00:01 | | |
| 1 | MERGE | ODS_AV_SUMMARY_BYSRCCD | | | | | | | |
| 2 | VIEW | | | | | | | | |
| 3 | NESTED LOOPS OUTER | | 1 | 417 | | 3 (0)| 00:00:01 | | |
| 4 | VIEW | | 1 | 360 | | 5 (100)| 00:00:01 | | |
| 5 | SORT GROUP BY | | 1 | 73 | 595M| | | | |
PLAN_TABLE_OUTPUT
|* 6 | FILTER | | | | | | | | |
|* 7 | HASH JOIN | | 6975K| 485M| 3944K| 17594 (1)| 00:03:32 | | |
| 8 | TABLE ACCESS FULL | ODS_MASTER_SOURCECODE | 84021 | 2953K| | 273 (1)| 00:00:04 | | |
|* 9 | TABLE ACCESS BY GLOBAL INDEX ROWID| ODS_ARTICLE_VIEWS | 7007K| 247M| | 826 (0)| 00:00:10 | 33 | 33 |
|* 10 | INDEX FULL SCAN | IDX_AV_ACCTNUM | 25M| | | 26 (0)| 00:00:01 | | |
| 11 | TABLE ACCESS BY GLOBAL INDEX ROWID | ODS_AV_SUMMARY_BYSRCCD | 1 | 57 | | 3 (0)| 00:00:01 | ROWID | ROWID |
|* 12 | INDEX UNIQUE SCAN | ODS_AV_SUMMARY_BYSRCCD_PK | 1 | | | 2 (0)| 00:00:01 | | |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
6 - filter(NULL IS NOT NULL)
7 - access("OS"."SOURCECODE"="OL"."SOURCECODE")
9 - filter("OS"."REQUESTDATETIME" IS NOT NULL AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-08-23 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-08-27 23:59:59', 'syyyy-mm-dd hh24:mi:ss') AND UPPER("OS"."SUCCESS_IND")='S')
10 - filter("OS"."ACCTNUM" IS NOT NULL)
12 - access("ODS_AV_SUMMARY_BYSRCCD"."SUMMARY_DATE"(+)=INTERNAL_FUNCTION("MRG_QUERY"."SUMMARY_DATE") AND
"ODS_AV_SUMMARY_BYSRCCD"."ACCTNUM"(+)="MRG_QUERY"."ACCTNUM" AND "ODS_AV_SUMMARY_BYSRCCD"."SOURCECODE"(+)="MRG_QUERY"."SOURCECODE")
Note
PLAN_TABLE_OUTPUT
- dynamic sampling used for this statementHi Toon,
Thanks for the quick resolution. I went back and verified the table's colunm details and it has a NOT NULL constraint.
Regards,
Chaitanya
P.S: Is it ok if I ask you for some help regarding a production issue I have been encountering since 15 days but haev no clear resolution yet about what/why is the reason (the said issue is neither uniform nor regular - its affecting some modules and happening on some days - i shall give the full details if you are willing to have a look) - i shall start a new post or email you directly - yur convenience. -
How to change the explain plan for currently running query?
Hi All,
I am using Oracle enterprise 9i edition. I have a query which frames dynamically and running in the database. I noticed a table with 31147758 rows
in the query which has no indexes and taking more time to process. I tried to create an INdex on that table. I know the query is already running with a FULL table scan. Is it possible to change the explain plan for the current running query to consider the INDEX?
[code]
SELECT /*+ USE_HASH (c,e,b,a) */
d.att_fcc extrt_prod_dim_id,
d.att_fcc compr_prod_dim_id,
a.glbl_uniq_id glbl_uniq_id,
to_date(c.dit_code,'RRRRMMDD')STRT_DT,
(to_date(c.dit_code,'RRRRMMDD')+150)END_DT,
a.pat_nbr pat_id,
a.rxer_id rxer_id,
e.rxer_geog_id rxer_geog_id,
a.pharmy_id pharmy_id,
a.pscr_pack_id pscr_pack_id,
a.dspnsd_pack_id dspnsd_pack_id,
DENSE_RANK () OVER (PARTITION BY a.pat_nbr ORDER BY c.dit_code) daterank,
COUNT( DISTINCT d.att_fcc ) OVER (PARTITION BY a.pat_nbr, c.dit_code) event_cnt
DENSE_RANK () OVER (PARTITION BY a.pat_nbr,
d.att_fcc
ORDER BY c.dit_code) prodrank,
DENSE_RANK () OVER (PARTITION BY a.pat_nbr,
d.att_fcc
ORDER BY c.dit_code DESC) stoprank
FROM
pd_dimitems c,
pd_pack_attribs d ,
lrx_tmp_rxer_geog e,
lrx_tmp_pat_daterank p,
lrx_tmp_valid_fact_link a
WHERE c.dit_id = a.tm_id
AND e.rxer_id = a.rxer_id
AND a.glbl_uniq_id = p.glbl_uniq_id
AND p.daterank > 1
AND a.pscr_pack_id = d.att_dit_id
[/code]
The table lrx_tmp_pat_daterank is having that 31147758 rows. So I am wondering how to make the query to use the newly created index on the table?Why do you think using Indexes will improve the performance of the query? How many rows this query is returning? Optimizer might chose a Full table scan when it finds out that Index plan might not be useful. Why are you using /*+ USE_HASH (c,e,b,a) */ hint? This Hint will force oracle to use Full table scan instead of using the index. Try removing it and see if the plan changes.
Regards, -
What is the significance of "cost" column in explain plan
Hi,
Can anyone explain what is the meaning of the values which we get in the cost column in the explain plan..For Ex : Cost : 4500 . What does this value mean...and is it measured in which form of units...i mean seconds,nanoseconds etckingfisher,
Ok one more link for you but I shall quote the text also here,
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#i82005
The cost is an estimated value proportional to the expected resource use needed to execute the statement with a particular plan. The optimizer calculates the cost of access paths and join orders based on the estimated computer resources, which includes I/O, CPU, and memory.
And few paragraphs down,
13.4.1.3.3 Cost
The cost represents units of work or resource used. The query optimizer uses disk I/O, CPU usage, and memory usage as units of work. So, the cost used by the query optimizer represents an estimate of the number of disk I/Os and the amount of CPU and memory used in performing an operation. The operation can be scanning a table, accessing rows from a table by using an index, joining two tables together, or sorting a row set. The cost of a query plan is the number of work units that are expected to be incurred when the query is executed and its result produced.
The access path determines the number of units of work required to get data from a base table. The access path can be a table scan, a fast full index scan, or an index scan. During table scan or fast full index scan, multiple blocks are read from the disk in a single I/O operation. Therefore, the cost of a table scan or a fast full index scan depends on the number of blocks to be scanned and the multiblock read count value. The cost of an index scan depends on the levels in the B-tree, the number of index leaf blocks to be scanned, and the number of rows to be fetched using the rowid in the index keys. The cost of fetching rows using rowids depends on the index clustering factor. See "Assessing I/O for Blocks, not Rows".
The join cost represents the combination of the individual access costs of the two row sets being joined, plus the cost of the join operation.
Now I guess if you read this part, it should be pretty clear what cost is.Cost is an evlaution of the resource that is estimated by Oracle for every step incurred in the uery execution.There are no of steps and each may involve doing IO,consuming CPU and/or using memory.Cost is a factor which oracle uses combining all of these 3 (depending on the version) together to propose the work done or expected to be done in exeuting a query.So this actualy should represent the time spent exactly on each and every step.That's what the objective frm cost is.But at the moment,this is not there.There amy be a situation that cost is shown as very high but query is working fine.There are woraround which can bring the cost down for example using and tweaking optimizer_index_cost_adj parameter , we can propose oracle regarding our indexes and it may pick up lesser cost evaluation.What is mentioned is that this model is becoming more and more mature and in the next releases, we may see that cost is representing exactly the time that we would spend inthe query.At the moment,its not there.So as Chris mentioned,Tuning for low cost only is not a good way.
I suggest you grab a copy of JL's book.He has explained it much better in his book.
Hope I said some thing useful.
Aman.... -
Explain Plan in SQL Developer vs. SQLPlus
Hi everyone,
I've got a quick question. Why would an explain plan hang in SQL Developer but come back immediately in SQL Plus?
For example, in SQL developer, I write my statement and use the F6 command to bring up the explain plan and it just hangs and hangs. It looks like it's trying to generate an explain plan, but it's been running for hours now.
When I log into SQL Plus, I do a
SQL> explain plan for <query>:
SQL> select * from table(dbms_xplan.display);That whole process takes less than a minute to get the explain plan.
Is there something fundamentally different being executed by SQL Developer?
Thanks!
-JoeJoe,
F6 in SQL Developer runs an AutoTrace, which actually runs the SQL and also displays timings and the explain plan. If you only want the explain plan, use F10.
Regards,
Bob
Maybe you are looking for
-
How many mails i can send at a time per day using APEX mail system?
HI, I am working on application, when i have written a process to send mail, i have a project where i have to send mail at a time for all the email id's given list there are upto 5000 email id's where text body also include certain set of data from a
-
Logic 7.1.1 won't let me record audio!
Installed Logic Pro 7 as upgrade to Logic Express. After initial install, I was able to record one audio track. Also, wanted to get my external midi modules to play back through audio track. After switching the audio driver back and forth between Bui
-
Multi select checkboxes in oim
I have a data field on application resource form.It has 10 values out of which user can select multiple values. But it has to be selected through checkbox. Example: System Level Access(field name)- with a search box. So when the search is hit, the 10
-
Capitvate in Oil & gas industry?
Anyone have any expamples of capitvate being used in oil and gas industries? Boilers? Pipelines? was wondering if this would be good for training as I am new to captivate and have not used it yet. Our company is thinking about using this in conjuctio
-
HI All, I want to configure Adobe Document Services (ADS). So when I check the connection by accessiin path. T.Code -->SA38 --> Report Name is FP_TEST_00 --> Execute --> Press on Print Preview Button, I am getting following error. ADS: SOAP Runtime E