Home » RDBMS Server » Performance Tuning » Inline Views
Inline Views [message #143767] Sat, 22 October 2005 03:19 Go to next message
rgopal67
Messages: 3
Registered: September 2005
Location: Palghat
Junior Member

I have a query like this

SELECT state_cd "State",substr(a.prod_cd,1,3) "Brand", substr(A.prod_cd,4,2)"Size",SUM(nvl(A.CBAL,0))
FROM mytab A
WHERE DATE = (SELECT MAX(B.DATE) FROM mytab B
WHERE A.PROD_CD = B.PROD_CD AND
A.STATE_CD = B.STATE_CD and
B.DATE <= '30-sep-2005')
and substr(prod_cd,1,3) = brand_cd
and nvl(A.CBAL,0) != 0
GROUP BY state_cd,substr(a.prod_cd,1,3),substr(A.prod_cd,4,2)

this takes lot of time to give the result. Can it be handled using Inline Views. Can anyone help?
Re: Inline Views [message #143845 is a reply to message #143767] Sun, 23 October 2005 06:11 Go to previous messageGo to next message
mchadder
Messages: 224
Registered: May 2005
Location: UK
Senior Member
Hello there.

Any chance you can post the EXPLAIN PLAN for this query, and how many rows are in "mytab", what indexes you have etc. etc.?

Regards
Re: Inline Views [message #143905 is a reply to message #143845] Mon, 24 October 2005 01:22 Go to previous messageGo to next message
rgopal67
Messages: 3
Registered: September 2005
Location: Palghat
Junior Member

My SQL is

SELECT state_cd "State",substr(a.prod_cd,1,3) "Brand", substr(A.prod_cd,4,2)"Size", c.print_order, SUM(nvl(A.CLOSING_BAL_CS,0))
FROM mytab A,brand c
WHERE DATE = (SELECT MAX(B.DATE) FROM mytab B
WHERE A.PROD_CD = B.PROD_CD AND
A.STATE_CD = B.STATE_CD and
B.DATE <= '30-sep-2005')
and substr(prod_cd,1,3) = brand_cd
and nvl(A.CBAL,0) != 0
GROUP BY state_cd,substr(a.prod_cd,1,3),substr(A.prod_cd,4,2),c.print_order

Explain Plan

Rows Operation Object
---- ------------------------------ -----------------
SELECT STATEMENT ()
SORT (GROUP BY)
FILTER ()
NESTED LOOPS ()
TABLE ACCESS (FULL) MYTAB
TABLE ACCESS (BY ROWID) BRAND
INDEX (UNIQUE SCAN) PK_BRAND
SORT (AGGREGATE)
INDEX (RANGE SCAN) STK

I HAVE AN INDEX STK FOR THE FIELDS DATE,PROD_CD,STATE_CD ON MYTAB
THERE ARE 13173 ROWS IN MYTAB. IT TAKES 18 MINUTES TO GIVE THE RESULT. CAN ANYONE GIVE ALTERNATIVE WAY FOR THIS

Regards,
Raj
Re: Inline Views [message #143968 is a reply to message #143767] Mon, 24 October 2005 07:45 Go to previous messageGo to next message
smartin
Messages: 1803
Registered: March 2005
Location: Jacksonville, Florida
Senior Member
I am moving your question to the performance tuning forum, and suggest that you read and follow the sticky there.
Re: Inline Views [message #144121 is a reply to message #143968] Tue, 25 October 2005 02:44 Go to previous message
girish.rohini
Messages: 744
Registered: April 2005
Location: Delhi (India)
Senior Member
Have you collected statistics on your underlying tables?
Previous Topic: Performance of Package and Procedure
Next Topic: What are the pluses of autostats
Goto Forum:
  


Current Time: Sat Apr 20 07:44:37 CDT 2024