90% of a simple select is overhead (network, parsing, optimizing, etc).
id = 123 OR id = 345
is optimized to id IN (123, 345)
. If there is an index on id
(the PRIMARY KEY
is an index), this is 2 probes into the table.
So if fetching one row is 100% of effort, then fetching 2 is about 110% of that (90% overhead, then 2 units of real work).
Meanwhile, 2 separate selects would be 200%.
On the other hand, if you have
WHERE x = 98 OR y = 65
there is no good indexing method for such.
Plan A: A full table scan, checking x and y for every row. Really slow for a big table.
Plan B: Change it to
( SELECT ... WHERE x = 98 )
UNION
( SELECT ... WHERE y = 65 )
This will be more like 200%. That is, making two queries helps in this case.
Plan C is "index merge union", which the Optimizer only occasionally resorts to.