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


Index on BIT column


Index on BIT column

Author
Message
ningaraju.n
ningaraju.n
SSC-Enthusiastic
SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)SSC-Enthusiastic (134 reputation)

Group: General Forum Members
Points: 134 Visits: 425
Hi All,

I have around 200+ tables in database and all the tables have column with the name IsDeleted which is of datatype bit. And we are using this for logical deletion, ie; if an record deleted we are updating the value 1 for IsDeleted column
and while fetching we will select only the records with 0 in IsDeleted column and we are using this column in every select statement for each table .

Now my question is whether i have to create index on this column for all tables? If yes how the performance will be gained?

Thanks in Advance
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47192 Visits: 44359
An index just on that column will probably not be useful. What you'll likely need to do is create indexes for the various queries and ensure that the IsDeleted is part of each index.

If you can post a couple of example queries I can probably help you further.


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


shian_lineage2
shian_lineage2
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 81
I've seen instances where an index on boolean field is useful. If there is a large discrepancy between the number of 0's and 1's, and you're searching for the the smaller of the two, an index may work well.

E.g.: If IsDeleted is set to 1 during online processing and then all entries with IsDeleted=1 are deleted by a script that gets run during off-hours, I'd expect the total number of rows where IsDeleted=1 to be small. In this case, if your WHERE clause filters on IsDeleted=1, you're likely to get seeks rather than scans. On the other hand, if your WHERE clause filters on IsDeleted=0, it still has to look through the majority of rows that might otherwise be returned, so you'll get scans.

Like GilaMonster said, though, it's unlikely that an index on a boolean, all by itself, is going to help you in any significant way. It's possible that adding it to existing indexes might help.
Deb Anderson
Deb Anderson
SSC Journeyman
SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)SSC Journeyman (88 reputation)

Group: General Forum Members
Points: 88 Visits: 351
i agree with shian. i've actually had instances where indexing on a bit field was extremely useful - though common wisdom suggests they may be more overhead than they are worth. test both with and without.

Cool
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14375 Visits: 9729
In SQL 2008, a filtered index on one or another of the values in a bit column, can make a HUGE difference in performance.

In 2005 and earlier, just don't make it the leading edge of the index, and it should help, but not quite as much.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Wilson.Mead
Wilson.Mead
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 18


Count yourself lucky when your indexing decisions can be based solely on a single column. Like most things in life, context creates more value than content.



Consider the question "Is 300 horsepower good?" It will not put another man on the moon or move 12 railrailcars of freight. Give a Miata that much power and you'll end up with a lot of scrap metal; a Corvette, well...you'll want more.



Do not create an index for the sake of having an index, understand how and why the index creates value, and be very wary of diminishing returns.


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