Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-83524

Enable indexed plans for expressions with $$NOW, $$CLUSTER_TIME, and $$USER_ROLES

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0, 8.0.0-rc9
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • Fully Compatible
    • v8.0, v7.3
    • QE 2024-05-13, QE 2024-05-27, QE 2024-06-10, QO 2024-06-24

      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

            Assignee:
            ben.shteinfeld@mongodb.com Ben Shteinfeld
            Reporter:
            steve.tarzia@mongodb.com Steve Tarzia
            Votes:
            1 Vote for this issue
            Watchers:
            26 Start watching this issue

              Created:
              Updated:
              Resolved: