In SBE plan cache key, we encode the number of elements in $in in it:
This is done because of explode for sort SBE plan will have the number of branches equal to the number of elements in $in.
However, this will lead to worse plan caching even for queries, where is no plan caching.
It is a fact that we have users that use $in's with arbitrary amount of elements from 1 to thousands.
Also, if a query have multiple $ins, it may lead to exponential growth.
One suggestion is instead of generating a unique plan for every $in size when exploding for sort, we can generate plans for all powers of 2 (or 4) and use the smallest plan that can fit all $in values.
- is related to
-
SERVER-82548 MongoDB 7.0.2 SBE selects a different index when doing $in with a large array
- Closed
-
SERVER-84728 Allow MatchExpression $or -> $in rewrite to preserve parameters
- Backlog
- related to
-
SERVER-88892 Consider removing exact number of elements in $in from plan cache key
- Open
-
SERVER-83777 Cap $in length in plan cache key with internalQueryMaxScansToExplode + 1
- Closed