diff options
author | Ian Boros <ian.boros@10gen.com> | 2018-03-26 18:19:05 -0400 |
---|---|---|
committer | Ian Boros <ian.boros@10gen.com> | 2018-03-26 18:19:05 -0400 |
commit | 6e0fb3da005b6fbe14b30c28bf3a148412635150 (patch) | |
tree | 367d25b97bac4fcab937f1c642da6ff47bb2c433 /jstests/core/explain_count.js | |
parent | f1b3e32355e84b1c2ad39cffab2e6e619a474e9d (diff) | |
download | mongo-6e0fb3da005b6fbe14b30c28bf3a148412635150.tar.gz |
Revert 0c082a81047cee66821e295d02e3588f7934ff64: SERVER-3645
Diffstat (limited to 'jstests/core/explain_count.js')
-rw-r--r-- | jstests/core/explain_count.js | 54 |
1 files changed, 8 insertions, 46 deletions
diff --git a/jstests/core/explain_count.js b/jstests/core/explain_count.js index d494a0c0584..a8001ef0b7f 100644 --- a/jstests/core/explain_count.js +++ b/jstests/core/explain_count.js @@ -15,48 +15,12 @@ function checkCountScanIndexExplain(explain, startKey, endKey, startInclusive, e assert.eq(countStage.stage, "COUNT_SCAN"); assert("indexBounds" in countStage); - assert.eq(countStage.indexBounds.startKey, startKey); - assert.eq(countStage.indexBounds.endKey, endKey); + assert.eq(bsonWoCompare(countStage.indexBounds.startKey, startKey), 0); + assert.eq(bsonWoCompare(countStage.indexBounds.endKey, endKey), 0); assert.eq(countStage.indexBounds.startKeyInclusive, startInclusive); assert.eq(countStage.indexBounds.endKeyInclusive, endInclusive); } -/** - * Ensure that the SHARDING_FILTER's child stage is an IXSCAN (and not a fetch). This is to ensure - * sharded clusters can still run the count command with a predicate on indexed fields reasonably - * fast. Assumes that the shard key is part of the index. - */ -function checkShardingFilterIndexScanExplain(explain, keyName, bounds) { - var filterStage = getPlanStage(explain.executionStats.executionStages, "SHARDING_FILTER"); - - assert.eq(filterStage.stage, "SHARDING_FILTER"); - const ixScanStage = filterStage.inputStage; - assert.eq(ixScanStage.stage, "IXSCAN"); - assert("indexBounds" in ixScanStage); - - assert.eq(ixScanStage.indexBounds[keyName].length, 1); - const expectedBoundsArr = JSON.parse(ixScanStage.indexBounds[keyName][0]); - assert.eq(expectedBoundsArr, bounds); -} - -/** - * Check that the explain from a count command run on a collection with a usable index for the - * predicate produces a reasonable plan. On sharded collections, we expect to have an IXSCAN - * followed by a SHARDING_FILTER. Otherwise, the COUNT_SCAN stage should be used. - */ -function checkIndexedCountWithPred(db, explain, keyName, bounds) { - assert.eq(bounds.length, 2); - if (isMongos(db) && FixtureHelpers.isSharded(db[collName])) { - // On sharded collections we have a SHARDING_FILTER with a child that's an IXSCAN. - checkShardingFilterIndexScanExplain(explain, keyName, bounds); - } else { - // On a standalone we just do a COUNT_SCAN over the {a: 1, _id: 1} index. - const min = {a: bounds[0], _id: {"$minKey": 1}}; - const max = {a: bounds[1], _id: {"$maxKey": 1}}; - checkCountScanIndexExplain(explain, min, max, true, true); - } -} - // Collection does not exist. assert.eq(0, t.count()); var explain = db.runCommand({explain: {count: collName}, verbosity: "executionStats"}); @@ -86,9 +50,7 @@ explain = db.runCommand( assertExplainCount({explainResults: explain, expectedCount: 0}); // Now add a bit of data to the collection. -// On sharded clusters, we'll want the shard key to be indexed, so we make _id part of the index. -// This means counts will not have to fetch from the document in order to get the shard key. -t.ensureIndex({a: 1, _id: 1}); +t.ensureIndex({a: 1}); for (var i = 0; i < 10; i++) { t.insert({_id: i, a: 1}); } @@ -123,21 +85,21 @@ assertExplainCount({explainResults: explain, expectedCount: 3}); assert.eq(10, db.runCommand({count: collName, query: {a: 1}}).n); explain = db.runCommand({explain: {count: collName, query: {a: 1}}, verbosity: "executionStats"}); assertExplainCount({explainResults: explain, expectedCount: 10}); -checkIndexedCountWithPred(db, explain, "a", [1.0, 1.0]); +checkCountScanIndexExplain(explain, {a: 1}, {a: 1}, true, true); // With a query and skip. assert.eq(7, db.runCommand({count: collName, query: {a: 1}, skip: 3}).n); explain = db.runCommand( {explain: {count: collName, query: {a: 1}, skip: 3}, verbosity: "executionStats"}); assertExplainCount({explainResults: explain, expectedCount: 7}); -checkIndexedCountWithPred(db, explain, "a", [1.0, 1.0]); +checkCountScanIndexExplain(explain, {a: 1}, {a: 1}, true, true); // With a query and limit. assert.eq(3, db.runCommand({count: collName, query: {a: 1}, limit: 3}).n); explain = db.runCommand( {explain: {count: collName, query: {a: 1}, limit: 3}, verbosity: "executionStats"}); assertExplainCount({explainResults: explain, expectedCount: 3}); -checkIndexedCountWithPred(db, explain, "a", [1.0, 1.0]); +checkCountScanIndexExplain(explain, {a: 1}, {a: 1}, true, true); // Insert one more doc for the last few tests. t.insert({a: 2}); @@ -147,11 +109,11 @@ assert.eq(0, db.runCommand({count: collName, query: {a: 2}, skip: 2}).n); explain = db.runCommand( {explain: {count: collName, query: {a: 2}, skip: 2}, verbosity: "executionStats"}); assertExplainCount({explainResults: explain, expectedCount: 0}); -checkIndexedCountWithPred(db, explain, "a", [2, 2]); +checkCountScanIndexExplain(explain, {a: 2}, {a: 2}, true, true); // Case where we have a limit, but we don't hit it. assert.eq(1, db.runCommand({count: collName, query: {a: 2}, limit: 2}).n); explain = db.runCommand( {explain: {count: collName, query: {a: 2}, limit: 2}, verbosity: "executionStats"}); assertExplainCount({explainResults: explain, expectedCount: 1}); -checkIndexedCountWithPred(db, explain, "a", [2, 2]); +checkCountScanIndexExplain(explain, {a: 2}, {a: 2}, true, true); |