What is the difference between doing:
SELECT * FROM table WHERE column IS NULL
or –
SELECT * FROM table WHERE column = 0
Is doing IS NULL significantly worse off than equating to a constant?
The use case comes up where I have something like:
SELECT * FROM users WHERE paying IS NULL
(or adding an additional column)
SELECT * FROM users WHERE is_paying = 0
If I understand your question correctly, you are asking about the relative benefits/problems with the two situations:
Given that both are in the data table, I cannot think of why one would perform better than the other. I do think the first is clearer on what the query is doing, so that is the version I would prefer. But from a performance perspective, they should be the same.
Someone else mentioned — and I’m sure you are aware — that NULL and 0 are different beasts. They can also behave differently in the optimization of joins and other elements. But, for simple filtering, I would expect them to have the same performance.
Well, there is one technicaility. The comparison to “0” is probably built into the CPU. The comparison to NULL is probably a bit operation that requires something like a mask, shift, and comparison — which might take an iota of time longer. However, this performance difference is negligible when compared to the fact that you are reading the data from disk to begin with.