summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Zolnierz <nicholas.zolnierz@mongodb.com>2023-03-31 16:46:53 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-05 13:44:41 +0000
commitf1304cded1b4303f062bd81ee5c51d18a6e5d18e (patch)
tree420834e44ef7c410c633502dfb3ce14d4e4dc576
parentf46c0475a3c3572b3acf14683427f4c1f77beff1 (diff)
downloadmongo-f1304cded1b4303f062bd81ee5c51d18a6e5d18e.tar.gz
SERVER-75172 Use unique collection name in partial_index_logical.js
(cherry picked from commit 07356b01c414aed4de30dbce8744c3e8210f7a96) (cherry picked from commit 876525210b5dd638696d77e2d96d04456043828b)
-rw-r--r--jstests/core/partial_index_logical.js56
1 files changed, 28 insertions, 28 deletions
diff --git a/jstests/core/partial_index_logical.js b/jstests/core/partial_index_logical.js
index c2e09d57e53..893f01a25ec 100644
--- a/jstests/core/partial_index_logical.js
+++ b/jstests/core/partial_index_logical.js
@@ -22,55 +22,56 @@
load("jstests/libs/analyze_plan.js"); // For getPlanCacheKeyFromShape.
+const coll = db[jsTestName()];
+coll.drop();
(function partialIndexMixedFields() {
- db.test.drop();
+ coll.drop();
// Create enough competing indexes such that a query is eligible for caching (single plan
// queries are not cached).
- assert.commandWorked(
- db.test.createIndex({num: 1}, {partialFilterExpression: {num: 5, foo: 6}}));
- assert.commandWorked(db.test.createIndex({num: -1}));
- assert.commandWorked(db.test.createIndex({num: -1, not_num: 1}));
+ assert.commandWorked(coll.createIndex({num: 1}, {partialFilterExpression: {num: 5, foo: 6}}));
+ assert.commandWorked(coll.createIndex({num: -1}));
+ assert.commandWorked(coll.createIndex({num: -1, not_num: 1}));
- assert.commandWorked(db.test.insert([
+ assert.commandWorked(coll.insert([
{_id: 0, num: 5, foo: 6},
{_id: 1, num: 5, foo: 7},
]));
// Run a query which is eligible to use the {num: 1} index as it is covered by the partial
// filter expression.
- assert.eq(db.test.find({num: 5, foo: 6}).itcount(), 1);
- assert.eq(db.test.find({num: 5, foo: 6}).itcount(), 1);
+ assert.eq(coll.find({num: 5, foo: 6}).itcount(), 1);
+ assert.eq(coll.find({num: 5, foo: 6}).itcount(), 1);
const matchingKey =
- getPlanCacheKeyFromShape({query: {num: 5, foo: 6}, collection: db.test, db: db});
- assert.eq(1,
- db.test.aggregate([{$planCacheStats: {}}, {$match: {planCacheKey: matchingKey}}])
- .itcount());
+ getPlanCacheKeyFromShape({query: {num: 5, foo: 6}, collection: coll, db: db});
+ assert.eq(
+ 1,
+ coll.aggregate([{$planCacheStats: {}}, {$match: {planCacheKey: matchingKey}}]).itcount());
// This query should not be eligible for the {num: 1} index despite the path 'num' being
// compatible (per the plan cache key encoding).
- assert.eq(1, db.test.find({num: 5, foo: 7}).itcount());
+ assert.eq(1, coll.find({num: 5, foo: 7}).itcount());
const nonCoveredKey =
- getPlanCacheKeyFromShape({query: {num: 5, foo: 7}, collection: db.test, db: db});
- assert.eq(1,
- db.test.aggregate([{$planCacheStats: {}}, {$match: {planCacheKey: nonCoveredKey}}])
- .itcount());
+ getPlanCacheKeyFromShape({query: {num: 5, foo: 7}, collection: coll, db: db});
+ assert.eq(
+ 1,
+ coll.aggregate([{$planCacheStats: {}}, {$match: {planCacheKey: nonCoveredKey}}]).itcount());
// Sanity check that the generated keys are different due to the index compatibility.
assert.neq(nonCoveredKey, matchingKey);
})();
(function partialIndexConjunction() {
- db.test.drop();
+ coll.drop();
// Create enough competing indexes such that a query is eligible for caching (single plan
// queries are not cached).
assert.commandWorked(
- db.test.createIndex({num: 1}, {partialFilterExpression: {num: {$gt: 0, $lt: 10}}}));
- assert.commandWorked(db.test.createIndex({num: -1}));
- assert.commandWorked(db.test.createIndex({num: -1, not_num: 1}));
+ coll.createIndex({num: 1}, {partialFilterExpression: {num: {$gt: 0, $lt: 10}}}));
+ assert.commandWorked(coll.createIndex({num: -1}));
+ assert.commandWorked(coll.createIndex({num: -1, not_num: 1}));
- assert.commandWorked(db.test.insert([
+ assert.commandWorked(coll.insert([
{_id: 0},
{_id: 1, num: 1},
{_id: 2, num: 11},
@@ -78,17 +79,16 @@ load("jstests/libs/analyze_plan.js"); // For getPlanCacheKeyFromShape.
// Run a query which is eligible to use the {num: 1} index as it is covered by the partial
// filter expression.
- assert.eq(db.test.find({num: {$gt: 0, $lt: 10}}).itcount(), 1);
- assert.eq(db.test.find({num: {$gt: 0, $lt: 10}}).itcount(), 1);
+ assert.eq(coll.find({num: {$gt: 0, $lt: 10}}).itcount(), 1);
+ assert.eq(coll.find({num: {$gt: 0, $lt: 10}}).itcount(), 1);
const validKey =
- getPlanCacheKeyFromShape({query: {num: {$gt: 0, $lt: 10}}, collection: db.test, db: db});
+ getPlanCacheKeyFromShape({query: {num: {$gt: 0, $lt: 10}}, collection: coll, db: db});
assert.eq(
- 1,
- db.test.aggregate([{$planCacheStats: {}}, {$match: {planCacheKey: validKey}}]).itcount());
+ 1, coll.aggregate([{$planCacheStats: {}}, {$match: {planCacheKey: validKey}}]).itcount());
// The plan for the query above should now be in the cache and active. Now execute a query with
// a very similar shape, however the predicate parameters are not satisfied by the partial
// filter expression.
- assert.eq(2, db.test.find({num: {$gt: 0, $lt: 12}}).itcount());
+ assert.eq(2, coll.find({num: {$gt: 0, $lt: 12}}).itcount());
})();
})();