February 14, 2013 at 10:37 pm
Can we add bit datatype column to the index? What will be the impact of the same?
February 15, 2013 at 12:18 am
There is nothing to stop you adding a BIT data type to an Index, HOWEVER, it will have very low cardinality, as there are basically 3 states, True, False, and Unknown.
Ideally the Bit wouldn't be the only column in the index and in 99% of cases is probably going to be part of the INCLUDE part of the index, as BIT fields tend to be used for filtering.
_________________________________________________________________________
SSC Guide to Posting and Best Practices
February 15, 2013 at 1:22 am
Yes, you can. Impact depends on whether it's useful for queries, where it is in the index and a whole lot more.
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
February 15, 2013 at 1:23 am
Jason-299789 (2/15/2013)
in 99% of cases is probably going to be part of the INCLUDE part of the index, as BIT fields tend to be used for filtering.
If the bit column tends to be used for filtering, wouldn't you put it in the key columns so that it can be part of the index seek.
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
February 15, 2013 at 2:02 am
Gail,
I would say it depends on various factors, but as a general rule I would look at having it in the Include column list initially, and then evaluate.
_________________________________________________________________________
SSC Guide to Posting and Best Practices
February 15, 2013 at 2:08 am
My general rule is if it is filtered on and can be part of a seek, then it goes in the key. No sense in making SQL do more work in an index seek than necessary.
Now, if the queries are such that the bit can't be used for a seek (function on the column), then sure it goes into the include
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
February 15, 2013 at 3:24 am
Fair Point Gail,
In then end it comes down to evaluating the requirement and looking at the reason for putting the BIT column on that particular index, then evaluating the change across other queries.
_________________________________________________________________________
SSC Guide to Posting and Best Practices
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply