summaryrefslogtreecommitdiff
path: root/jstests/orr.js
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2012-07-13 15:00:39 -0700
committerAaron <aaron@10gen.com>2012-07-13 16:44:08 -0700
commit6bea062f70ef5593a9510e17bc1dbdda6f631ce5 (patch)
treee3fe467ad191ce848f852acb718a7b6bd8ec3848 /jstests/orr.js
parentab4fd6ec2a704bacf48ab6c93bf15a7b4f588c0d (diff)
downloadmongo-6bea062f70ef5593a9510e17bc1dbdda6f631ce5.tar.gz
SERVER-6416 Compute field ranges for singleton $or clauses.
Diffstat (limited to 'jstests/orr.js')
-rw-r--r--jstests/orr.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/jstests/orr.js b/jstests/orr.js
new file mode 100644
index 00000000000..7d04f2ab1f4
--- /dev/null
+++ b/jstests/orr.js
@@ -0,0 +1,35 @@
+// Index bounds within a singleton $or expression can be used with sorting. SERVER-6416 SERVER-1205
+
+t = db.jstests_orr;
+t.drop();
+
+function assertIndexBounds( bounds, query, sort, hint ) {
+ cursor = t.find( query ).sort( sort );
+ if ( hint ) {
+ cursor.hint( hint );
+ }
+ assert.eq( bounds, cursor.explain().indexBounds.a );
+}
+
+t.ensureIndex( { a:1 } );
+
+// Tight index bounds for a singleton $or expression with an indexed sort.
+assertIndexBounds( [[ 1, 1 ]], { $or:[ { a:1 } ] }, { a:1 } );
+
+// Tight index bounds for a nested singleton $or expression with an indexed sort.
+assertIndexBounds( [[ 1, 1 ]], { $or:[ { $or:[ { a:1 } ] } ] }, { a:1 } );
+
+// No index bounds computed for a non singleton $or expression with an indexed sort.
+assertIndexBounds( [[ { $minElement:1 }, { $maxElement:1 } ]], { $or:[ { a:1 }, { a:2 } ] },
+ { a:1 } );
+
+// Tight index bounds for a singleton $or expression with an unindexed sort.
+assertIndexBounds( [[ 1, 1 ]], { $or:[ { a:1 } ] }, { b:1 } );
+
+// No index bounds computed for a non singleton $or expression and an unindexed sort, so a $natural
+// plan is used.
+assertIndexBounds( undefined, { $or:[ { a:1 }, { a:2 } ] }, { b:1 } );
+
+// No index bounds computed for a non singleton $or expression with an unindexed sort.
+assertIndexBounds( [[ { $minElement:1 }, { $maxElement:1 } ]], { $or:[ { a:1 }, { a:2 } ] },
+ { b:1 }, { a:1 } );