Details
-
Improvement
-
Resolution: Unresolved
-
Major - P3
-
None
-
None
-
None
-
None
-
Query Optimization
Description
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.