In the past I\'ve noted terrible performance when querying a varbinary(max) column. Understandable, but it also seems to happen when checking if it\'s null or not, and I was
I think it's slow because the varbinary column is not (and can't be) indexed. Therefore, your approach to use a computed (and indexed) column is valid.
However, I would use ISNULL(DATALENGTH(Content), -1)
instead, so that you can distinguish between length 0 and NULL. Or just use DATALENGTH(Content)
. I mean, Microsoft SQL Server is not Oracle where an empty string is the same as NULL.
We had a similar problem when looking for rows where a varbinary value was not null. For us the solution was to update the statistics for the database:
exec sp_updatestats
After doing this the queries ran much faster.