~ubuntu-branches/ubuntu/utopic/mongodb/utopic

« back to all changes in this revision

Viewing changes to jstests/aggregation/bugs/server6192_server6193.js

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-07-03 09:23:46 UTC
  • mfrom: (1.3.10) (44.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20140703092346-c5bvt46wnzougyly
Tags: 1:2.6.3-0ubuntu1
* New upstream stable release:
  - Dropped patches, included upstream:
    + 0003-All-platforms-but-Windows-find-hash-in-std-tr1.patch
    + 0008-Use-system-libstemmer.patch
    + 0011-Use-a-signed-char-to-store-BSONType-enumerations.patch
    + 0001-SERVER-12064-Atomic-operations-for-gcc-non-Intel-arc.patch
    + 0002-SERVER-12065-Support-ARM-and-AArch64-builds.patch
  - d/p/*: Refreshed/rebased remaining patches.
  - Use system provided libyaml-cpp:
    + d/control: Add libyaml-cpp-dev to BD's.
    + d/rules: Enable --with-system-yaml option.
    + d/p/fix-yaml-detection.patch: Fix detection of libyaml-cpp library.
  - d/mongodb-server.mongodb.upstart: Sync changes from upstream.
  - d/control,mongodb-dev.*: Drop mongodb-dev package; it has no reverse
    dependencies and upstream no longer install header files.
  - d/NEWS: Point users to upstream upgrade documentation for upgrades
    from 2.4 to 2.6.
* Merge from Debian unstable.
* d/control: BD on libv8-3.14-dev to ensure that transitioning to new v8
  versions is a explicit action due to changes in behaviour in >= 3.25
  (LP: #1295723).
* d/mongodb-server.prerm: Dropped debug echo call from maintainer script
  (LP: #1294455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// test short-circuiting of $and and $or in
 
2
// $project stages to a $const boolean
 
3
 
 
4
var t = db.jstests_aggregation_server6192;
 
5
t.drop();
 
6
t.save( {x: true} );
 
7
 
 
8
function assertOptimized(pipeline, v) {
 
9
    var explained = t.runCommand("aggregate", {
 
10
        pipeline: pipeline,
 
11
        explain: true
 
12
    });
 
13
 
 
14
    printjson({input: pipeline, output: explained});
 
15
 
 
16
    assert("stages" in explained);
 
17
    assert("$project" in explained.stages[1]);
 
18
    var projectStage = explained.stages[1]["$project"];
 
19
    assert.eq(projectStage.a["$const"], v, "ensure short-circuiting worked");
 
20
}
 
21
 
 
22
function assertNotOptimized(pipeline) {
 
23
    var explained = t.runCommand("aggregate", {
 
24
        pipeline: pipeline,
 
25
        explain: true
 
26
    });
 
27
 
 
28
    printjson({input: pipeline, output: explained});
 
29
 
 
30
    assert("stages" in explained);
 
31
    assert("$project" in explained.stages[1]);
 
32
    var projectStage = explained.stages[1]["$project"];
 
33
    assert(!("$const" in projectStage.a), "ensure no short-circuiting");
 
34
}
 
35
 
 
36
// short-circuiting for $and
 
37
assertOptimized([ {$project: {a: {$and: [0, '$x']}}} ], false);
 
38
assertOptimized([ {$project: {a: {$and: [0, 1, '$x']}}} ], false);
 
39
assertOptimized([ {$project: {a: {$and: [0, 1, '', '$x']}}} ], false);
 
40
 
 
41
assertOptimized([ {$project: {a: {$and: [1, 0, '$x']}}} ], false);
 
42
assertOptimized([ {$project: {a: {$and: [1, '', 0, '$x']}}} ], false);
 
43
assertOptimized([ {$project: {a: {$and: [1, 1, 0, 1]}}} ], false);
 
44
 
 
45
// short-circuiting for $or
 
46
assertOptimized([ {$project: {a: {$or: [1, '$x']}}} ], true);
 
47
assertOptimized([ {$project: {a: {$or: [1, 0, '$x']}}} ], true);
 
48
assertOptimized([ {$project: {a: {$or: [1, '', '$x']}}} ], true);
 
49
 
 
50
assertOptimized([ {$project: {a: {$or: [0, 1, '$x']}}} ], true);
 
51
assertOptimized([ {$project: {a: {$or: ['', 0, 1, '$x']}}} ], true);
 
52
assertOptimized([ {$project: {a: {$or: [0, 0, 0, 1]}}} ], true);
 
53
 
 
54
// examples that should not short-circuit
 
55
assertNotOptimized([ {$project: {a: {$and: [1, '$x']}}} ]);
 
56
assertNotOptimized([ {$project: {a: {$or: [0, '$x']}}} ]);
 
57
assertNotOptimized([ {$project: {a: {$and: ['$x', '$x']}}} ]);
 
58
assertNotOptimized([ {$project: {a: {$or: ['$x', '$x']}}} ]);
 
59
assertNotOptimized([ {$project: {a: {$and: ['$x']}}} ]);
 
60
assertNotOptimized([ {$project: {a: {$or: ['$x']}}} ]);
 
61