MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how is this query resolved?

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
jctgf
Beginner


Joined: 05 Nov 2006
Posts: 89
Topics: 36

PostPosted: Sat Mar 07, 2009 6:07 pm    Post subject: how is this query resolved? Reply with quote

Code:

SELECT ...
FROM TABLE1
WHERE COLUMNA = ...
    AND COLUMNB < ...
ORDER BY COLUMNB
FETCH FIRST 200 ROWS ONLY


Hi there,
In this query I select lines from a table, order it and limit the result cursor to 250 lines.
I wonder if these steps are taken in the sequence described above, please.
If so, and if the number of lines selected in the first step is huge, it probably won
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Sat Mar 07, 2009 10:50 pm    Post subject: Reply with quote

jctgf,

If both the FETCH FIRST clause and the ORDER BY clause are specified, the ordering is performed on the entire result table prior to returning the first n rows.

Check this link

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQJ12/4.4.3?

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Sun Mar 08, 2009 10:15 pm    Post subject: Reply with quote

If you have an index that matches the ORDER BY columns exactly, DB2 could bypass the physical sort. You'd have to look at the access path for the query to make sure.
Back to top
View user's profile Send private message
jctgf
Beginner


Joined: 05 Nov 2006
Posts: 89
Topics: 36

PostPosted: Mon Mar 09, 2009 5:12 pm    Post subject: Reply with quote

thanks.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group