Convert Inequality Predicates on Bit / Boolean Columns to Equality Predicate - by Michael Ferguson

Status : 

 


2
0
Sign in
to vote
ID 812278 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 12/24/2013 9:14:25 AM
Access Restriction Public

Description

SQL 2012 SP1 doesn't seem to use an inequality predicate on a bit field as a search argument ("SARG"). Clearly, since bit fields may only contain two values, an inequality predicate for a bit can easily be converted to an equality predicate. Converting "<> 0" to "= 1" (and "<> 1" to "= 0") should be a relatively easy optimization to add to the algebrizer / optimizer. Although savvy users can easily fix explicit SQL code by rewriting the inequality predicate as an equality predicate, this optimization will benefit certain ORM frameworks that are not smart enough to evaluate "! obj.BitColumn" in code to "BitColumn = 0" (and instead produce code like "obj.BitColumn <> 1", which will not SARG).
Sign in to post a comment.