summaryrefslogtreecommitdiff
path: root/jstests/queryoptimizera.js
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2012-06-05 19:50:34 +0200
committerAntonin Kral <a.kral@bobek.cz>2012-06-05 19:50:34 +0200
commit3703a282eca7e79e91f4bd651b1b861b76dc6c68 (patch)
treeb69552c69c48ebc6899f7bbbe42843793a423237 /jstests/queryoptimizera.js
parent61619b3142c1de8f60f91964ff2656054d4f11a6 (diff)
downloadmongodb-3703a282eca7e79e91f4bd651b1b861b76dc6c68.tar.gz
Imported Upstream version 2.0.6
Diffstat (limited to 'jstests/queryoptimizera.js')
-rw-r--r--jstests/queryoptimizera.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/jstests/queryoptimizera.js b/jstests/queryoptimizera.js
new file mode 100644
index 0000000..48d7ccf
--- /dev/null
+++ b/jstests/queryoptimizera.js
@@ -0,0 +1,87 @@
+// Check that a warning message about doing a capped collection scan for a query with an _id
+// constraint is printed at appropriate times. SERVER-5353
+
+function numWarnings() {
+ logs = db.adminCommand( { getLog:"global" } ).log
+ ret = 0;
+ logs.forEach( function( x ) {
+ if ( x.match( warningMatchRegexp ) ) {
+ ++ret;
+ }
+ } );
+ return ret;
+}
+
+collectionNameIndex = 0;
+
+// Generate a collection name not already present in the log.
+do {
+ testCollectionName = 'jstests_queryoptimizera__' + collectionNameIndex++;
+ warningMatchString = 'unindexed _id query on capped collection.*collection: test.' +
+ testCollectionName;
+ warningMatchRegexp = new RegExp( warningMatchString );
+
+} while( numWarnings() > 0 );
+
+t = db[ testCollectionName ];
+t.drop();
+
+notCappedCollectionName = testCollectionName + '_notCapped';
+
+notCapped = db[ notCappedCollectionName ];
+notCapped.drop();
+
+db.createCollection( testCollectionName, { capped:true, size:1000 } );
+db.createCollection( notCappedCollectionName, { autoIndexId:false } );
+
+t.insert( {} );
+notCapped.insert( {} );
+
+oldNumWarnings = 0;
+
+function assertNoNewWarnings() {
+ assert.eq( oldNumWarnings, numWarnings() );
+}
+
+function assertNewWarning() {
+ ++oldNumWarnings;
+ assert.eq( oldNumWarnings, numWarnings() );
+}
+
+// Simple _id query without an _id index.
+t.find( { _id:0 } ).itcount();
+assertNewWarning();
+
+// Simple _id query without an _id index, on a non capped collection.
+notCapped.find( { _id:0 } ).itcount();
+assertNoNewWarnings();
+
+// A multi field query, including _id.
+t.find( { _id:0, a:0 } ).itcount();
+assertNewWarning();
+
+// An unsatisfiable query.
+t.find( { _id:0, a:{$in:[]} } ).itcount();
+assertNoNewWarnings();
+
+// An hinted query.
+t.find( { _id:0 } ).hint( { $natural:1 } ).itcount();
+assertNoNewWarnings();
+
+// Retry a multi field query.
+t.find( { _id:0, a:0 } ).itcount();
+assertNewWarning();
+
+// Warnings should not be printed when an index is added on _id.
+t.ensureIndex( { _id:1 } );
+
+t.find( { _id:0 } ).itcount();
+assertNoNewWarnings();
+
+t.find( { _id:0, a:0 } ).itcount();
+assertNoNewWarnings();
+
+t.find( { _id:0, a:0 } ).itcount();
+assertNoNewWarnings();
+
+t.drop(); // cleanup