performance issue [message #322421] |
Fri, 23 May 2008 08:18 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
manoj12
Messages: 210 Registered: March 2008 Location: India
|
Senior Member |
|
|
Dear Sir
This query is taking a long time to execute
Please check the query and the below is the explain plan mentioned to it
select to_char(stmtdt, 'yyyy') as ID, to_char(stmtdt, 'yyyy') as year
from statement
where borrid= &var_borrId and user_id= &var_user_id and coaid = &var_mdlid
and to_char(stmtdt, 'yyyy') in
(
select os.year from
(
select borrid, year, count(*) as cntActuals
from subjective_prm_trans
where borrid= &var_borrId and user_id= &var_user_id and mdlid = &var_mdlid and endnodeflag = 'E'
group by year, borrid
) os,
(
select j.borrid, j.year, j.cntVariable + k.cntFixed as cntMdlTotals
from
(
select a.borrid, a.year , count(*) as cntVariable
from subjective_prm_trans a, mdl_Parameter_Tree m
where
a.prmid = m.parentid and a.mdlid = m.mdlid and
a.endnodeflag = 'N' and a.value between 0.0001 and 1 and
a.prmid not in (select r.prmid from mdl_parameter_tree r where trim(lower(r.prmname)) = 'project risk' and r.mdlid= &var_mdlid ) and
a.borrid= &var_borrId and a.mdlid= &var_mdlid and a.user_id= &var_user_id
group by a.borrid , a.year
) j,
(
select count(*) as cntFixed
from mdl_parameter_tree u
where u.prmid not in
(
select t.prmid
from mdl_parameter_tree t
where t.rootnode in
(
select b.rootnode
from subjective_prm_trans a, mdl_parameter_tree b
where
a.mdlid = b.mdlid and a.prmid = b.prmid and
a.endnodeflag = 'N' and a.value between 0.0001 and 1 and
a.prmid not in (select r.prmid from mdl_parameter_tree r where trim(lower(r.prmname)) = 'project risk' and r.mdlid= &var_mdlid ) and
a.borrid= &var_borrId and a.mdlid= &var_mdlid and a.user_id= &var_user_id
) and
t.endnodeflag = 'E' and parametertype = 'S' and mdlid= &var_mdlid
) and
u.endnodeflag ='E' and
u.parametertype = 'S' and
u.mdlid= &var_mdlid
) k
) om
where
os.borrid = om.borrid and
os.year = om.year and
os.cntActuals = om.cntMdlTotals
)
order by year desc
Below is the explain plan for the query
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=28 Card=1 Bytes=61
)
1 0 SORT (ORDER BY) (Cost=28 Card=1 Bytes=61)
2 1 HASH JOIN (SEMI) (Cost=26 Card=1 Bytes=61)
3 2 TABLE ACCESS (FULL) OF 'STATEMENT' (Cost=2 Card=1 Byte
s=48)
4 2 VIEW OF 'VW_NSO_1' (Cost=23 Card=1 Bytes=13)
5 4 NESTED LOOPS (Cost=23 Card=1 Bytes=91)
6 5 HASH JOIN (Cost=13 Card=1 Bytes=78)
7 6 VIEW (Cost=4 Card=1 Bytes=39)
8 7 SORT (GROUP BY) (Cost=4 Card=1 Bytes=55)
9 8 TABLE ACCESS (FULL) OF 'SUBJECTIVE_PRM_TRANS
' (Cost=2 Card=1 Bytes=55)
10 6 VIEW (Cost=9 Card=1 Bytes=39)
11 10 SORT (GROUP BY) (Cost=7 Card=1 Bytes=107)
12 11 FILTER
13 12 HASH JOIN (Cost=5 Card=1 Bytes=107)
14 13 TABLE ACCESS (FULL) OF 'SUBJECTIVE_PRM_T
RANS' (Cost=2 Card=1 Bytes=81)
15 13 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TR
EE' (Cost=2 Card=142 Bytes=3692)
16 12 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TREE
' (Cost=2 Card=1 Bytes=155)
17 5 VIEW
18 17 SORT (AGGREGATE)
19 18 FILTER
20 19 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TREE'
(Cost=2 Card=1 Bytes=284)
21 19 FILTER
22 21 NESTED LOOPS (Cost=6 Card=1 Bytes=636)
23 22 MERGE JOIN (CARTESIAN) (Cost=4 Card=1 By
tes=481)
24 23 TABLE ACCESS (FULL) OF 'SUBJECTIVE_PRM
_TRANS' (Cost=2 Card=1 Bytes=68)
25 23 BUFFER (SORT) (Cost=2 Card=1 Bytes=413
)
26 25 TABLE ACCESS (FULL) OF 'MDL_PARAMETE
R_TREE' (Cost=2 Card=1 Bytes=413)
27 22 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TR
EE' (Cost=2 Card=18 Bytes=2790)
28 21 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TREE
' (Cost=2 Card=1 Bytes=155)
Statistics
----------------------------------------------------------
18 recursive calls
0 db block gets
387229 consistent gets
306954 physical reads
0 redo size
432 bytes sent via SQL*Net to client
584 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
114 sorts (memory)
0 sorts (disk)
1 rows processed
Any help would help to resolve the issue
|
|
|
|
|
|
|
|
|
|
|
|
Re: performance issue [message #322740 is a reply to message #322732] |
Mon, 26 May 2008 02:19 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
manoj12
Messages: 210 Registered: March 2008 Location: India
|
Senior Member |
|
|
Dear Sir
I have not send you any unformatted messages sir.This is what the problem actually I am facing.And I would ask for your help to tune the below query.
Regards
|
|
|
|
Re: performance issue [message #322756 is a reply to message #322744] |
Mon, 26 May 2008 02:47 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
manoj12
Messages: 210 Registered: March 2008 Location: India
|
Senior Member |
|
|
Dear Sir
I have understood sir
Do you wanted me to format the code now
select to_char(stmtdt, 'yyyy') as ID, to_char(stmtdt, 'yyyy') as year
from statement
where borrid= &var_borrId and user_id= &var_user_id and coaid = &var_mdlid
and to_char(stmtdt, 'yyyy') in
(
select os.year from
(
select borrid, year, count(*) as cntActuals
from subjective_prm_trans
where borrid= &var_borrId and user_id= &var_user_id and mdlid = &var_mdlid and endnodeflag = 'E'
group by year, borrid
) os,
(
select j.borrid, j.year, j.cntVariable + k.cntFixed as cntMdlTotals
from
(
select a.borrid, a.year , count(*) as cntVariable
from subjective_prm_trans a, mdl_Parameter_Tree m
where
a.prmid = m.parentid and a.mdlid = m.mdlid and
a.endnodeflag = 'N' and a.value between 0.0001 and 1 and
a.prmid not in (select r.prmid from mdl_parameter_tree r where trim(lower(r.prmname)) = 'project risk' and r.mdlid= &var_mdlid ) and
a.borrid= &var_borrId and a.mdlid= &var_mdlid and a.user_id= &var_user_id
group by a.borrid , a.year
) j,
(
select count(*) as cntFixed
from mdl_parameter_tree u
where u.prmid not in
(
select t.prmid
from mdl_parameter_tree t
where t.rootnode in
(
select b.rootnode
from subjective_prm_trans a, mdl_parameter_tree b
where
a.mdlid = b.mdlid and a.prmid = b.prmid and
a.endnodeflag = 'N' and a.value between 0.0001 and 1 and
a.prmid not in (select r.prmid from mdl_parameter_tree r where trim(lower(r.prmname)) = 'project risk' and r.mdlid= &var_mdlid ) and
a.borrid= &var_borrId and a.mdlid= &var_mdlid and a.user_id= &var_user_id
) and
t.endnodeflag = 'E' and parametertype = 'S' and mdlid= &var_mdlid
) and
u.endnodeflag ='E' and
u.parametertype = 'S' and
u.mdlid= &var_mdlid
) k
) om
where
os.borrid = om.borrid and
os.year = om.year and
os.cntActuals = om.cntMdlTotals
)
order by year desc
Well Sir I have decided to create a function based index on the stmtdt column in the statement table since I can see from above explain plan.The query is taking 28.781 seconds to return only one row as well as the query is reading is 694183 data blocks (306954 physical reads
and 387229 consistent gets) to return ONE row -- that's a bit
excessive, I think.
I Think I should create a materialised view sir based on the various subqueries I am using. A materialized view
may be better than the in-line views as an MV can be indexed.
This is what my overall suggestion is all about sir.Sorry for the incovinience caused.
Well This is the above explain plan sir
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=28 Card=1 Bytes=61
)
1 0 SORT (ORDER BY) (Cost=28 Card=1 Bytes=61)
2 1 HASH JOIN (SEMI) (Cost=26 Card=1 Bytes=61)
3 2 TABLE ACCESS (FULL) OF 'STATEMENT' (Cost=2 Card=1 Bytes=48)
4 2 VIEW OF 'VW_NSO_1' (Cost=23 Card=1 Bytes=13)
5 4 NESTED LOOPS (Cost=23 Card=1 Bytes=91)
6 5 HASH JOIN (Cost=13 Card=1 Bytes=78)
7 6 VIEW (Cost=4 Card=1 Bytes=39)
8 7 SORT (GROUP BY) (Cost=4 Card=1 Bytes=55)
9 8 TABLE ACCESS (FULL) OF 'SUBJECTIVE_PRM_TRANS' (Cost=2 Card=1 Bytes=55)
10 6 VIEW (Cost=9 Card=1 Bytes=39)
11 10 SORT (GROUP BY) (Cost=7 Card=1 Bytes=107)
12 11 FILTER
13 12 HASH JOIN (Cost=5 Card=1 Bytes=107)
14 13 TABLE ACCESS (FULL) OF 'SUBJECTIVE_PRM_TRANS' (Cost=2 Card=1 Bytes=81)
15 13 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TREE' (Cost=2 Card=142 Bytes=3692)
16 12 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TREE' (Cost=2 Card=1 Bytes=155)
17 5 VIEW
18 17 SORT (AGGREGATE)
19 18 FILTER
20 19 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TREE'
(Cost=2 Card=1 Bytes=284)
21 19 FILTER
22 21 NESTED LOOPS (Cost=6 Card=1 Bytes=636)
23 22 MERGE JOIN (CARTESIAN) (Cost=4 Card=1 By
tes=481)
24 23 TABLE ACCESS (FULL) OF 'SUBJECTIVE_PRM
_TRANS' (Cost=2 Card=1 Bytes=68)
25 23 BUFFER (SORT) (Cost=2 Card=1 Bytes=413)
26 25 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TREE' (Cost=2 Card=1 Bytes=413)
27 22 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TREE' (Cost=2 Card=18 Bytes=2790)
28 21 TABLE ACCESS (FULL) OF 'MDL_PARAMETER_TREE' (Cost=2 Card=1 Bytes=155)
Statistics
----------------------------------------------------------
18 recursive calls
0 db block gets
387229 consistent gets
306954 physical reads
0 redo size
432 bytes sent via SQL*Net to client
584 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
114 sorts (memory)
0 sorts (disk)
1 rows processed
Is the above suggestion correct sir.If I am wrong do correct me
Regards
[Updated on: Mon, 26 May 2008 02:48] Report message to a moderator
|
|
|
Re: performance issue [message #322790 is a reply to message #322756] |
Mon, 26 May 2008 04:31 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
manoj12
Messages: 210 Registered: March 2008 Location: India
|
Senior Member |
|
|
Dear Sir
Well I think the message is in the formatted way.I would like to hear from your sir.Can you please tell me your suggestion so that I can get the correct answer.I am extremely sorry for posting the message in the unformatted way.
Thanks and
regards
|
|
|
|
|
|
Re: performance issue [message #322827 is a reply to message #322813] |
Mon, 26 May 2008 06:25 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
manoj12
Messages: 210 Registered: March 2008 Location: India
|
Senior Member |
|
|
Dear Sir
I got the below output in the formatted way now sir.Could you please check and tell whether the suugesstion is correct or not
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 61 |
| 1 | SORT ORDER BY | | 1 | 61 |
| 2 | HASH JOIN SEMI | | 1 | 61 |
| 3 | TABLE ACCESS FULL | STATEMENT | 1 | 48 |
| 4 | VIEW | VW_NSO_1 | 1 | 13 |
| 5 | NESTED LOOPS | | 1 | 91 |
| 6 | HASH JOIN | | 1 | 78 |
| 7 | VIEW | | 1 | 39 |
| 8 | SORT GROUP BY | | 1 | 55 |
| 9 | TABLE ACCESS FULL | SUBJECTIVE_PRM_TRANS | 1 | 55 |
| 10 | VIEW | | 1 | 39 |
| 11 | SORT GROUP BY | | 1 | 107 |
| 12 | FILTER | | | |
| 13 | HASH JOIN | | 1 | 107 |
| 14 | TABLE ACCESS FULL | SUBJECTIVE_PRM_TRANS | 1 | 81 |
| 15 | TABLE ACCESS FULL | MDL_PARAMETER_TREE | 142 | 3692 |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| 16 | TABLE ACCESS FULL | MDL_PARAMETER_TREE | 1 | 155 |
| 17 | VIEW | | 1 | 13 |
| 18 | SORT AGGREGATE | | 1 | 284 |
| 19 | FILTER | | | |
| 20 | TABLE ACCESS FULL | MDL_PARAMETER_TREE | 1 | 284 |
| 21 | FILTER | | | |
| 22 | NESTED LOOPS | | 1 | 636 |
| 23 | MERGE JOIN CARTESIAN| | 1 | 481 |
| 24 | TABLE ACCESS FULL | SUBJECTIVE_PRM_TRANS | 1 | 68 |
| 25 | BUFFER SORT | | 1 | 413 |
| 26 | TABLE ACCESS FULL | MDL_PARAMETER_TREE | 1 | 413 |
| 27 | TABLE ACCESS FULL | MDL_PARAMETER_TREE | 12 | 1860 |
| 28 | TABLE ACCESS FULL | MDL_PARAMETER_TREE | 1 | 155 |
--------------------------------------------------------------------------------
Note: cpu costing is off, 'PLAN_TABLE' is old version
36 rows selected
[Updated on: Mon, 26 May 2008 07:43] Report message to a moderator
|
|
|
|
Re: performance issue [message #322979 is a reply to message #322879] |
Tue, 27 May 2008 00:07 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
manoj12
Messages: 210 Registered: March 2008 Location: India
|
Senior Member |
|
|
Dear Sir
Quote: |
As well I have suggested to create a materialized view and index that view as the materialized view can be index whereas the inline view cannot be index.
Also There are some basic problems that I found in the query and the explain plan that should be fixed
* There are no indexes used in the query, which may be part or most of the performance problem - verify that indexes exist and statistics are gathered for those indexes.
* The cardinality numbers are low (possibily indicating that it has been a while since statistics were gathered) - make certain that statistics are gathered with DBMS_STATS.
* There is a merge join Cartesian in the plan which can severely hurt performance with large numbers of rows - we may need a hint to fix this.
* The formatting of the plan without spaces makes it impossible
to see how the data was retrieved by the plan.
|
This is what I have suggested so far sir.Is the above suggestion correct?
Regards
[Updated on: Tue, 27 May 2008 01:10] by Moderator Report message to a moderator
|
|
|
|
Re: performance issue [message #323129 is a reply to message #322999] |
Tue, 27 May 2008 07:00 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
manoj12
Messages: 210 Registered: March 2008 Location: India
|
Senior Member |
|
|
Dear Sir
I have created a function based index on the STMTDT COLUMN ON THE STATEMENT TABLE.AFTER THAT I HAVE CREATED A MATERIALISED VIEW ON THE INLINE VIEW CREATED.ANY HELP WOULD HELP ME TO RESOLVE THE ISSUE
REGARDS
|
|
|
Re: performance issue [message #323232 is a reply to message #323129] |
Tue, 27 May 2008 18:27 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
In the following subset of the SQL:
select j.borrid, j.year, j.cntVariable + k.cntFixed as cntMdlTotals
from
(
select a.borrid, a.year , count(*) as cntVariable
from subjective_prm_trans a, mdl_Parameter_Tree m
where
a.prmid = m.parentid and a.mdlid = m.mdlid and
a.endnodeflag = 'N' and a.value between 0.0001 and 1 and
a.prmid not in (select r.prmid from mdl_parameter_tree r where trim(lower(r.prmname)) = 'project risk' and r.mdlid= &var_mdlid ) and
a.borrid= &var_borrId and a.mdlid= &var_mdlid and a.user_id= &var_user_id
group by a.borrid , a.year
) j,
(
select count(*) as cntFixed
from mdl_parameter_tree u
where u.prmid not in
(
select t.prmid
from mdl_parameter_tree t
where t.rootnode in
(
select b.rootnode
from subjective_prm_trans a, mdl_parameter_tree b
where
a.mdlid = b.mdlid and a.prmid = b.prmid and
a.endnodeflag = 'N' and a.value between 0.0001 and 1 and
a.prmid not in (select r.prmid from mdl_parameter_tree r where trim(lower(r.prmname)) = 'project risk' and r.mdlid= &var_mdlid ) and
a.borrid= &var_borrId and a.mdlid= &var_mdlid and a.user_id= &var_user_id
) and
t.endnodeflag = 'E' and parametertype = 'S' and mdlid= &var_mdlid
) and
u.endnodeflag ='E' and
u.parametertype = 'S' and
u.mdlid= &var_mdlid
) k
) om
You have inline views J and K in the FROM clause, but you do not have any join criteria (no WHERE clause). So this is like a CARTESIAN PRODUCT.
This is not a great problem because K will return a sinle row (it is a simple COUNT(*)). The thing that IS a problem is that K is being executed for each row returned from J.
Try reversing the order of J and K in the FROM clause (so that K is first) and add an ORDERED hint to stop it from nesting K.
select /*+ORDERED*/ j.borrid, j.year, j.cntVariable + k.cntFixed as cntMdlTotals
from
(...) k, (...) j
Ross Leishman
|
|
|
|