我有一个这样的查询:
SELECT *
FROM table_a
LEFT JOIN table_b ON table_a.id_a = table_b.id_a
WHERE
table_b.field = 'something' OR table_b.field IS NULL
我想要 table_b.field = 'something' 的记录,或者 table_b 中没有 table_a 行记录的记录。当我添加 IS NULL 时,查询需要大约 60 秒才能执行,而没有它则需要 0.4 秒。
任何人都可以解释这种行为吗?我认为 IS NULL 否认了一些优化,但我不完全确定。