SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


What column to use for Cluster index


What column to use for Cluster index

Author
Message
Joe-420121
Joe-420121
Mr or Mrs. 500
Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)Mr or Mrs. 500 (556 reputation)

Group: General Forum Members
Points: 556 Visits: 560
I have a table with over 10 million rows, it has all the PaymentHistory. It has ID as identity column, and EMPID with duplicate emp numbers. All the query, [joins], [where clause] are using EMPID. Which column should be created for CLUSTERED index? pls help thans in advanceCool
Wilfred van Dijk
Wilfred van Dijk
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1960 Visits: 1363
Generally, you'll get the most benefit of a (clustered) index if you add columns which are most used in your where clause.
In your case EMPLID. But Clustered indexes have to be unique, which is not in your case.
But, if you create a clustered index on a non-unique field, SQL will add a column to make this index unique.

So you have to compare the extra diskspace against the performance benefits.

You could also consider partitioning. A history table is a perfect candidate for that feature.

Wilfred
The best things in life are the simple things
free_mascot
free_mascot
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5757 Visits: 2250
Probably you can use database Engine tunning advisor and/or use Show Plan to find our more.

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
GilaMonster
GilaMonster
SSC Guru
SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)

Group: General Forum Members
Points: 156070 Visits: 45920
A history table that isn't mostly queried by date?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Andrew Gothard-467944
Andrew Gothard-467944
Say Hey Kid
Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)Say Hey Kid (666 reputation)

Group: General Forum Members
Points: 666 Visits: 2357
Wilfred van Dijk (10/3/2008)
Generally, you'll get the most benefit of a (clustered) index if you add columns which are most used in your where clause.
In your case EMPLID. But Clustered indexes have to be unique, which is not in your case.
But, if you create a clustered index on a non-unique field, SQL will add a column to make this index unique.

So you have to compare the extra diskspace against the performance benefits.

You could also consider partitioning. A history table is a perfect candidate for that feature.


Not necessarily - your clustered index should always* be monotinic. If as an extreme example, you're writing a Db for a web facing app using GUIDS even though you're going to be using the GUIDS for lookups and queries you DO NOT use them for your clustered index as the random nature of the GUID means that the new records can end up going anywhere in your table. This can lead to huge performance issues, page splits, pagelocks as everything is reordered in the table to place the row in the right physical position. You'd probably use insert datetime and cover the lookup using a covering index



* Well, no rules hold fast all the time. Sure someone'll think of a situation where this wouldn't be the case I'm sure
GilaMonster
GilaMonster
SSC Guru
SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)SSC Guru (156K reputation)

Group: General Forum Members
Points: 156070 Visits: 45920
Andrew Gothard (10/3/2008)

* Well, no rules hold fast all the time. Sure someone'll think of a situation where this wouldn't be the case I'm sure


Depends how fast the table changes. If inserts only happen occasionally (an employees table, or something like that), then the main reason for clustering on an ascending key (fragmentation) isn't that applicable.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search