Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to determine if index fields are in specific sequenc
Message
 
 
To
24/05/2012 02:58:14
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Application:
Web
Miscellaneous
Thread ID:
01544239
Message ID:
01544247
Views:
22
>Hi
>I am tuning my database performance.I found that, the order of field expression in index could cause performance issue
>
>IndexA: FieldA, FieldB, FieldC can be slower than IndexA: FieldC, FieldA, FieldB
>
>I would like to know, how to check if the existing index expression is in A,B,C sequence, then only I drop it and re-create it with C,A,B?
>
>Thank you

Check this query which orders columns in the index by its ordinal position in the index:
SELECT OBJECT_SCHEMA_NAME(T.[object_id],DB_ID()) AS [Schema],  
  T.[name] AS [table_name], I.[name] AS [index_name], AC.[name] AS [column_name],  
  I.[type_desc], I.[is_unique], I.[data_space_id], I.[ignore_dup_key], I.[is_primary_key], 
  I.[is_unique_constraint], I.[fill_factor],    I.[is_padded], I.[is_disabled], I.[is_hypothetical], 
  I.[allow_row_locks], I.[allow_page_locks], IC.[is_descending_key], IC.[is_included_column] 
FROM sys.[tables] AS T  
  INNER JOIN sys.[indexes] I ON T.[object_id] = I.[object_id]  
  INNER JOIN sys.[index_columns] IC ON I.[object_id] = IC.[object_id] 
  INNER JOIN sys.[all_columns] AC ON T.[object_id] = AC.[object_id] AND IC.[column_id] = AC.[column_id] 
WHERE T.[is_ms_shipped] = 0 AND I.[type_desc] <> 'HEAP' 
ORDER BY T.[name], I.[index_id], IC.[key_ordinal]
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform