Remix.run Logo
▲ nathanfries 2 hours ago

Why can't consecutive OR statements with common columns be reduced to IN? (I say consecutive since I assume ordering matters).

WHERE id = 1 OR id = 2... Should be abled to be reduced to WHERE id IN (1,2...)

However WHERE id = 1 OR name = 'John' OR id = 2 Maybe can't be reduced to WHERE id IN (1,2) OR name = 'John'

▲moring 2 hours ago | parent [-]

Why does order of the OR operands matter?

▲nathanfries an hour ago | parent | next [-]

With a perfect optimizer and perfect knowledge of ordinality and statistics, I think performance would be the same. However in practice, I do not believe it always reorders predicates reliably for optimal performance.

My experience is that order does matter in MySQL and especially in DWH environments where the optimizer may not be aware of things like partitioning.

▲ 22 minutes ago | parent [-]
[deleted]
▲Riemer an hour ago | parent | prev [-]

OR short-circuiting, evaluation stops when one of the statements is true. So it might influence performance?

▲ 25 minutes ago | parent [-]
[deleted]