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.
Similar Messages
-
How to pass parameter in Function by using select statement?
Hi,
I got a problem. I cant pass in parameter to function by using select statement. But it can pass in parameter by using 'hardcode' method. How can I solve this problem?
Eg,
select * from table (SplitFunction('HS750020,HS750021')) <<< this work.
but
select * from table (SplitFunction(select LOT_NO from TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) <<< do not work.
Thanks for who try to help. Thanks.skymonster84 wrote:
I have try this before. But it not work.here is an example
create or replace type stringlist as table of varchar2(100)
create or replace function splitstring(pstring in varchar2) return stringlist
as
lstringlist stringlist;
begin
select regexp_substr(pstring,'[^,]+',1, level) bulk collect into lstringlist
from dual
connect by level <= length(pstring)-length(replace(pstring,','))+1;
return lstringlist;
end;
select * from table(select splitstring('xx,yy,zz') from dual)
create table t(str varchar2(100))
insert into t values('x,y,z')
insert into t values('a,b,c')
select * from table(select splitstring(str) from t where rownum<2)
/If you supply multiple values then it will fail.
select * from table(select splitstring(str) from t)
/ -
Limitations in using a function within a select statement
I have a function which retrieves various data elements from the
database and formats it accordingly. The data (varchar2)
returned could be in excess of 2,000 characters length.
I need to use the returned data as part of a view. I am able to
use the function in a "select" statement, but when I use it with
returned data in excess of 2,000 chars, I get the following
error:
ORA-06502: PL/SQL: numeric or value error
This error is occurring whenever the returned data is in excess
of 2,000 characters.
Is there an alternative method to what I am proposing, I have
tried alternative data types but if I am able to use it in a
"select" statement, I get the above error when the returned
length exceeds 2,000 chars.
Thanks
Peterare u using oracle 7. varchar2 limit in 8 is 4000.
-
Can call a function in the select statement?
Is there any ways to call a function in the select statement?
what I like to do is this:
select deptno, totalEmployees(deptno), TotalSalary(deptno)
from emp;
I know it can be done by count(*) and join tables, but my case
is much more complex and the where clauses are different from
one function to another, and have many tables to join and many
combinations
ThanksFunctions can be used in a select statement subject to certain
restrictions, see
http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/
server.817/a85397/statem9b.htm#2062024
It's under "CREATE FUNCTION> Keywords and Parameters> function>
Restrictions on User-Defined Functions"
Here is an except...
When a function is called from within a query or DML statement,
the function cannot:
a) Have OUT or IN OUT parameters
b) Commit or roll back the current transaction, create or roll
back to a savepoint, or alter the session or the system. DDL
statements implicitly commit the current transaction, so a user-
defined function cannot execute any DDL statements.
c) Write to the database, if the function is being called from a
SELECT statement. However, a function called from a subquery in
a DML statement can write to the database.
d) Write to the same table that is being modified by the
statement from which the function is called, if the function is
called from a DML statement.
Except for the restriction on OUT and IN OUT parameters, Oracle
enforces these restrictions not only for the function called
directly from the SQL statement, but also for any functions that
function calls, and on any functions called from the SQL
statements executed by that function or any function it calls. -
Return multiple values from a function to a SELECT statement
I hope I've provided enough information here. If not, just let me know what I'm missing.
I am creating a view that will combine information from a few tables. Most of it is fairly straightforward, but there are a couple of columns in the view that I need to get by running a function within a package. Even this is fairly straightforward (I have a function named action_date in a package called rp, for instance, which I can use to return the date I need via SELECT rp.action_date(sequence_number).
Here's the issue: I actually need to return several bits of information from the same record (not just action_date, but also action_office, action_value, etc.) - a join of the tables won't work here as I'll explain below. I can, of course, run a separate function for each statement but that is obviously inefficient. Within the confines of the view select statement however, I'm not sure how to return each of the values I need.
For instance, right now, I have:
Table1:
sequence_number NUMBER(10),
name VARCHAR(30),
Table2:
Table1_seq NUMBER(10),
action_seq NUMBER(10),
action_date DATE,
action_office VARCHAR(3),
action_value VARCHAR(60),
I can't simply join Table1 and Table2 because I have to do some processing in order to determine which of the matching returned rows I actually need to select. So the package opens a cursor and processes each row until it finds the one that I need.
The following works but is inefficient since all of the calls to the package will return columns from the same record. I just don't know how to return all the values I need into the SELECT statement.
CREATE VIEW all_this_stuff AS
SELECT sequence_number, name,
rp.action_date(sequence_number) action_date,
rp.action_office(sequence_number) action_office,
rp.action_value(sequence_number) action_value
FROM table1
Is there a way to return multiple values into my SELECT statement or am I going about this all wrong?
Any suggestions?
Thanks so much!Hi,
What you want is a Top-N Query , which you can do using the analytic ROW_NUMBER function in a sub-query, like this:
WITH got_rnum AS
SELECT action_seq, action_dt, action_office, action_type, action_value
, ROW_NUMBER () OVER ( ORDER BY action_date
, action_seq
, action_serial
) AS rnum
FROM table2
WHERE action_code = 'AB'
AND action_office LIKE 'E' -- Is this right?
SELECT action_seq, action_dt, action_office, action_type, action_value
FROM got_rnum
WHERE rnum = 1
;As written, this will return (at most) one row.
I suspect you'll really want to get one row for each group , where a group is defined by some value in a table to which you're joining.
In that case, add a PARTITION BY clause to the ROW_NUMBER function.
If you'd post a little sample data (CREATE TABLE and INSERT statements), I could show you exactly how.
Since I don't have your tables, I'll show you using tables in the scott schema.
Here's a view that has data from the scott.dept table and also from scott.emp, but only for the most senior employee in each department (that is, the employee with the earliest hiredate). If there happens to be a tie for the earliest hiredate, then the contender with the lowest empno is chosen.
CREATE OR REPLACE VIEW senior_emp
AS
WITH got_rnum AS
SELECT d.deptno
, d.dname
, e.empno
, e.ename
, e.hiredate
, ROW_NUMBER () OVER ( PARTITION BY d.deptno
ORDER BY e.hiredate
, e.empno
) AS rnum
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
SELECT deptno
, dname
, empno
, ename
, hiredate
FROM got_rnum
WHERE rnum = 1
SELECT *
FROM senior_emp
;Output:
. DEPTNO DNAME EMPNO ENAME HIREDATE
10 ACCOUNTING 7782 CLARK 09-JUN-81
20 RESEARCH 7369 SMITH 17-DEC-80
30 SALES 7499 ALLEN 20-FEB-81
By the way, one of the conditions in the query you posted was
action_office LIKE 'E'which is equivalent to
action_office = 'E'(LIKE is always equivalent to = if the string after LIKE doesn't contain any wildcards.)
Did you mean to say that, or did you mean something like this:
action_office LIKE 'E%'instead? -
How to get the value from a function using a select statement
I have a function(user defined not built in) that returns multiple values(like an array). My question is how do i get those values in a select statement. when i tried to retrieve it,
select pack.my_members from dual;
i am getting an error
ORA-00902: invalid datatype
I am sure this must be a syntax error with the select statement
The following is the function that give the array of data
package pack
package spec
Type my_table is table of varchar2(25);
function the_members
return pack.my_table;
pakcage body
function the_members return pack.my_table
Remarks: This function returns a table containing names of the
members
is
tm pack.my_table:= pack.my_table('first member','second member','third member','fourth member');
begin
return tm;
end the_members;Check this example on Pipelinedfunction
-
How to pass an array to a function from a SELECT statement
Hi all. I have a problem with passing an array to a function directly from a SELECT statement.
Here is what I want. If I have a function
function AAA(arrayVar <ArrayType>) return number;
I want to be able to call this function this way
select AAA((2,3,4))
from dual
or this way
select AAA((10,12))
from dual
In other words I want to be able to pass an arbitrary number of numbers to the function. And I want this to work in a SELECT statement.
Does anyone have any ideas how to implement this? What <ArrayType> should I use?(I've read about VARRAY, nested tables in the Oracle documentation but as far as I've understood these array types are meant to be used within PL/SQL blocks).
I found only this http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:208012348074 through Google but it didn't help me.
Thank you in advance.> What <ArrayType> should I use?
SQL data types - as 3360 showed above. You cannot use PL/SQL structures and user types in the SQL Engine.
You can however use all SQL structures and types in PL/SQL.
Arrays in SQL is created as collection type - basic o-o. The collection type (or class) serve as a container for instantiated objects or scalar type.
This is covered in detail in [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14260/toc.htm]
Oracle® Database Application Developer's Guide - Object-Relational Features -
Calling a user defined function in a select statement
PLS-00231: function 'F_GET_PROJECT_ID' may not be used in SQL
I am caling a user defined function 'F_GET_PROJECT_ID' in a select statement and getting the above error .
Can any one help me to resolve it.
I can not replace the function with a local variable nor can I assign the output of the function to a variable and use the variable in the sql stmt. cos, the in put parameters of the function comes from the same select statement.
Please help
Thanks in advanceCan you provide your function code? Using a function like that is possible from the below example. I suspect something in your function code.
SQL> create or replace function sample_func(p_sal number)
2 return number
3 is
4 v_sal number;
5 begin
6 v_sal := p_sal+100;
7 return v_sal;
8 end;
9 /
Function created.
SQL>
SQL> select empno, ename, sal, sample_func(sal)
2 from emp
3 /
EMPNO ENAME SAL SAMPLE_FUNC(SAL)
7839 KING 5000 5100
7698 BLAKE 2850 2950
7782 CLARK 2450 2550
7566 JONES 2975 3075
7654 MARTIN 1250 1350
7499 ALLEN 1600 1700
7844 TURNER 1500 1600
7900 JAMES 950 1050
7521 WARD 1250 1350
7902 FORD 3000 3100
7369 SMITH 800 900
7788 SCOTT 3000 3100
7876 ADAMS 1100 1200
7934 MILLER 1300 1400
14 rows selected.
SQL>And yeah... your formatted code is this.
cursor c1 is
SELECT t.upi_nbr upi_nbr,
f_get_project_id(l.pay_type_code,
l.charge_type_nme,
l.charge_code) project_id,
LAST_DAY(TO_DATE(SUBSTR(t.Year_Month, 5, 2)||'/'||'01'||'/'||SUBSTR(t.Year_Month,1,4),
'MM/DD/YYYY'))reporting_period_end_date,
SUM (c.hours_worked_qty) reported_hrs
from trs.trs_timesheet@oraprod5 T,
trs.trs_line@oraprod5 L,
trs.trs_cell@oraprod5 C
where T.upi_nbr=L.upi_nbr
and T.year_month=L.year_month
and L.row_nbr=C.row_nbr
and L.upi_nbr=C.upi_nbr
and L.year_month = C.year_month
and L.invalid_activity_ind = 'V'
and rtrim(L.charge_code) is not null
AND L.Pay_Type_Code<>'REQ'
and C.Hours_Worked_Qty > 0
GROUP BY t.upi_nbr,
t.year_month,
t.oui_nbr,
l.charge_code,
l.activity_detail_code,
l.charge_type_nme,
l.pay_type_code;Cheers
Sarma. -
SQL query - how to get parameters into a function within a SELECT statement
Hi,
I have SQL query roughly as follows
SELECT A, B, C, MAX(CASE...) AS "D_NAME", FunctionX(B, C, "D_NAME")
FROM...
WHERE...
How to get alias "D_NAME" as a valid parameter into FunctionX?Hi,
user8819407 wrote:
Hi,
I have SQL query roughly as follows
SELECT A, B, C, MAX(CASE...) AS "D_NAME", FunctionX(B, C, "D_NAME")
FROM...
WHERE...
How to get alias "D_NAME" as a valid parameter into FunctionX?Either
(1) repeat the calculation or
(2) compute it in a sub-query
Here's an example of (2)
WITH got_d_name AS
SELECT A, B, C, MAX(CASE...) AS "D_NAME"
FROM...
WHERE...
SELECT A, B, C, D_NAME, FunctionX (B, C, D_NAME)
FROM got_d_name
;A column alias (like d_name) can be referenced in the ORDER BY clause of the query where it was defined, but that's the only place in that query where it can be referenced. -
Why the explain plan incorrent?
I have a sql in oracle10.2.03:
select *
from (select a.*
from t_user a, t_message b
where b.user_id = a.row_id and a.user_type = 1
order by b.happen_time desc)
where rownum <= 5
there are indexes on column a.user_type,b.user_id,b.happen_time, and has been analyzed. a.user_type=1 only have 1/1000 records
the explain plan is below:
cost Cardinary Bytes
SELECT STATEMENT, GOAL = ALL_ROWS 30 5 3790
COUNT STOPKEY
VIEW BMTEST 30 6 4548
NESTED LOOPS 30 6 1158
TABLE ACCESS BY INDEX ROWID BMTEST T_MESSAGE 13 1524118 24385888
INDEX FULL SCAN DESCENDING BMTEST IDX_MESSAGE_2 1 168
TABLE ACCESS BY INDEX ROWID BMTEST T_USER 1 1 177
INDEX UNIQUE SCAN BMTEST PK_USER 1 1
Oracle use the index full scan descending on the happen_time. the cost only has 30.
After I add hint on the sql on the user_id of t_message
select *
from (select /*+index (b idx_message_1)*/ a.*
from t_user a, t_message b
where b.user_id = a.row_id and a.user_type = 1
order by b.happen_time desc)
where rownum <= 5
the explain plan change to:
cost Cardinary Bytes
SELECT STATEMENT, GOAL = ALL_ROWS 5020 5 3790
COUNT STOPKEY
VIEW BMTEST 5020 54707 41467906
SORT ORDER BY STOPKEY 5020 54707 10558451
TABLE ACCESS BY INDEX ROWID BMTEST T_MESSAGE 26 515 8240
NESTED LOOPS 2707 54707 10558451
TABLE ACCESS BY INDEX ROWID BMTEST T_USER 1 106 18762
INDEX RANGE SCAN BMTEST IDX_USER_2 1 106
INDEX RANGE SCAN BMTEST IDX_MESSAGE_1 1 515
INDEX UNIQUE SCAN BMTEST PK_USER 1 1
The cost is 5020, but the execute usage time only is 100ms, and the first SQL does not add hint usage 20s.
Why the lower cost waste more time, if the cost caculate is incorrect?
Edited by: [email protected] on Sep 11, 2008 9:14 PM[email protected] wrote:
But i am afraid i use a misunderstand title for this post,my doubt is why oracle get a large cost with the sql execute few time but get a small cost with the sql execute long time.The cost of a query isn't a particularly good proxy for runtime. It is perfectly reasonable for a query with a cost of 1000 to run more quickly than a query with a cost of 100. The cost of queries is only directly comparable between different plans in the same 10053 trace file.
[email protected] wrote:
All the indexed columns are both analyzed by the command or by DBMS_STATS package and the cpu costing is enabled.But what order are the commands being run? And why is the ANALYZE command being used to gather optimizer stats.
In the first plan:
INDEX FULL SCAN DESCENDING BMTEST IDX_MESSAGE_2 1 168
Why this index full scan cost only 1? how did oracle get this number? Is there formula to caculate the cost of index full scan? I have read the article named "Cost Based Oracle Fundamentals" and there is no introduce how to caculate it.
I think this abnormality cost makes the cost of next step "NESTED LOOPS" very smal and finally lead this abnormality result.1) Which article are you talking about? Are you talking about Jonathan Lewis's book "Cost Based Oracle Fundamentals"? Or are you referring to a different article somewhere?
2) Can you post the query plans formatted via DBMS_XPLAN.DISPLAY (including the predicate information and enclose the output in the \[pre\] and \[pre\] tags to preserve white space?
Justin
Justin -
Explain plan on Update statement in function
All,
I have an update statement in a function and my explain plan shows:
"Optimizer" "Cost" "Cardinality" "Bytes"
"UPDATE STATEMENT" "ALL_ROWS" "2" "1" "7"
"UPDATE user.<table_name>" "" "" "" ""
"INDEX(UNIQUE SCAN) <table_name>.<PK_column_cons>" "ANALYZED" "1" "1" "7"
Filtering is on index unique column, but cost is 1 what does that mean?
do i need to change my update statement in function?
Any ideas?
Regards,
~ORAThe cost is the optimizer's measure of how much effort it will take to execute the statement. For any statement the optimizer will evaluate a number of execution plans and choose the one with the lowest cost. I wouldn't worry too much about what it actually "means". However if you want to understand this subject in a lot more detail I would recommend the book Cost-Based Oracle Fundamentals by Jonathan Lewis.
For your update statement the optimizer has chosen to access a single row by the primary key index, which is probably good enough, so you should not need to change it.
The only faster way to access the data would be to use the row's ROWID directly. You would need to have fetched this explicitly in a previous SELECT statement, or you could use it implicitly with the WHERE CURRENT OF syntax for a cursor opened with FOR UPDATE. -
Hi,
For getting the explain plan for a query, we use the statement
"explain plan for " + Query
Similarly, to get an explain plan for a procedure, do we have any way like
"explain plan for " + "Execute " + Procedure
How do we get an explain plan for a procedure that is executed
Thanks in Advance.teckfreak wrote:
Hi Robert,
I am working on an utility application which will execute the procedure and show the explain plan to the user for him to analyze the explain plan and take necessary steps for optimization. I am showing the Procedure inputs to the user, allowing him to enter values and taking them and executing the procedure. I am setting the trace and extracting the explain plan for the procedure using TKPROF utility and showing it to the user.
While doing so, the trace file is stored in udump folder. I am accessing the trace file from TKPROF utility. I am able to run the TKPROF from the command prompt. But if I try automating the TKPROF command in a .NET application using Process.Start, it says "Not able to access the file.". I tried giving full permissions to Everyone and it still throws the error. Kindly guide me how to proceed.. A different approach that you might want to consider (as indicated by William):
- Flush the shared pool and use a unique MODULE description for each execution of your procedure (e.g. using DBMS_APPLICATION_INFO.SET_MODULE), e.g. using a logon trigger
- Query V$SQL for your unique MODULE description and run DBMS_XPLAN.DISPLAY_CURSOR for each corresponding child cursor found (SQL_ID + CHILD_NUMBER) in the shared pool. This plan generation could be automated using a procedure
The result of this approach corresponds to the tracing using TKPROF since it will provide the actual execution plans used at runtime rather than separate EXPLAIN PLAN results which might differ from the actual plans.
This assumes that your shared pool is sufficiently large to hold all the child cursor created by your procedure without aging them out while the procedure is running. It's probably also only applicable to an environment where not too much work is being done while running this test and the recommended flushing of the shared pool.
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. -
Explain Plan from TKPROF trace file.
Hello,
My procedure is taking time for that i have trace on in procedure fo find explain plan of particular query.
Using below statement Trace is on.
EXECUTE IMMEDIATE 'ALTER SESSION SET SQL_TRACE = TRUE';
EXECUTE IMMEDIATE 'ALTER SESSION SET TIMED_STATISTICS = TRUE';Now for getting expalin plan from TKPROF i have used below statement but for some query i have found explain paln and some case i cant found explain plan.
tkprof mf_ora_23773.trc mf_ora_23773.txt explain =abc/abc
can u please help me to analyze where i m wrong?
Thanks.First of all, you should best avoid using the explain= clause on the tkprof command line.
This will run explain plan on the statement in the trace file, and that explain plan can even be wrong, as there is no information on datatypes in the trace file.
The real explain plan data is flushed to the trace file, when the program issues commit or rollback. Oracle always issues an implicit commit when the program disconnects, so when you run the program to completion you should have explain plan output in your trace files.
You won't get explain plan output if you don't have access to the objects in the SQL statement. Also recursive SQL won't produce explain plan result.
One would need to see part of your trace file to verify your assertion the explain clause doesn't always work.
Sybrand Bakker
Senior Oracle DBA -
Explain plan for Query performance
Hi Gurus,
I need to improve the performance of a procedure. The procedure has the below QUery. I dont have Idea on how to imrpove the perf by seeing the explain plan. Can anyone please help me to explain where I need to change the code.
The below are the code and Explain plan for the same.
-----------Code----------------------------
SELECT IV_STORECODE AS STORECODE,
TO_CHAR(RD.ITEMCODE) AS ITEMCODE,
C.ITEMCATEGORYNAME,
ISUB.ITEMSUBCATEGORY1NAME
FROM RECEIPTS R
INNER JOIN RECEIPTDETAILS RD
ON R.RECEIPTID = RD.RECEIPTID
INNER JOIN ITEMCOMPANY IC
ON IC.ITEMCODE = RD.ITEMCODE
INNER JOIN ITEMCATEGORY C
ON IC.ITEMCATEGORY = C.ITEMCATEGORYID
LEFT OUTER JOIN ITEMSUBCATEGORY1 ISUB
ON ISUB.ITEMSUBCATEGORY1ID = IC.ITEMSUBCATEGORY1
AND ISUB.ITEMSUBCATEGORY1ID IN
(SELECT ITEMSUBCATEGORY1ID
FROM ITEMSUBCATEGORY1
WHERE ITEMCATEGORYID = IV_ITEMCATEGORY)
INNER JOIN STORE SE
ON SE.STORECODE = R.STORECODE
WHERE R.STORECODE = IV_STORECODE
AND SE.HOSPITALID = IV_HOSPITALID
AND TRUNC(R.CREATEDDATE) BETWEEN V_FROMDATE AND
V_TODATE
AND R.STATUSID NOT IN (99, 5)
AND
(IV_DRUGTYPE IS NULL OR
IC.DRUGTYPECATEGORYID = IV_DRUGTYPE)
UNION
SELECT IV_STORECODE AS STORECODE,
TO_CHAR(STD.ITEMCODE) AS ITEMCODE,
C.ITEMCATEGORYNAME,
ISUB.ITEMSUBCATEGORY1NAME
FROM STOCKTRANSACTION ST
INNER JOIN STOCKTRANSACTIONDETAILS STD
ON ST.STOCKTRANSACTIONID = STD.STOCKTRANSACTIONID
INNER JOIN ITEMCOMPANY IC
ON IC.ITEMCODE = STD.ITEMCODE
INNER JOIN ITEMCATEGORY C
ON IC.ITEMCATEGORY = C.ITEMCATEGORYID
LEFT OUTER JOIN ITEMSUBCATEGORY1 ISUB
ON ISUB.ITEMSUBCATEGORY1ID = IC.ITEMSUBCATEGORY1
AND ISUB.ITEMSUBCATEGORY1ID IN
(SELECT ITEMSUBCATEGORY1ID
FROM ITEMSUBCATEGORY1
WHERE ITEMCATEGORYID = IV_ITEMCATEGORY)
INNER JOIN STORE SE
ON SE.STORECODE = ST.STORECODE
WHERE ST.STORECODE = IV_STORECODE
AND SE.HOSPITALID = IV_HOSPITALID
AND TRUNC(ST.CREATEDDATE) BETWEEN V_FROMDATE AND
V_TODATE
AND ST.STATUS <> 99
AND STD.ITEMCODE NOT LIKE '%#%'
AND
(IV_DRUGTYPE IS NULL OR
IC.DRUGTYPECATEGORYID = IV_DRUGTYPE)
UNION
SELECT D.STORECODE,
TO_CHAR(D.ITEMCODE) AS ITEMCODE,
C.ITEMCATEGORYNAME,
ISUB.ITEMSUBCATEGORY1NAME
FROM DAILYINVENTORY D
INNER JOIN ITEMCOMPANY IC
ON IC.ITEMCODE = D.ITEMCODE
INNER JOIN ITEMCATEGORY C
ON IC.ITEMCATEGORY = C.ITEMCATEGORYID
LEFT OUTER JOIN ITEMSUBCATEGORY1 ISUB
ON ISUB.ITEMSUBCATEGORY1ID = IC.ITEMSUBCATEGORY1
AND ISUB.ITEMSUBCATEGORY1ID IN
(SELECT ITEMSUBCATEGORY1ID
FROM ITEMSUBCATEGORY1
WHERE ITEMCATEGORYID = IV_ITEMCATEGORY)
INNER JOIN STORE SE
ON SE.STORECODE = D.STORECODE
WHERE D.STORECODE = IV_STORECODE
AND SE.HOSPITALID = IV_HOSPITALID
AND TRUNC(D.UPDATEDDATE) <= V_TODATE
AND D.QTY > 0
AND D.ITEMCODE NOT LIKE '%#%'
AND C.ITEMCATEGORYID = IV_ITEMCATEGORY
AND (IV_DRUGTYPE IS NULL OR
IC.DRUGTYPECATEGORYID = IV_DRUGTYPE)
AND (IV_SUBITEMCATEGORY IS NULL OR
ISUB.ITEMSUBCATEGORY1ID = IV_SUBITEMCATEGORY) Will post the explain plan ..
Thanks in advance..Ensure you also include all the other information people will need to help you, e.g. database version, table structures/relationships and cardinalities, row counts etc.
See the two threads linked to in the FAQ: {message:id=9360003}
Maybe you are looking for
-
Error 500 when trying to access Admingui in Sun Application Server 8.2
Hello there I�m evaluating Sun Communication Suite 5, and one of the components installaed is the Sun JAS 8.2. When i try to access the admin console on the port 4849, it shows me the login page, and when i insert the username and pass the server ans
-
How to get oriental instrument in logic pro 9
I have Logic Pro 9 on Mac mini I want to use arabic instrument like oud, Nay etc... How can I get it?
-
iPhoto won't load photos while attempting to open program. I loaded about 150 pics today from Koday EasyShare program. I also had a "iPhoto crash" today while attempting to share these photos. Since then, I've loaded iLife 05 and upgraded iPhoto, but
-
Has anyone ever used this combination and if so, any advice would be greatly appreciated. Mac mini Mac OS X (10.4)
-
LWAP PoE settings when using power injector
We have 3500 series access points connected to a 5508 WLC. What power over ethernet option should I select for an AP thats using a power injector? Prestandard State or Power Injector State?