IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Performance issue for OPEN cursor


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Tue Jun 09, 2009 8:05 pm
Reply with quote

Hello All,

I have a Cursor Defined with the Below Query
Code:

SELECT     A.COL1,                                                     
           A.COL2,                                           
           MAX(A.COL3)                                         
             FROM  VIEW1 A,                                 
                   VIEW2 B                               
             WHERE A.COL1 = B.COL1                    AND               
                   A.COL2 = B.COL2                    AND               
                   A.COL3 IN ('AAA','BBB','ZZZ') AND             
                   B.Col4 = :WS-VAR1                   AND               
                   B.col5 = :WS-VAR2                                         
             GROUP BY A.COLUMN1, A.COLUMN2     
             ORDER BY A.COLUMN1 ASC , A.COLUMN2 DESC;                     



Code:

VIew1
------
Col1 Col2 Col3
10   4    AAA
10   4    BBB
10   5    ZZZ
11   1    ZZZ
12   6    AAA
12   6    BBB
13   3    AAA

VIEW2
-----
Col1  COl2  Col4  Col5
10    4     3     5
11    1     2     3
12    6     3     5
13    3     3     5


Considering the values of ws-Var1 = 3 and ws-Var2=5
Following is the Output of the SQL
Code:

A.Col1   A.Col2  A.COl3
-------  ------  ------
10        4       BBB
12        6       BBB
13        3       AAA


Problem:CPU time for Opening the Cursor is much Higher(due to the MAx function and
GROUP/ORDER clause) and it has an impact on the performance.

CAn anyone suggest any modification to the SQL query in such a way that
the MAX function and GROUP/ORDER can be avoided,but give the Same Above result.

Thanks,
Sree
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Jun 09, 2009 8:24 pm
Reply with quote

Are VIEW1 and VIEW2 views or tables. Applying your query against actual tables would most likely be faster then using views.
Back to top
View user's profile Send private message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 54
Location: Madrid

PostPosted: Tue Jun 09, 2009 8:27 pm
Reply with quote

HI Carg,

I am restricted to use Views instead of actual Tables.
VIEW1 and VIEW2 are Views.

Thanks,
Sree
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Jun 10, 2009 7:02 pm
Reply with quote

views usually perform pretty well stand-alone and they can insulate the developer from requiring any knowledge about the table. But when multiple views are joined , the access path can be less than optimum.

Basically, you will need to reference the base table directly along with code similar to the logic in the view for a better performance ...

Alternatively you can try this query

Code:


SELECT A.COL1, A.COL2, A.COL3 FROM
(
SELECT COL1,COL2,MAX(COL3) AS COL3
FROM VIEW1
WHERE COL3 IN ('AAA','BBB','ZZZ')
GROUP BY COL1, COL2
) AS A
,
(
SELECT COL1, COL2
FROM VIEW2
WHERE B.COL4 = :WS-VAR1
AND B.COL5 = :WS-VAR2
) AS B

WHERE A.COL1 = B.COL1
AND A.COL2 = B.COL2
ORDER BY A.COL1 ASC, A.COL2 DESC ;


Be sure to run EXPLAIN on both queries as I am not aware of the table indexes ...
Back to top
View user's profile Send private message
bauer

New User


Joined: 03 Mar 2009
Posts: 28
Location: germany

PostPosted: Mon Jun 15, 2009 3:10 pm
Reply with quote

Use Explain and check if runstats has executed.

which indices are available ?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Calling an Open C library function in... CICS 1
No new posts exploiting Z16 performance PL/I & Assembler 2
No new posts Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
No new posts Open VSAM File in IMS DC Region - DFS... IMS DB/DC 0
Search our Forums:

Back to Top