I have a simple SELECT
query:
SELECT * FROM MyTable
WHERE ParentId IN (0, 1) OR ParentId IS NULL
ORDER BY SortColumn
LIMIT 0, 2048;
Why is it that this query runs 10x slower when I write WHERE ParentId IN (1)
instead of (0, 1)
?
The query runs faster whether it finds the second id or not.
Edit:
It looks like running the query checking for 1 element and without the OR ParentId IS NULL
runs just as fast as running the query checking for multiple elements.
ParentId
is a foreign key to another column and therefore indexed.
Why would this matter so much?