Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can a bit-field be so slow?

Status
Not open for further replies.

jel

Programmer
Feb 17, 2002
349
NL
In a (rather complex) T-SQL statement I used the expression:
WHERE .... AND fieldx = 1 ....
fieldx has datatype 'bit'.
The query performed very poor, and removing this specific constraint speeded things up more then 10 times.
Because I needed the constraint anyways, I made a wild experiment: I changed the datatype to int, and put an index on it. Guess what: performance still 10 times better then before.
Not being an SQL-guru at all: what is happening here? I'd think a bit-field would me much faster then an indexed int-field?
 
The bit data type can not have an index, and is not a good data type for data that you wish to filter on. The advantage of the bit datatype is that it takes up a small amount of space and up to 8 bit values from a single record can take up just one byte of data. As your tests showed, choose another data type and your conditional queries will run much faster.
 
Thanks stravis, glad to know my uneducated guess was correct.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top