2

我有一个这样的查询:

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 否认了一些优化,但我不完全确定。

4

1 回答 1

1

您对 Table_b 中的字段有索引吗?如果它在连接索引中,请确保它是第一个。

于 2012-03-06T21:19:19.100 回答