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

Efficiency - Joining various tables vs individual select


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

New User


Joined: 07 Apr 2010
Posts: 94
Location: Bangalore, India

PostPosted: Mon Mar 25, 2013 10:23 pm
Reply with quote

Hi,

Requirement - to be accomplished via COBOL

TABLE A : TABLE B = 1 : many

1. Select 1 row from TABLE A - about 600 bytes of data per row.
2. Fetch upto 100 records from TABLE B based on COL1 from TABLE A - about 20 bytes of data per row.
3. Perform 1 and 2 until a list of values - COL1, gets exhausted

Can any one suggest the better option in terms of efficiency, performance and cost from the below 2 - both the tables have millions of rows?

A. Use 1 cursor, use JOIN to combine TABLE A & TABLE B and retrieve the required rows.
B. Use 2 cursors, open cursor 1, fetch first row, open cursor 2, fetch all rows, close cursor 2, fetch second row in cursor 1, open cursor 2, fetch all rows, close cursor 2 and so on.



Thanks
TS70363
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Mon Mar 25, 2013 10:38 pm
Reply with quote

Try for multi row fetch for cursor 2
Back to top
View user's profile Send private message
TS70363

New User


Joined: 07 Apr 2010
Posts: 94
Location: Bangalore, India

PostPosted: Tue Mar 26, 2013 8:50 am
Reply with quote

Hi Rohit,

Yes, cursor 2 is a multi-row fetch cursor..

But question over here is, which one of the 2 options is better
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Tue Mar 26, 2013 12:20 pm
Reply with quote

Hi TS70363,

Use Joins and give good filtering conditions in the WHERE clause(not flag indicators having low cardinality).

Thanks,
Sushanth
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Tue Mar 26, 2013 5:45 pm
Reply with quote

Hi,
join should be the good option over here and have a multi row fetch , share your explain results. 1st option should give less MIPS than 2.so try it and share your results.
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 Dynamically pass table name to a sele... DB2 2
No new posts SELECT from data change table DB2 5
No new posts Select two different counts from SQL... DB2 6
No new posts Need to fetch data from so many DB2 t... DB2 9
No new posts Select a DB2 value in a specific deci... DB2 4
Search our Forums:

Back to Top