i have a query that goes like this:

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

i want to have the records with table_b.field = 'something' or the ones where theres is no record in table_b for the row in table_a. when i add the IS NULL the query takes about 60 seconds to execute vs 0.4 seconds without it.

anyone can explain this behavior? i think the IS NULL denies some optimization, but im not completely sure.

有帮助吗?

解决方案

do you have an index on Field in Table_b? If it is in a concatenated index, make sure it is the first one.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top