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

Support internal expr comparison operators when determining clustered collection scan bounds

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.3.0-rc0, 7.0.13, 6.0.17
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • Fully Compatible
    • v7.0, v6.0
    • QO 2023-12-11

      Currently, query on clustered collection will not use the index

      db.coll.find({$expr: {$gt: ["$_id", <..>]}})
      

       

      However, same syntax with a secondary index will work.

      Because of slight semantic difference between match $gt and aggregation $gt
      (match does type-bracketing, aggregation uses the specified BSON comparison order for values of different types), we have two sets of comparison match expressions:
       regular ones like $gt and $_internalExprGt which use slightly different logic.

      When computing bounds for secondary index scan, $_internalExpr* operators are supported, however, they are not supported in clustered collection scan bounds:
      https://github.com/mongodb/mongo/blob/bc654c2bf5fb81d7767c1c25aa09628fc5de90a8/src/mongo/db/query/planner_access.cpp#L449

      There might be a reason for it, because of semantic difference, so we need to either fix it by adding internal expr comparison operations to the code, linked about, or add a comment about why we can't do it.

            Assignee:
            james.harrison@mongodb.com James Harrison
            Reporter:
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved: