2

I have a pure boolean type of field in my web-app, but now I am thinking about difference between nullable and non-nullable property.

In which case would I have the best performance: use 'true' and 'false' value or use 'true' and NULL instead?

1
  • What do you mean by "best performance"? Why would you think about performance before thinking about what's the most reasonable way? This is not even about this exact thing (there's no possible performance gain for using null instead of false), it's more about the whole concept of optimizing for performance before identifying the actual performance bottlenecks. Don't guess on performance - make your application nice and clean, test it, and if needed, optimize the parts that will make an impact. Commented Mar 12, 2015 at 8:42

1 Answer 1

1

The common convention is to use true and false as values - they mean you know the answer to the question asked. null is not a value - it's a lack thereof, and is usually used as such.

E.g., consider the (morbid) column has_cancer. true means the subject has it, false that he does not, and null that he has not been tested yet, so we just don't know.

Sign up to request clarification or add additional context in comments.

2 Comments

Can i optimize the db queries if to use null field? Do i have any additional features in this case?
@Sergey_Ksenofontov You get the awesome features like ANSI NULL behaviour - any operand that is null will propagate to the return value. 1 + NULL is NULL, for example. This usually leads to having to do something like 1 + coalesce(column, 0) everywhere :) Treat null the way it's supposed to be treated - an absence of value, not "yet another value".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.