If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Order of records...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-20-03, 16:54
nagasurir nagasurir is offline
Registered User
 
Join Date: Nov 2003
Location: California,USA
Posts: 71
Order of records...

Can any one tell in what order the data will be retrieved for a SELECT query from a table with the no of records in millions in that table.
Reply With Quote
  #2 (permalink)  
Old 11-20-03, 17:03
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
A relational database in general, and DB2 in particular, will not guarantee the order of rows retrieved unless you specify the Order By clause.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 12-11-03, 05:27
tupiex tupiex is offline
Registered User
 
Join Date: Dec 2003
Location: Johannesburg, South Africa
Posts: 18
Talking DB2 Information

Hi

Not many people know or realise that the data with in a table will automatically lie in the oprder of the CLUSTERING index by default. If you do not specify a CLUSTERING index then rows will be in the order of the FIRST INDEX created.

Thus if you are getting data through a SELECT * in the incorrect order, this will be the problem.

What the other replier said is true, if you want to retrieve data in a different order then you will need to use an ORDER BY, but just remember there is move overhead fro this.

The best solution is to define a CLUSTERING index (only one on a table because of the row sequece) and then other indexes for the other query or use ORDER BY.

JUST REMEMBER THERE IS ALWAYS A COST. Lots of Indexes will cause UPDATES/INSERTS and DELETES to be slower.
__________________
Divvy
Reply With Quote
  #4 (permalink)  
Old 12-11-03, 07:50
GertK GertK is offline
Registered User
 
Join Date: Nov 2003
Location: Netherlands
Posts: 96
Re: DB2 Information

Quote:
Originally posted by tupiex
Hi

Not many people know or realise that the data with in a table will automatically lie in the oprder of the CLUSTERING index by default. If you do not specify a CLUSTERING index then rows will be in the order of the FIRST INDEX created.

Thus if you are getting data through a SELECT * in the incorrect order, this will be the problem.
Hi,
AFAIK it's even not sure you will get the data in the order of the clustering index or the first index created. If DB2 is using parallel IO to get the data it can be returned to the DB2 engine in a different order and without an order by it's directly returned to the requesting application.

There's also a difference between DB2 OS/390 and DB2 Unix/Windows when talking about clustering indexes. DB2 Unix/Windows tries to put the data in the right phisical order but you can't be sure it really is.
If I remember right from 10 years ago DB2 OS/390 fysically inserts the rows in the order of the clustering index.

Kind regards, Gert
Reply With Quote
  #5 (permalink)  
Old 12-20-03, 19:16
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: DB2 Information

yep ... even if you get the rows in the same order a million times, it is merely coincidence

Sathyaram

Quote:
Originally posted by GertK
Hi,
AFAIK it's even not sure you will get the data in the order of the clustering index or the first index created. If DB2 is using parallel IO to get the data it can be returned to the DB2 engine in a different order and without an order by it's directly returned to the requesting application.

There's also a difference between DB2 OS/390 and DB2 Unix/Windows when talking about clustering indexes. DB2 Unix/Windows tries to put the data in the right phisical order but you can't be sure it really is.
If I remember right from 10 years ago DB2 OS/390 fysically inserts the rows in the order of the clustering index.

Kind regards, Gert
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #6 (permalink)  
Old 12-20-03, 20:48
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
if there's no clustering index, rows might be returned in the order of the first index, but what if the first index isn't declared until after the table has been loaded? what then?

unless you use ORDER BY, any sequence you see is, as they say, mere coincidence


rudy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On