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

Boolean simplifier causes problems on upsert

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0, 7.3.4, 8.0.0-rc10
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • Fully Compatible
    • v8.0, v7.3
    • 200

      update operation with upsert: true upserts a new document if the filter does not match any documents. The new document is the combination of fields from the filter and the update expressions. The query engine ignores any fields in the filter which are behind negations ($nor, $not). However, the Boolean simplifier, introduced in 7.3, can simplify such expressions and remove some negations.

      Let's take a look at the filter expression with root $nor:

      {$nor: [{$or: [{"x": 1}, {"y": 2}]}, {"x": {$ne: 3}}]}
      

      since everything is behind $nor the query engine cannot extract any field values for the document to upsert. However, the Boolean simplifier will simplify such expression to

      {x: {$eq: 3, $ne: 1}, y: {$ne: 2}}
      

      Now the query engine can extract

      {x: 3}

      for the document to upsert. This brings the issue of inconsistent behaviour depending on whether the simplifier enabled or not, which is incorrect since the simplifier shouldn't change the query's semantics. We decided to disable the simplifier for upsert operations until we come up the better solution.

            Assignee:
            alexander.ignatyev@mongodb.com Alexander Ignatyev
            Reporter:
            alexander.ignatyev@mongodb.com Alexander Ignatyev
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: