IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Composite Index


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rakesh1155

New User


Joined: 21 Jan 2009
Posts: 84
Location: India

PostPosted: Tue Jan 11, 2011 11:06 am
Reply with quote

Hi,

I have a doubt.

Lets say I have a table name TABLEA having 5 columns ( col_a, col_b, col_c, col_d, col_e).

I have a query like below:

SELECT * from TABLEA
where col_a = something
and col_b = something
and col_c = something

For a scenario like this,
What kind of index would give me better query performance ?
1. A single index as col_a, col_b and col_c as a composite non-unique index.
OR
2. Three indexes as col_a as a non-unique index, col_b as a non-unique index, col_c as a non-unique index.

I have an understand that a single index with the three columns would give a better query performance but would like to have a confirmation from the experts.

Thanks in advance.

Rakesh.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jan 11, 2011 11:27 am
Reply with quote

Hello,

I'd use the composite index, but i'd also ensure the definition placed the most unique column first, the next most unique column second, and the least unique column third.

For example if the columns are for country, region, and custid, i'd define this as custid, then region, then country.
Back to top
View user's profile Send private message
rakesh1155

New User


Joined: 21 Jan 2009
Posts: 84
Location: India

PostPosted: Tue Jan 11, 2011 1:21 pm
Reply with quote

Thank You for confirming this.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Jan 11, 2011 1:36 pm
Reply with quote

dick scherrer wrote:
Hello,

I'd use the composite index, but i'd also ensure the definition placed the most unique column first, the next most unique column second, and the least unique column third.

For example if the columns are for country, region, and custid, i'd define this as custid, then region, then country.

In my experience most reports on this kind of tables are sorted on country/region/custid.
and many (less frequent ?) queries only supply the country or country/region.
The performance gain for a query that supplies all 3 values with an index custid,region,country opposed to an index country/region/custid is in my experience very small .
especially considered the performance loss on queries with the sorts or queries that supply only country/region.

Indexes required also depends on R.I. so if you have R.I to country and to region and to custid then you might need all 3 indexes. or at least the index to the table where most deletes happen. which in this case would probably be customer.

So arguments for both cases. and as usual the final answer is : "it depends".
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jan 11, 2011 8:45 pm
Reply with quote

Hi Guy,

Quote:
So arguments for both cases. and as usual the final answer is : "it depends".
Yup. . . icon_smile.gif

It was my understanding (possibly not correct/complete) that the reason for this key was for this particular query. If it will be used for more, more considertion would be in order.

As you say - "it depends".

d
Back to top
View user's profile Send private message
rakesh1155

New User


Joined: 21 Jan 2009
Posts: 84
Location: India

PostPosted: Wed Jan 12, 2011 8:54 am
Reply with quote

Well... I agree "It depends in most cases" icon_smile.gif

Thank You Guys!!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Cobol file using index COBOL Programming 2
No new posts DL/I status code AK for GU call using... IMS DB/DC 1
No new posts Add column to existing records using ... JCL & VSAM 2
No new posts choice of clustering index DB2 3
No new posts Secondary index error while loading d... IMS DB/DC 2
Search our Forums:

Back to Top