nvl problem i think [message #519152] |
Wed, 10 August 2011 01:34 |
|
shashank_kurasrediffmail
Messages: 63 Registered: July 2011 Location: hyderabad
|
Member |
|
|
hi all ,
I have a problem,help me please
whem am trying to use nvl for one condition it is taking lot of time to execute but when am removing nvl function then the query executing in 2 min
condition is given below
(HOI2.ORG_INFORMATION1)=nvl(TO_CHAR(:p_set_of_books_id) , HOI2.ORG_INFORMATION1)
but when am using the same condition as below the querry executing in 2 min
(HOI2.ORG_INFORMATION1)=TO_CHAR(:p_set_of_books_id)
my querry given below
(SELECT cust.customer_number cust_no, cust.customer_name customer,
cnv.item_no, SUM(wd.shipped_quantity) shp_qty_nos,
0 rtn_qty_nos,
ROUND(SUM(cnv.cnf * wd.shipped_quantity), 3) shp_qty_tons,
0 rtn_qty_tons, 0 net_shp_qty_nos, 0 net_shp_qty_tons
FROM wsh_delivery_details wd,
wsh_delivery_assignments wda,
wsh_new_deliveries wnd,
ra_customers cust,
vis_itm_ctg_cnv_mst cnv,
HR_ORGANIZATION_INFORMATION HOI2,
MTL_PARAMETERS mp,
oe_order_headers_all oh,
qp_list_headers_tl pl
WHERE
oh.header_id = wd.source_header_id
AND oh.sold_to_org_id = WND.customer_id
AND oh.price_list_id = pl.list_header_id(+)
AND oh.ship_from_org_id = HOI2.organization_id
AND oh.ship_from_org_id = mp.organization_id
AND mp.organization_id=mp.organization_id
AND mp.organization_id = wnd.organization_id
AND wd.delivery_detail_id = wda.delivery_detail_id
AND wda.delivery_id = wnd.delivery_id
AND oh.sold_to_org_id = cust.customer_id
AND oh.sold_to_org_id = wd.customer_id
AND cnv.inventory_item_id = wd.inventory_item_id
AND pl.NAME LIKE '%' || :p_brand || '%'
AND (HOI2.ORG_INFORMATION1) =nvl(TO_CHAR(:p_set_of_books_id),HOI2.ORG_INFORMATION1)
AND mp.organization_code BETWEEN NVL(:p_from_org_code,
mp.organization_code)
AND NVL(:p_to_org_code,
mp.organization_code)
AND cust.customer_class_code =
NVL(:p_cust_class_code, cust.customer_class_code)
AND TRUNC(wnd.initial_pickup_date) BETWEEN :p_from_date
AND :p_to_date
AND NVL(wd.shipped_quantity, 0) <> 0
AND wd.source_header_type_id =
NVL(:p_order_type, wd.source_header_type_id)
AND cust.customer_number BETWEEN NVL(:p_from_customer,
cust.customer_number)
AND NVL(:p_to_customer,
cust.customer_number)
AND ( cnv.item_no LIKE 'A-FG%'
OR cnv.item_no LIKE 'B-FG%'
OR cnv.item_no LIKE 'P-FG%')
GROUP BY
ROLLUP(cust.customer_name,
cust.customer_number,
cnv.item_no,
cnv.cnf)
HAVING GROUPING_ID(cust.customer_name,
cust.customer_number,
cnv.item_no,
cnv.cnf)=0
)
CM: Got rid of some unnecessary white space
[Updated on: Wed, 10 August 2011 04:47] by Moderator Report message to a moderator
|
|
|
Re: nvl problem i think [message #519167 is a reply to message #519152] |
Wed, 10 August 2011 03:04 |
cookiemonster
Messages: 13958 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Do you really format your queries like that? The indentation is all over the place - makes it hard to read.
Using nvl like that generally prevents oracle from using an index on the relevant column.
Post explains plans of the query with and without the nvl.
|
|
|
|
|
|
|
Re: nvl problem i think [message #519185 is a reply to message #519180] |
Wed, 10 August 2011 04:30 |
|
shashank_kurasrediffmail
Messages: 63 Registered: July 2011 Location: hyderabad
|
Member |
|
|
and when i use the same condition in other sub querry its working .the querry execting in same amount of time for both conditions ..
(HOI2.ORG_INFORMATION1)=nvl(TO_CHAR(:p_set_of_books_id) , HOI2.ORG_INFORMATION1)
AND (HOI2.ORG_INFORMATION1) =TO_CHAR(:p_set_of_books_id)
so i think its not problem of index
[Updated on: Wed, 10 August 2011 04:33] Report message to a moderator
|
|
|
Re: nvl problem i think [message #519188 is a reply to message #519185] |
Wed, 10 August 2011 04:45 |
cookiemonster
Messages: 13958 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
According to those explain plans the one with the nvl should be faster. So either:
1) your statistics aren't up to date
2) You ran the explain plans on a different DB to the one you're getting the performance problem on.
So you need to fix that.
As for your last post, all that proves is that the sub-query didn't use the index in the first place.
However the query you posted above doesn't contain a sub-query so I'm not sure what you are refering to.
nvl itself is not slow. When it causes a query to slow down it is almost always because it's usage prevents oracle from using an index.
|
|
|
|
Re: nvl problem i think [message #519192 is a reply to message #519191] |
Wed, 10 August 2011 05:10 |
cookiemonster
Messages: 13958 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
And are those executions plans from the DB that has the performance problem or another DB, like say a Development DB?
If I'm reading that plan right there is very little data in the tables.
Also are you sure that the only difference between the 2 queries explained above is the nvl? Because the 1st is doing a lot more table accesses than the second.
|
|
|
|
|
|
Re: nvl problem i think [message #519200 is a reply to message #519198] |
Wed, 10 August 2011 05:26 |
cookiemonster
Messages: 13958 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
And are you having the performance problem on the test DB?
If yes, then it looks like your stats are out of date - regather them for all relevant tables and try again.
If no, run the explain on the DB where you are having the performance problem.
|
|
|
|
|
|
|
|
|
Re: nvl problem i think [message #519214 is a reply to message #519213] |
Wed, 10 August 2011 07:02 |
cookiemonster
Messages: 13958 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
To run procedures in sqplus you need to either wrap them in an anonymous block (BEGIN...code...END) or use exec.
The table name needs to be wrapped in quotes and be in upper case.
|
|
|
|
|
|
|
|
|
Re: nvl problem i think [message #519252 is a reply to message #519246] |
Wed, 10 August 2011 09:26 |
cookiemonster
Messages: 13958 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Not local error, Oracle one, they do sometimes use raise_application_error you know:
SQL> exec dbms_stats.gather_table_stats(user,'made_up_table');
BEGIN dbms_stats.gather_table_stats(user,'made_up_table'); END;
*
ERROR at line 1:
ORA-20000: Unable to analyze TABLE "OPS$GALAGA"."MADE_UP_TABLE", insufficient
privileges or does not exist
ORA-06512: at "SYS.DBMS_STATS", line 13149
ORA-06512: at "SYS.DBMS_STATS", line 13179
ORA-06512: at line 1
|
|
|
Re: nvl problem i think [message #519253 is a reply to message #519246] |
Wed, 10 August 2011 09:30 |
John Watson
Messages: 8960 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Hi - be careful running dbms_stats like that on an EBS database.
You are meant to go through the FND_STATS package. It has certain configured defaults (particularly for histograms, I think) that are supposed to be optimal for EBS.
John.
[update: typo]
[Updated on: Wed, 10 August 2011 09:31] Report message to a moderator
|
|
|
|
|