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

Express path can return incorrect results when scanning a unique, multi-field index

    • Query Execution
    • Fully Compatible
    • ALL
    • v8.0
    • None
    • 0
    • None
    • None
    • None
    • None
    • None
    • None

      Issue Status as of <April 8, 2025>

      ISSUE DESCRIPTION AND IMPACT

      On MongoDB Server version 8.0 - 8.0.4, it is possible under certain circumstances for a simple equality (non-_id) predicate query on sharded collections to report no results when a valid result exists.

      The bug can arise when all of the following are true:
      The query is executed on a sharded cluster with two or more shards running MongoDB versions 8.0 - 8.0.4
      The query is of the form:
      find({'fieldA':'value'}).limit(1) or
      aggregate([{$match: {'fieldA':'value'}},{$limit:1}])
      (where 'fieldA' is not the _id field)
      The sharded collection has a compound unique index that includes the field used in the query, for example, {key:{'fieldA':1,'fieldB':1}, unique:true}. And it doesn't have a unique index on just that one field, like {key:{'fieldA': 1}, unique:true }.
      While executing the query described above, the query engine may improperly apply an optimization. In certain circumstances involving the placement of orphaned documents, this may result in no documents being returned instead of one.
      DIAGNOSIS AND AFFECTED VERSIONS

      This bug affects users in 8.0 - 8.0.4.

      REMEDIATION AND WORKAROUNDS

      Customers are recommended to upgrade to 8.0.6. For MongoDB Atlas Customers, your Atlas 8.0 clusters will be upgraded automatically to the version containing the fix.

      Workaround exists without upgrading the cluster:
      Add a hint() to the affected query, which causes the fault path to be bypassed.
      Alternatively the user can set the query knob internalQueryDisableSingleFieldExpressExecutor to true to turn off the fault path for all non-_id queries.

      OTHER AFFECTED TOOLS

      —-----------------------------------------------------

      Original description

      I was looking at the eligibility checks for PlanExecutorExpress and noticed a bug. The express path should only support shard filtering for unique, single-field indexes (see SERVER-87016). This guarantees that the plan only reads a single key, which the shard filter may or may not filter out.
      However, I believe there is a bug where the express path would permit using a unique, multi-field index. Depending on the presence of orphans, this could lead to a situation where we produce incorrect query results

            Assignee:
            colin.stolley@mongodb.com Colin Stolley
            Reporter:
            hana.pearlman@mongodb.com Hana Pearlman
            Votes:
            0 Vote for this issue
            Watchers:
            19 Start watching this issue

              Created:
              Updated:
              Resolved: