Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Index on BIT column Expand / Collapse
Author
Message
Posted Thursday, September 16, 2010 12:55 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 21, 2013 3:14 AM
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
Post #986958
Posted Thursday, September 16, 2010 1:27 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:52 AM
Points: 42,467, Visits: 35,535
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 2008, MVP
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

Post #986980
Posted Tuesday, February 15, 2011 8:37 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 11:42 AM
Points: 12, Visits: 55
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.
Post #1064337
Posted Tuesday, February 15, 2011 9:32 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, April 17, 2013 2:47 PM
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.

Post #1064373
Posted Tuesday, February 15, 2011 10:44 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
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
Post #1064428
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse