summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2018-12-13 10:59:25 -0500
committerCharlie Swanson <charlie.swanson@mongodb.com>2018-12-20 14:08:33 -0500
commitef51ce0672dde933164fba1fc4f7ecf53c77b378 (patch)
tree7608ee73b0ad6b1da6852a92c7590bd49dc1abb5 /jstests
parent9aafd59034c627b4a4cbda492bce3cc6cbef7b9a (diff)
downloadmongo-ef51ce0672dde933164fba1fc4f7ecf53c77b378.tar.gz
SERVER-38601 Add regression test for SERVER-35455
(cherry picked from commit 5b736830826eca2cc36f4c6e2ebbcaf524e9c5e0) (cherry picked from commit 8b4693170a7e5f640057a8532a9f92753ff3fb99) (cherry picked from commit e4a68bba3602f5e295d6e2949cc4db749e752d27)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/contained_or_with_nested_or.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/jstests/core/contained_or_with_nested_or.js b/jstests/core/contained_or_with_nested_or.js
new file mode 100644
index 00000000000..93963434617
--- /dev/null
+++ b/jstests/core/contained_or_with_nested_or.js
@@ -0,0 +1,41 @@
+// This test was designed to reproduce a memory leak that was fixed by SERVER-35455.
+(function() {
+ "use strict";
+
+ const coll = db.contained_or_with_nested_or;
+ coll.drop();
+ assert.writeOK(coll.insert([
+ // Should not match the query:
+ {_id: 0, active: false, loc: "USA", agency: "FBI", vip: false},
+ {_id: 1, active: false, loc: "RUS", agency: "OTHER", vip: true},
+ {_id: 2, active: true, loc: "RUS", agency: "OTHER", vip: false},
+ {_id: 3, active: true, loc: "USA", agency: "OTHER", vip: false},
+ {_id: 4, active: true, loc: "UK", agency: "OTHER", vip: false},
+ {_id: 5, active: true, loc: "UK", agency: "OTHER", vip: true},
+ {_id: 6, active: true},
+ // Should match the query:
+ {_id: 7, active: true, loc: "USA", agency: "FBI", vip: false},
+ {_id: 8, active: true, loc: "USA", agency: "CIA", vip: true},
+ {_id: 9, active: true, loc: "RUS", agency: "OTHER", vip: true},
+ {_id: 10, active: true, loc: "RUS", agency: "KGB"},
+ ]));
+ assert.commandWorked(coll.createIndexes([{loc: 1}, {agency: 1}, {vip: 1}]));
+
+ // The following query reproduced the memory leak described in SERVER-38601. To catch a
+ // regression, we would only expect this test to fail on ASAN variants. Before SERVER-35455 we
+ // would construct a plan for one clause of the $or, then realize that the other clause could
+ // not be indexed and discard the plan for the first clause in a way that leaks memory.
+ const results = coll.find({
+ active: true,
+ $or: [
+ {loc: "USA", $or: [{agency: "FBI"}, {vip: true}]},
+ {loc: "RUS", $or: [{agency: "KGB"}, {vip: true}]}
+ ]
+ })
+ .toArray();
+
+ // Just assert on the matching _ids. We avoid adding a sort to the query above to avoid
+ // restricting the plans the query planner can consider.
+ const matchingIds = results.map(result => result._id).sort((x, y) => x - y);
+ assert.eq(matchingIds, [7, 8, 9, 10], tojson(matchingIds));
+}());