SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Is using 0x0 faster than a 0 in a WHERE clause


Is using 0x0 faster than a 0 in a WHERE clause

Author
Message
smrtstpetesmith
smrtstpetesmith
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 12
For a bit field, is using

WHERE mybit = 0x0

faster than

WHERE mybit = 0


I am being told to use 0x0 but am not yet convinced.

Thanks!
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62379 Visits: 17954
smrtstpetesmith (2/28/2014)
For a bit field, is using

WHERE mybit = 0x0

faster than

WHERE mybit = 0


I am being told to use 0x0 but am not yet convinced.

Thanks!


Why don't you do some performance tests?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
smrtstpetesmith
smrtstpetesmith
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 12
I am but my results thus far are statistically insignificant...
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62379 Visits: 17954
smrtstpetesmith (2/28/2014)
I am but my results thus far are statistically insignificant...


I would surprised if there is any difference. Throw together a few million row test table and give it a whirl. I suspect it will be the same.

What is the rationale you are being told to use 0x0 instead of 0? Often people get ideas about performance and they stick with them even if there is nothing to back it up. I have a feeling this may be one of those situations.

If you do end up using 0x0 you should probably add a comment about what that is for others who stumble across your code in the future and wonder what it is trying to accomplish. ;-)

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Richard Fryar
Richard Fryar
SSC Eights!
SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)SSC Eights! (925 reputation)

Group: General Forum Members
Points: 925 Visits: 1172
smrtstpetesmith (2/28/2014)
For a bit field, is using

WHERE mybit = 0x0

faster than

WHERE mybit = 0

I am being told to use 0x0 but am not yet convinced.

Thanks!


I suspect the person who told you that assumed it would avoid an implicit conversion in the execution plan. So the way to tell is to try both and compare the plans.

I've just done that with a very simple test, and the results were the other way around.
Using 0x0 resulted in an implicit conversion to bit, whereas using 0 did not.

The conversion is performed just once against a constant, so has zero impact on cost. Both queries had identical cost, even down to 7th decimal place.


Check Your SQL Servers Quickly and Easily
www.sqlcopilot.com
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