简体   繁体   English

SQL Server 2005-选择性能-WHERE和NULL

[英]SQL Server 2005 - Select Performance - WHERE and NULL

I have the following issue: 我有以下问题:

SQL Server 2005 SQL Server 2005

  • Table: Documents 表:文件
  • Records: 400'000 记录:400'000
  • Field Value IS NOT an INDEX 字段值不是索引
  • Query: 查询:

     SELECT * FROM Documents WHERE value = 0 

CASE A: 案例A:

  • ALL 400'000 Records have value = NULL 所有400'000条记录的值= NULL
  • Performance = X Seconds 性能= X秒

CASE B: 案例B:

  • 200'000 Records have value = NULL 200'000条记录的值= NULL
  • 200'000 Records have value <> NULL 200'000条记录的值<> NULL
  • Performance = X + Y Seconds 性能= X + Y秒

CASE C: 案例C:

  • 400'000 Records have value <> NULL 400'000条记录的值<> NULL
  • Performance = X + Y + Z Seconds 性能= X + Y + Z秒

Is this a common behavior, or do I have to search the cause of the performance degrees somewhere else ? 这是常见的行为吗?还是我必须在其他地方搜索导致性能降低的原因?

You almost certainly don't have an index on the value column. 您几乎可以肯定在value列上没有索引。 Given this assumption, your results aren't very surprising. 在这种假设下,您的结果并不令人惊讶。 NULL is internally stored as a separate bit that is simpler to lookup (and reject) than performing a numeric comparison. NULL在内部存储为单独的位,比执行数字比较更容易查找(和拒绝)。

If you had an index, then I'd be somewhat suprised by these results. 如果您有索引,那么这些结果会让我有些惊讶。 It would also help if you posted exact figures about the table (column widths), as well as exactly what results you saw instead of "X, Y and Z". 如果您发布有关表格的准确数字(列宽),以及确切看到的结果而不是“ X,Y和Z”,这也将有所帮助。 And as always, when checking for performance issues look at the query plan . 与往常一样,在检查性能问题时,请查看查询计划

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM