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 > Basic question on SQL indexes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-09-09, 20:08
sundaram sundaram is offline
Registered User
 
Join Date: Mar 2006
Posts: 104
Basic question on SQL indexes

I have a table xxx with cols c1, c2,c3,c4 in schema schema1

ihave created index for table xxx as

CREATE INDEX "SCHEMA1 "."IDX907092354290000" ON "SCHEMA1 "."XXX" ("C1" ASC, "C2" DESC, "C3" ASC) ALLOW REVERSE SCANS ;

which of the the sql query will use the index

SELECT C4 FROM SCHEMA1.XXX WHERE C1="A"
SELECT C4 FROM SCHEMA1.XXX WHERE C2="B" AND C3="C"


SELECT C4 FROM SCHEMA1.XXX WHERE C3="C"

thanks

harikumar
Reply With Quote
  #2 (permalink)  
Old 07-09-09, 22:19
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Only the first query will use the b-tree of the index, which is by far the most efficient access path (assuming it is not a small table).

The other queries "may" or "may not" use the index, but if they use it, DB2 will have to read the entire index, sort of like a table scan on the index. The reason for that is that the first column of the index is not in the predicate.

You can google "b-tree index" to find out what that means if you don't understand.
__________________
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
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