作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个这样的表:
// mytable
+----+-------+---------+
| id | name | code |
+----+-------+---------+
| 1 | jack | 1 |
| 2 | acton | 1 |
| 3 | aiken | 1 |
| 4 | peter | null |
| 5 | ash | null |
| 6 | fabia | 2 |
| 7 | ubon | null |
| 8 | taavi | null |
| 9 | wade | 2 |
| 10 | ian | 1 |
+----+-------+---------+
我想选择id
为4的行。这是我的查询:
select * from mytable where id = 4
我还知道该行的 code
值为 null
。现在我想知道,如果我添加这个...并且code = null
会提高搜索速度吗?
最佳答案
如果添加:
and code = null
那么您将不会返回任何行,因为 = null
始终返回 null
。 where
过滤掉值不为 true 的行。
相反,你会:
and code is null
据推测,id
上有一个索引(所有主键都有一个索引)。如果是这样,SQL 引擎可能会在获取该行后再进行一次比较,以确保 code
与条件匹配。考虑到获取数据的所有其他工作,这是非常非常可以忽略不计的。包含附加条件很可能不会对性能产生明显影响。
关于mysql - 增加WHERE子句的条件会提高搜索速度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34482719/
我是一名优秀的程序员,十分优秀!