三值逻辑
三值的谓词:
谓词求值后有三个元素{T,F,U}
,也就是true
, false
, 和unknow
求值和谓词
SELECT 1=NULL
在mysql , 这个会返回一行,这行是值是null
① 然后根据规范 where
case
和having
子句都只取三值逻辑真值中的true
SELECT 1 NOT IN (1, NULL) ## false 所以不会被条件筛选出来
SELECT 1 NOT IN ( NULL) ## null , 因为上面的规则①所以也不会被筛选出来
所以在where
子句中使用not in
而not int
中包含null
的时候会筛选不出来
exist
规范规定exist是个二值函数,所以要映射成true
或者false
, mysql中则是只要返回一行真值就是true
- 相关阅读 http://www.vldb.org/conf/1987/P235.PDF https://dl.acm.org/doi/10.1145/111197.111212 https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#operator_not-in https://modern-sql.com/concept/three-valued-logic#footnote-0 论文 SQL’s Three-Valued Logic and Certain Answers