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

Several aggregation pipeline operators are not commutative when inputs are null and invalid

    XMLWordPrintable

Details

    • ALL
    • Hide

      db.example.aggregate( [ { $project: {A: 1, acc :

      { $setIntersection: [null, "string"]}

      }
      (executes cleanly)

      db.example.aggregate( [ { $project: {A: 1, acc :

      { $setIntersection: ["string", null]}

      }
      (throws an exception)  

      The same behavior holds if $setIntersection is replaced with $add, $multiply, etc.

      Show
      db.example.aggregate( [ { $project: {A: 1, acc : { $setIntersection: [null, "string"]} } (executes cleanly) db.example.aggregate( [ { $project: {A: 1, acc : { $setIntersection: ["string", null]} } (throws an exception)   The same behavior holds if $setIntersection is replaced with $add, $multiply, etc .

    Description

      While working on SERVER-41992, which found that $setIntersection was not commutative on null and empty inputs, it became apparent that $setIntersection was also not commutative on null and invalid inputs. If a null input came first, the operation would return null but exit cleanly; if an invalid input came first, the operation would throw. We also noticed that $setIntersection is far from the only agg operator with this problem: see for example $add or $multiply

      This seemed problematic because it means that, in an operation we report is commutative, the user might have their aggregation pipeline exit cleanly, or might have it fail due to an exception, depending only on the order of arguments. Even on non-commutative operations, this behavior might be confusing to users; it masks certain instances of invalid input depending on if an argument before the invalid input is null. It also is confusing as a general inconsistency: should users expect all agg operators that are passed anything null to return null, even if other input is invalid, or should they always throw when any input is invalid?

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            george.wangensteen@mongodb.com George Wangensteen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: