Comparing these statements
SELECT * FROM Table
WHERE
(field IS NULL OR field = 'empty_value')
vs.
SELECT * FROM Table
WHERE
COALESCE(field, 'empty_value') = 'empty_value'
in terms of performance, which one is better? Is there any difference?
I already know the first one requires a slightly more complex filter operation, while the second one needs +1 scalar computation prior the filter. The performance impacts of doing this in a single table are insignificant, but what may happen when the query is complex? And when there are multiple fields in this situation? Should I prefer one over the other?
PS: I am using 'empty_value'
as a generic way to describe a situation where the absence of a particular value (=NULL
) and a particular value (='empty_value'
) have the same meaning for the query. Changing anything in the table design or how it stores its values is not an option.
PS2: I am using SQL Server, but I would like to get a more generic answer about this issue. But, I would stick to SQL Server if the answer is implementation dependent.