Home » RDBMS Server » Performance Tuning » need help with rewriting the query (8.0.6)
need help with rewriting the query [message #456174] Sat, 15 May 2010 09:56 Go to next message
ateeqrahman786
Messages: 52
Registered: December 2009
Location: Hyderabad,India
Member
Hi,

i have traced the query and the tkprof result is as follows:


SELECT BUS_UNIT,REQUEST_NO,REQUEST_DATE,REQUEST_TIME,REG_NO,TOP_BRASS_YN,REQUEST_ADMT_THEATRE_FLAG,PT_CODE,PT_NAME,CTYP_CUST_TYPE,CUST_CUSTO MER,PRIORTY
FROM
A_INP_THEATRE_ADMT WHERE bus_unit = :1 and trunc(request_date) >= (trunc(sysdate)-90) order by request_no desc


call count cpu elapsed disk query current rows
------- ------ ---- --------- ----- ------- ------ ------
Parse 1 0.00 0.02 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 7 0.11 0.10 0 36606 0 77
------- ------ -------- ---------- ---------- ---- ----
total 9 0.11 0.12 0 36606 0 77

Misses in library cache during parse: 0
Optimizer goal: CHOOSE
Parsing user id: 675

Rows Row Source Operation
------- ---------------------------------------------------
81 SORT ORDER BY
81 VIEW A_INP_THEATRE_ADMT
81 SORT UNIQUE
81 UNION-ALL
46 NESTED LOOPS
7629 TABLE ACCESS BY INDEX ROWID A_INP_THEATRE_REQUEST
7630 INDEX RANGE SCAN (object id 418783)
59 TABLE ACCESS BY INDEX ROWID A_PT_MASTER
118 INDEX RANGE SCAN (object id 5282)
35 NESTED LOOPS
28279 TABLE ACCESS BY INDEX ROWID A_INP_ADMT_MSSG
28280 INDEX RANGE SCAN (object id 418787)
43 TABLE ACCESS BY INDEX ROWID A_PT_MASTER
86 INDEX RANGE SCAN (object id 5282)

---------------------------------------------

could someone please rewrite the query as "A_INP_THEATRE_ADMT" is a view.Its accessing 36606 rows to fetch just 77 rows.

Regards,
Ateeq

[Updated on: Sat, 15 May 2010 10:00]

Report message to a moderator

Re: need help with rewriting the query [message #456176 is a reply to message #456174] Sat, 15 May 2010 10:22 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Since NOBODY can optimize SQL just by looking at it, we need a few more details.
http://www.orafaq.com/forum/m/433888/136107/#msg_433888
Please refer to URL above & be sure to provide the details requested:
1) DDL for all tables & indexes

[Updated on: Sat, 15 May 2010 10:22]

Report message to a moderator

Re: need help with rewriting the query [message #456204 is a reply to message #456176] Sun, 16 May 2010 00:01 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
SELECT BUS_UNIT,REQUEST_NO,REQUEST_DATE,REQUEST_TIME,REG_NO,TOP_BRASS_YN,REQUEST_ADMT_THEATRE_FLAG,PT_CODE,PT_NAME,CTYP_CUST_TYPE,CUST_CUSTO MER,PRIORTY 
FROM
A_INP_THEATRE_ADMT WHERE bus_unit = :1 and trunc(request_date) >= (trunc(sysdate)-90) order by request_no desc

is functionally identical to
SELECT BUS_UNIT,REQUEST_NO,REQUEST_DATE,REQUEST_TIME,REG_NO,TOP_BRASS_YN,REQUEST_ADMT_THEATRE_FLAG,PT_CODE,PT_NAME,CTYP_CUST_TYPE,CUST_CUSTO MER,PRIORTY 
FROM
A_INP_THEATRE_ADMT WHERE bus_unit = :1 and request_date >= (trunc(sysdate)-90) order by request_no desc

So remove the TRUNC() and maybe allow it touse an index if it exists.

Ross Leishman
Re: need help with rewriting the query [message #456208 is a reply to message #456176] Sun, 16 May 2010 01:17 Go to previous messageGo to next message
ateeqrahman786
Messages: 52
Registered: December 2009
Location: Hyderabad,India
Member
The below script is for the view A_INP_THEATRE_ADMT.
----------------------------------------------------
CREATE OR REPLACE FORCE VIEW ULTGNP.A_INP_THEATRE_ADMT
(BUS_UNIT, REQUEST_NO, REG_NO, REQUEST_DATE, REQUEST_TIME, 
 PT_CODE, CTYP_CUST_TYPE, CUST_CUSTOMER, TOP_BRASS_YN, PT_NAME, 
 PRIORTY, REQUEST_ADMT_THEATRE_FLAG)
AS 
SELECT B.BUS_UNIT,REQUEST_NO,REG_NO,REQUEST_DATE,REQUEST_TIME,
          A.PT_CODE,CTYP_CUST_TYPE,CUST_CUSTOMER,TOP_BRASS_YN,
PT_FIRST_NAME_E||' '||PT_SECOND_NAME_E||' '||PT_LAST_NAME_E  PT_NAME,
DECODE(REQUEST_PRIORTY_FLAG,'N','NORMAL','E','EMERGENCY','N') PRIORTY,
REQUEST_ADMT_THEATRE_FLAG
FROM  A_PT_MASTER A, A_INP_THEATRE_REQUEST B
WHERE A.BUS_UNIT  = B.BUS_UNIT AND
      A.PT_CODE   = B.PT_CODE  AND
      NVL(A.PT_CASH_PRIVATE,'C') NOT IN ('C','P','E') AND
      B.TOP_BRASS_YN  <> 'Y'    AND
      B. REQUEST_STATUS_FLAG = 'O' AND
      NVL(B.ADMIT_STATUS_FLAG,'O') <> 'C'
UNION
SELECT B.BUS_UNIT,REQUEST_NO,REG_NO,REQUEST_DATE,REQUEST_TIME,
       A.PT_CODE,CTYP_CUST_TYPE,CUST_CUSTOMER,TOP_BRASS_YN,
PT_FIRST_NAME_E||' '||PT_SECOND_NAME_E||' '||PT_LAST_NAME_E  PT_NAME,
DECODE(REQUEST_PRIORTY_FLAG,'N','NORMAL','E','EMERGENCY','N') PRIORTY,
REQUEST_ADMT_THEATRE_FLAG
FROM  A_PT_MASTER A, A_INP_ADMT_MSSG B
WHERE A.BUS_UNIT  = B.BUS_UNIT AND
      A.PT_CODE   = B.PT_CODE  AND
      NVL(A.PT_CASH_PRIVATE,'C') NOT IN ('C','P','E') AND
      B.TOP_BRASS_YN  <> 'Y' AND
      B.REQUEST_STATUS_FLAG = 'O' AND
      NVL(B.ADMIT_STATUS_FLAG,'O') <> 'C';


CREATE PUBLIC SYNONYM A_INP_THEATRE_ADMT FOR ULTGNP.A_INP_THEATRE_ADMT;





CM: Added code tags, please do so yourself next time - see the orafaq forum guide if you're not sure how.

[Updated on: Sun, 16 May 2010 03:33] by Moderator

Report message to a moderator

Re: need help with rewriting the query [message #456227 is a reply to message #456208] Sun, 16 May 2010 03:35 Go to previous messageGo to next message
cookiemonster
Messages: 13921
Registered: September 2008
Location: Rainy Manchester
Senior Member
What indexes do you have on the three tables?
Re: need help with rewriting the query [message #456230 is a reply to message #456227] Sun, 16 May 2010 04:04 Go to previous messageGo to next message
ateeqrahman786
Messages: 52
Registered: December 2009
Location: Hyderabad,India
Member
/forum/fa/7812/0/

[Updated on: Sun, 16 May 2010 04:09]

Report message to a moderator

Re: need help with rewriting the query [message #456237 is a reply to message #456230] Sun, 16 May 2010 07:25 Go to previous messageGo to next message
cookiemonster
Messages: 13921
Registered: September 2008
Location: Rainy Manchester
Senior Member
I assume the first set is for A_PT_MASTER.
Next time get the list using sqlplus, then copy and paste it here as text, not an image, using code tags.
Which table(s) is request_date on?
Re: need help with rewriting the query [message #456239 is a reply to message #456237] Sun, 16 May 2010 07:31 Go to previous messageGo to next message
ateeqrahman786
Messages: 52
Registered: December 2009
Location: Hyderabad,India
Member
The first set is for A_PT_MASTER.

Request_date is in these tables -
A_INP_THEATRE_ADMT

A_INP_ADMT_MSSG

[Updated on: Sun, 16 May 2010 07:33]

Report message to a moderator

Re: need help with rewriting the query [message #456264 is a reply to message #456239] Sun, 16 May 2010 16:13 Go to previous messageGo to next message
cookiemonster
Messages: 13921
Registered: September 2008
Location: Rainy Manchester
Senior Member
TRy adding an index to both A_INP_THEATRE_ADMT and A_INP_ADMT_MSSG consisting of the following columns:
BUS_UNIT, PT_CODE, REQUEST_DATE, REQUEST_STATUS_FLAG
Re: need help with rewriting the query [message #456265 is a reply to message #456264] Sun, 16 May 2010 16:14 Go to previous messageGo to next message
cookiemonster
Messages: 13921
Registered: September 2008
Location: Rainy Manchester
Senior Member
And make sure you remove the trunc as Ross suggested.
Re: need help with rewriting the query [message #456303 is a reply to message #456265] Mon, 17 May 2010 02:50 Go to previous message
ateeqrahman786
Messages: 52
Registered: December 2009
Location: Hyderabad,India
Member
Thanks for the reply guyz, i ll try them and let u know the result.
Previous Topic: need help to speed up data loading in form
Next Topic: explain plan
Goto Forum:
  


Current Time: Thu May 02 18:39:36 CDT 2024