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 > Command SELECT... ORDER with index

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-13-04, 12:45
Marbolito Marbolito is offline
Registered User
 
Join Date: May 2004
Posts: 2
Command SELECT... ORDER with index

Hello,

Is it possible to use index when we have to use only the clause ORDER ? (I needn't to use the clause WHERE)

Can we have the possibility to use an index with the clause "ORDER" ?

Example :
Select *
from view
order by a, b, c

I would like tio create an index ordered like a,b, c
Reply With Quote
  #2 (permalink)  
Old 05-13-04, 12:55
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Yes, and DB2 will probably use the index and avoid a sort.

Andy
Reply With Quote
  #3 (permalink)  
Old 05-13-04, 12:57
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Most likely db2 will use an index ...

There may be occasions(based on statistics, of course) when there may be a tablescan ...

I assume the columns a.b and c in the view are not based on functions ...

HTH

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #4 (permalink)  
Old 05-13-04, 12:57
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Yes, DB2 may decide to use an index in lieu of a sort. But there is no guarantee, and DB2 will use what it thinks is fastest based on the query and the statistics from a runstats.
__________________
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
  #5 (permalink)  
Old 05-13-04, 13:03
Marbolito Marbolito is offline
Registered User
 
Join Date: May 2004
Posts: 2
Quote:
Originally Posted by Marcus_A
Yes, DB2 may decide to use an index in lieu of a sort. But there is no guarantee, and DB2 will use what it thinks is fastest based on the query and the statistics from a runstats.
Can we force the use of an index ? I have 250000 records and the system doesn't take it (IBM AS400 V5R1)
Reply With Quote
  #6 (permalink)  
Old 05-13-04, 13:15
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Not sure about AS400 ...

But what is the definition of the table and view ?

I assume you have done RUNSTATS ...

Cheers
sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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