Question

Does the order of the values in a WHERE IN clause matter? (this is on Firebird SQL if that is important)

Such as does:

where field1 in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

offer a performance increase over

where field1 in (3, 5, 10, 2, 1, 8, 6, 9, 4, 7)
Was it helpful?

Solution

Yes it will, but possibly in an implementation dependent manner. The IN is processed as sequential OR's, and one might assume that the most likely processing order is as written.

That said, I would start by assuming that the optimizer will process the elements in the order given, because that is easiest, and rank them in the set from most- to least-likely. It can't hurt, and will most probably help. Whether the difference is measurable or significant is another matter; measure it and let us know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top