Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another questions about the database Index...

Status
Not open for further replies.

fletchsod

Programmer
Dec 16, 2002
181
Quick question here!! I have are

Code:
  .. FROM SESSIONS WHERE SESSION_ID = '***'			
  .. FROM SESSIONS WHERE SESSION_ID = '***' AND USER_ID = '***'
  .. FROM SESSIONS WHERE USER_ID = '***'

The primary key is SESSION_ID. Since SESSION_ID is automatically indexed due to primary key. Suppose I add the USER_ID to the existing index that include the primary key, would it still work? Or do I have to make a seperate index for "USER_ID"?

Thanks..
 
So, I would have to create a seperate index instead for the "USER_ID"?? Right??
 
Yes, you should do this , but try to test before and after.
If USER_ID has a very low cardinality, then adding an index may have zero effect on performance. As the article points out, there is no golden rule, you need to test and find out..

Ties Blom

 
Right. Thanks. Yea, I read the article. I know what you meant about index as a matter of arts.
 
If the table have a few indexes then DB2 would go for whatever is the shortest by default? What would the default be that DB2 will use?

I'm just wondering because I have 18 tables and some SQL Queries varies.
 
The query optimizer has a mind of its own. The sure way of finding out is using explain plan to check how the optimizer chooses its path , then add an index and check again. You can theorize all you want, but in this case you need to test (especially if you already know the queries that are going to be fired at the tables)

Ties Blom

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top