Reputation: 1931
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.
Upvotes: 2
Views: 1255
Reputation: 5145
do you have an index on Field in Table_b? If it is in a concatenated index, make sure it is the first one.
Upvotes: 1