[SERVER-41992] $setIntersection with null and empty intersections violates commutativity Created: 27/Jun/19  Updated: 29/Oct/23  Resolved: 23/Jul/19

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 4.3.1

Type: Bug Priority: Major - P3
Reporter: Claire Childs (Inactive) Assignee: George Wangensteen
Resolution: Fixed Votes: 0
Labels: afz, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Related
is related to SERVER-36698 Add suite for agg expr fuzzer optimiz... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.2
Steps To Reproduce:

python buildscripts/resmoke.py --storageEngine wiredTiger --suites aggregation repro_set_intersection.js

repro_set_intersection.js

assert.commandWorked(db.my_coll.insert({ a: []}));
const res1 = db.my_coll
                 .aggregate([{
                     $project: {
                         a: {
                             $setIntersection: [
                                 "$a",
                                 "$missing",
                             ]
                         },
                         _id: 0,
                     }
                 }])
                 .toArray();
const res2 = db.my_coll
                 .aggregate([{
                     $project: {
                         a: {
                             $setIntersection: [
                                 "$missing",
                                 "$a",
                             ]
                         },
                         _id: 0,
                     }
                 }])
                 .toArray();
assert.eq(res1, res2);

 

Sprint: Query 2019-07-15, Query 2019-07-29
Participants:
Linked BF Score: 0

 Description   

When $setIntersection is evaluated, if a nullish expression is encountered first then null is returned. If instead the intersection becomes empty, then an empty array is returned. This means that changing the order of the operands changes the result, invalidating commutativity.

[js_test:repro] 2019-06-27T17:23:27.757-0400 2019-06-27T17:23:27.755-0400 E QUERY [js] uncaught exception: Error: [[ \{ "a" : [ ] } ]] != [[ \{ "a" : null } ]] are not equal :
[js_test:repro] 2019-06-27T17:23:27.757-0400 doassert@src/mongo/shell/assert.js:20:14
[js_test:repro] 2019-06-27T17:23:27.757-0400 assert.eq@src/mongo/shell/assert.js:180:9
[js_test:repro] 2019-06-27T17:23:27.757-0400 @repro.js:30:1
[js_test:repro] 2019-06-27T17:23:27.757-0400 2019-06-27T17:23:27.755-0400 F - [main] failed to load: repro.js
[js_test:repro] 2019-06-27T17:23:27.757-0400 2019-06-27T17:23:27.755-0400 E - [main] exiting with code -3



 Comments   
Comment by Githook User [ 23/Jul/19 ]

Author:

{'name': 'George Wangensteen', 'email': 'george.wangensteen@10gen.com'}

Message: SERVER-41992 Fix $setIntersection so it is commutative with null and empty arguments.
Branch: master
https://github.com/mongodb/mongo/commit/6f2e0facc4a5cb406af096d6ad85b5616ddd73d3

Comment by David Storch [ 27/Jun/19 ]

Great find claire.childs!

Generated at Thu Feb 08 04:59:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.