I have been looking into this issue and have a couple of conclussions.
- The timings are not completly right (on both cases), if you print your times you will see that the first takes 3400ms and the rest along the lines of 100ms. That's the regular expressions compiler at work.
- The issue is not the In operator, it is way more pervasive than that. The problem did exist in 2.5 too, however, given that the types of queries that we support in 2.5 is smaller the threshold is a bit higher.
- There is nothing I could cut from the QueryBuilder that would improve the situation to the point of the 2.5 behavior without tackling the underlying problem.
Therefore, I am changing the name of the issue to: "Improve the QueryBuilder with a different parsing model" because even if I could squeeze some milliseconds from here or there, the culprit is that it grows non linearly. Eventually the query will reach a threshold in size (easier when you use the IN operator) and start costing as you report.