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

Is using 0x0 faster than a 0 in a WHERE clause Expand / Collapse
Author
Message
Posted Friday, February 28, 2014 9:11 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 4, 2014 2:15 PM
Points: 2, Visits: 10
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!
Post #1546412
Posted Friday, February 28, 2014 9:48 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:13 PM
Points: 12,995, Visits: 12,414
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 Moden's 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)
Post #1546442
Posted Friday, February 28, 2014 9:55 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 4, 2014 2:15 PM
Points: 2, Visits: 10
I am but my results thus far are statistically insignificant...
Post #1546443
Posted Friday, February 28, 2014 10:11 AM This worked for the OP Answer marked as solution


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:13 PM
Points: 12,995, Visits: 12,414
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 Moden's 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)
Post #1546465
Posted Monday, March 3, 2014 9:53 AM This worked for the OP Answer marked as solution
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 26, 2014 5:09 AM
Points: 283, Visits: 1,118
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
Post #1547011
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse