0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-28 07:59:02 +01:00

SERVER-17158 add delimiter to planCacheKey for sort args

Closes #938

Signed-off-by: David Storch <david.storch@10gen.com>
This commit is contained in:
james.wahlin@10gen.com 2015-03-18 15:45:05 -04:00 committed by David Storch
parent 2c6ab1eaae
commit 879f306b22
2 changed files with 20 additions and 3 deletions

View File

@ -205,9 +205,21 @@ namespace {
// Sort query should generate different key from unsorted query.
ASSERT_OK(PlanCacheCommand::canonicalize(&txn, ns,
fromjson("{query: {a: 1, b: 1}, sort: {a: 1}}"), &cqRaw));
scoped_ptr<CanonicalQuery> sortQuery(cqRaw);
ASSERT_NOT_EQUALS(query->getPlanCacheKey(), sortQuery->getPlanCacheKey());
fromjson("{query: {a: 1, b: 1}, sort: {a: 1, b: 1}}"), &cqRaw));
scoped_ptr<CanonicalQuery> sortQuery1(cqRaw);
ASSERT_NOT_EQUALS(query->getPlanCacheKey(), sortQuery1->getPlanCacheKey());
// Confirm sort arguments are properly delimited (SERVER-17158)
ASSERT_OK(PlanCacheCommand::canonicalize(&txn, ns,
fromjson("{query: {a: 1, b: 1}, sort: {aab: 1}}"), &cqRaw));
scoped_ptr<CanonicalQuery> sortQuery2(cqRaw);
ASSERT_NOT_EQUALS(sortQuery1->getPlanCacheKey(), sortQuery2->getPlanCacheKey());
// Changing order and/or value of predicates should not change key
ASSERT_OK(PlanCacheCommand::canonicalize(&txn, ns,
fromjson("{query: {b: 3, a: 3}, sort: {a: 1, b: 1}}"), &cqRaw));
scoped_ptr<CanonicalQuery> sortQuery3(cqRaw);
ASSERT_EQUALS(sortQuery1->getPlanCacheKey(), sortQuery3->getPlanCacheKey());
// Projected query should generate different key from unprojected query.
ASSERT_OK(PlanCacheCommand::canonicalize(&txn, ns,

View File

@ -275,6 +275,11 @@ namespace {
*os << "d";
}
encodeUserString(elt.fieldName(), os);
// Sort argument separator
if (it.more()) {
*os << ",";
}
}
}