Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Index Creation Guidelines


Index Creation Guidelines

Author
Message
TryHard
TryHard
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 1
Does anyone have any input on the indexing rules when using a GUID primary key column?
My understanding is that using a clustered index on this is not a good idea, for the same reasons as not using a clustered index on a name field. So a non clustered index is the other alternative. So then if there are no other great candidates for a clustered index, why would you create a column with sequencial number just so you can have a clustered index as suggested by others. I can't see the benefit in this.

One final point. The article is a general guide which seems quite valid. One major point that I believe has been mmissed by all is to considere the ratio of updates/inserts/deletes to selects. This should have a major impact on your decision making process. An extra couple of milliseconds on an insert due to an index recalculation is insignificant compared to a second on a select.
Leo Peysakhovich
Leo Peysakhovich
SSC-Enthusiastic
SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)

Group: General Forum Members
Points: 161 Visits: 339

Your last point is valid.

"why would you create a column with sequencial number just so you can have a clustered index as suggested by others. I can't see the benefit in this"

The benefit of clustered index in this case in maintenance and storing the data on pages with lower fragmentation level. 





Henmi
Henmi
Valued Member
Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)

Group: General Forum Members
Points: 59 Visits: 1
I have a question about the composite index.

Should a composite index be in the same order as it appears in the WHERE clause?

For example, the composite index is (address_id, address_type) and my WHERE clause is like this: address_type=xxx AND address_id =1.

Does the order like that affects the usage of composite index?

Thanks

Hendry



Sergiy
Sergiy
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: 5822 Visits: 11394
No, it does not.

But in composite index it's better to have strongest restriction first.
In your case index (address_id, address_type) will be used much more likely then (address_type, address_id).

Of course, it depends. I'm talking about typical situation, but don't forget to use your brain.
Brian Laws
Brian Laws
SSC-Enthusiastic
SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)SSC-Enthusiastic (182 reputation)

Group: General Forum Members
Points: 182 Visits: 104
I think that the decision of the column order in the composite index should also be informed by the other indexes on the table.

If the column is already in its own index or the first in another index, then I'd consider using a different column as the first in the new composite index. That way, the query optimizer can make use of the two index and make an intersect them in other queries. For example, if there already is an index on address_id, then I would try using (address_type, address_id). With the address_type first, the query analyzer could now use that index when address_type is in your where clause. This _may_ increase performance of other queries. However, you will definitely have to test and see if the trade-off is worth it. The (address_id, address_type) may have a bigger payoff than the queries with address_type in the where clause.

I'm not really sure about what benefits a composite index would give over 2 indexes. Wouldn't an index intersection of separate address_id and address_type indexes be as effective as the composite (address_id, address_type)? If not in a single query, it may be more beneficial overall (since other queries can use the two, separate indexes). I could use some clarification on this. Thanks!
Rohit Nayak-223705
Rohit Nayak-223705
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 90

Consider a table like

create table example(

tx_id int,

product_id int,

fiscal_yr_id int,

amount decimal

)

According to business rules, the uniqueness constraint is defined as (tx_id,product_id,fiscal_yr_id) ; so naturally they are candidates for the composite primary key.

Also assume that all of the queries would be exact queries i.e. where tx_id=--- and product_id=--- and fiscal_yr_id =-- i.e. no range queries and that  the selectivity of the fiscal_yr_id is low i.e. say  that it only contains two choices 2006,2007

In cases like these, are there alternatives to having the clustered index pk with (tx_id,product_id,fiscal_yr_id) that might offer better performance?

Thanks

~Rohit

 

 

 

 

 


Leo Peysakhovich
Leo Peysakhovich
SSC-Enthusiastic
SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)

Group: General Forum Members
Points: 161 Visits: 339
3 columns are forming the key - tx_id,product_id,fiscal_yr_id. You should look at selectivity of the first and combination of first and second column. If this selectivity is right you should not worry about third column. We are talking about complete index selectivity



tymberwyld
tymberwyld
SSC Veteran
SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)SSC Veteran (284 reputation)

Group: General Forum Members
Points: 284 Visits: 274
Question,
In SQL Server 2005, is it still necessary to create indexes for Foreign Keys? I was under the impression in SQL 2000 and previous that a Foreign Key is merely a Constraint and not really an Index. So, if I have a Foreign Key which I know is NOT highly selective, should I also put an index on it (say FK_IX_OrderDetails_Orders)?



Leo Peysakhovich
Leo Peysakhovich
SSC-Enthusiastic
SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)

Group: General Forum Members
Points: 161 Visits: 339

It all depend from the data analysis. In most cases, if table is not lookup table, it is not a bad idea to have index on FK column(s) because it will be used for a join between tables. But there will be small number of situations where this advise is not correct.





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