Strategies for checking ISNULL on varbinary fields?

后端 未结 2 1167
孤街浪徒
孤街浪徒 2020-12-16 12:15

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

相关标签:
2条回答
  • 2020-12-16 13:01

    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.

    0 讨论(0)
  • 2020-12-16 13:09

    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.

    0 讨论(0)
提交回复
热议问题