This code from SERVER-74264 disabled constant folding for expressions involving $$NOW, $$CLUSTER_TIME, or $$USER_ROLES. This prevents some relatively simple queries from being satisfied by an index. For example:
db.coll.find({"$expr": {"$lt": ["$_ts",
{"$subtract": ["$$NOW",604800]}]}})
will lead to a collection scan even if there is an index on the _ts field.
We should find a way to build an IXSCAN plan for such queries while still avoiding the plan cache bug fixed by SERVER-74264.
Note that this was inspired by HELP-52526 for a query generated by online archive.
This was also hit by HELP-59541, with an associated server ticket SERVER-89783.
- is caused by
-
SERVER-74264 Incorrect $$NOW behavior in projection of find
- Closed
- is duplicated by
-
SERVER-89783 $expr not using indices in $match stage
- Closed
- related to
-
SERVER-87218 Improve index usage for constants inside of `let`
- Closed
-
SERVER-91625 [v7.0] Enable indexed plans for expressions with $$NOW, $$CLUSTER_TIME and $$USER_ROLES
- Closed
-
SERVER-91535 Ensure plans cached in SBE plan cache allow indexed plans for predicates referencing system variables
- Needs Scheduling