summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2016-05-05 17:33:34 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2016-05-10 16:00:35 -0400
commit8f8043d6128813e9862b5a5c30a90d007d92c363 (patch)
treec5cf74eab1ad31f171b5fef90d39d4247df6b086 /src/mongo/db/commands
parent87f738623ffe55535fde1462cda5d9715893e713 (diff)
downloadmongo-8f8043d6128813e9862b5a5c30a90d007d92c363.tar.gz
SERVER-24045 Refactor CanonicalQuery::canonicalize()
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r--src/mongo/db/commands/find_cmd.cpp4
-rw-r--r--src/mongo/db/commands/geo_near_cmd.cpp7
-rw-r--r--src/mongo/db/commands/index_filter_commands.cpp9
-rw-r--r--src/mongo/db/commands/index_filter_commands_test.cpp35
-rw-r--r--src/mongo/db/commands/mr.cpp14
-rw-r--r--src/mongo/db/commands/plan_cache_commands.cpp8
-rw-r--r--src/mongo/db/commands/plan_cache_commands_test.cpp24
7 files changed, 63 insertions, 38 deletions
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index 13ba25eb033..7441c60c01e 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -147,7 +147,7 @@ public:
ExtensionsCallbackReal extensionsCallback(txn, &nss);
auto statusWithCQ =
- CanonicalQuery::canonicalize(txn, lpqStatus.getValue().release(), extensionsCallback);
+ CanonicalQuery::canonicalize(txn, std::move(lpqStatus.getValue()), extensionsCallback);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
@@ -232,7 +232,7 @@ public:
// Finish the parsing step by using the LiteParsedQuery to create a CanonicalQuery.
ExtensionsCallbackReal extensionsCallback(txn, &nss);
- auto statusWithCQ = CanonicalQuery::canonicalize(txn, lpq.release(), extensionsCallback);
+ auto statusWithCQ = CanonicalQuery::canonicalize(txn, std::move(lpq), extensionsCallback);
if (!statusWithCQ.isOK()) {
return appendCommandStatus(result, statusWithCQ.getStatus());
}
diff --git a/src/mongo/db/commands/geo_near_cmd.cpp b/src/mongo/db/commands/geo_near_cmd.cpp
index 392c0f58993..aeccd4a9c19 100644
--- a/src/mongo/db/commands/geo_near_cmd.cpp
+++ b/src/mongo/db/commands/geo_near_cmd.cpp
@@ -207,9 +207,12 @@ public:
BSONObj projObj = BSON("$pt" << BSON("$meta" << LiteParsedQuery::metaGeoNearPoint) << "$dis"
<< BSON("$meta" << LiteParsedQuery::metaGeoNearDistance));
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(rewritten);
+ lpq->setProj(projObj);
+ lpq->setLimit(numWanted);
const ExtensionsCallbackReal extensionsCallback(txn, &nss);
- auto statusWithCQ = CanonicalQuery::canonicalize(
- txn, nss, rewritten, BSONObj(), projObj, 0, numWanted, BSONObj(), extensionsCallback);
+ auto statusWithCQ = CanonicalQuery::canonicalize(txn, std::move(lpq), extensionsCallback);
if (!statusWithCQ.isOK()) {
errmsg = "Can't parse filter / create query";
return false;
diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp
index 961e34e4ccd..ab8c0634747 100644
--- a/src/mongo/db/commands/index_filter_commands.cpp
+++ b/src/mongo/db/commands/index_filter_commands.cpp
@@ -322,9 +322,12 @@ Status ClearFilters::clear(OperationContext* txn,
invariant(entry);
// Create canonical query.
- auto statusWithCQ = CanonicalQuery::canonicalize(
- txn, nss, entry->query, entry->sort, entry->projection, extensionsCallback);
- invariant(statusWithCQ.isOK());
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(entry->query);
+ lpq->setSort(entry->sort);
+ lpq->setProj(entry->projection);
+ auto statusWithCQ = CanonicalQuery::canonicalize(txn, std::move(lpq), extensionsCallback);
+ invariantOK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
// Remove plan cache entry.
diff --git a/src/mongo/db/commands/index_filter_commands_test.cpp b/src/mongo/db/commands/index_filter_commands_test.cpp
index 7015d32ec56..7f00a1521f4 100644
--- a/src/mongo/db/commands/index_filter_commands_test.cpp
+++ b/src/mongo/db/commands/index_filter_commands_test.cpp
@@ -118,13 +118,13 @@ void addQueryShapeToPlanCache(OperationContext* txn,
const char* queryStr,
const char* sortStr,
const char* projectionStr) {
- BSONObj queryObj = fromjson(queryStr);
- BSONObj sortObj = fromjson(sortStr);
- BSONObj projectionObj = fromjson(projectionStr);
-
// Create canonical query.
- auto statusWithCQ = CanonicalQuery::canonicalize(
- txn, nss, queryObj, sortObj, projectionObj, ExtensionsCallbackDisallowExtensions());
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(fromjson(queryStr));
+ lpq->setSort(fromjson(sortStr));
+ lpq->setProj(fromjson(projectionStr));
+ auto statusWithCQ =
+ CanonicalQuery::canonicalize(txn, std::move(lpq), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -146,13 +146,13 @@ bool planCacheContains(const PlanCache& planCache,
QueryTestServiceContext serviceContext;
auto txn = serviceContext.makeOperationContext();
- BSONObj queryObj = fromjson(queryStr);
- BSONObj sortObj = fromjson(sortStr);
- BSONObj projectionObj = fromjson(projectionStr);
-
// Create canonical query.
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(fromjson(queryStr));
+ lpq->setSort(fromjson(sortStr));
+ lpq->setProj(fromjson(projectionStr));
auto statusWithInputQuery = CanonicalQuery::canonicalize(
- txn.get(), nss, queryObj, sortObj, projectionObj, ExtensionsCallbackDisallowExtensions());
+ txn.get(), std::move(lpq), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithInputQuery.getStatus());
unique_ptr<CanonicalQuery> inputQuery = std::move(statusWithInputQuery.getValue());
@@ -167,13 +167,12 @@ bool planCacheContains(const PlanCache& planCache,
// Canonicalizing query shape in cache entry to get cache key.
// Alternatively, we could add key to PlanCacheEntry but that would be used in one place
// only.
- auto statusWithCurrentQuery =
- CanonicalQuery::canonicalize(txn.get(),
- nss,
- entry->query,
- entry->sort,
- entry->projection,
- ExtensionsCallbackDisallowExtensions());
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(entry->query);
+ lpq->setSort(entry->sort);
+ lpq->setProj(entry->projection);
+ auto statusWithCurrentQuery = CanonicalQuery::canonicalize(
+ txn.get(), std::move(lpq), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCurrentQuery.getStatus());
unique_ptr<CanonicalQuery> currentQuery = std::move(statusWithCurrentQuery.getValue());
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 56bd3f7fcf2..22597ba6d7c 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -1060,8 +1060,10 @@ void State::finalReduce(OperationContext* txn, CurOp* curOp, ProgressMeterHolder
const NamespaceString nss(_config.incLong);
const ExtensionsCallbackReal extensionsCallback(_txn, &nss);
- auto statusWithCQ =
- CanonicalQuery::canonicalize(txn, nss, BSONObj(), sortKey, BSONObj(), extensionsCallback);
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setSort(sortKey);
+
+ auto statusWithCQ = CanonicalQuery::canonicalize(txn, std::move(lpq), extensionsCallback);
verify(statusWithCQ.isOK());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -1422,10 +1424,14 @@ public:
unique_ptr<ScopedTransaction> scopedXact(new ScopedTransaction(txn, MODE_IS));
unique_ptr<AutoGetDb> scopedAutoDb(new AutoGetDb(txn, nss.db(), MODE_S));
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(config.filter);
+ lpq->setSort(config.sort);
+
const ExtensionsCallbackReal extensionsCallback(txn, &nss);
- auto statusWithCQ = CanonicalQuery::canonicalize(
- txn, nss, config.filter, config.sort, BSONObj(), extensionsCallback);
+ auto statusWithCQ =
+ CanonicalQuery::canonicalize(txn, std::move(lpq), extensionsCallback);
if (!statusWithCQ.isOK()) {
uasserted(17238, "Can't canonicalize query " + config.filter.toString());
return 0;
diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp
index f48c16dc268..440889255ba 100644
--- a/src/mongo/db/commands/plan_cache_commands.cpp
+++ b/src/mongo/db/commands/plan_cache_commands.cpp
@@ -209,10 +209,12 @@ StatusWith<unique_ptr<CanonicalQuery>> PlanCacheCommand::canonicalize(OperationC
// Create canonical query
const NamespaceString nss(ns);
+ auto lpq = stdx::make_unique<LiteParsedQuery>(std::move(nss));
+ lpq->setFilter(queryObj);
+ lpq->setSort(sortObj);
+ lpq->setProj(projObj);
const ExtensionsCallbackReal extensionsCallback(txn, &nss);
-
- auto statusWithCQ = CanonicalQuery::canonicalize(
- txn, std::move(nss), queryObj, sortObj, projObj, extensionsCallback);
+ auto statusWithCQ = CanonicalQuery::canonicalize(txn, std::move(lpq), extensionsCallback);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
diff --git a/src/mongo/db/commands/plan_cache_commands_test.cpp b/src/mongo/db/commands/plan_cache_commands_test.cpp
index ab811c7cf92..21cbc937e73 100644
--- a/src/mongo/db/commands/plan_cache_commands_test.cpp
+++ b/src/mongo/db/commands/plan_cache_commands_test.cpp
@@ -130,8 +130,10 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) {
auto txn = serviceContext.makeOperationContext();
// Create a canonical query
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(fromjson("{a: 1}"));
auto statusWithCQ = CanonicalQuery::canonicalize(
- txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
+ txn.get(), std::move(lpq), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -159,8 +161,10 @@ TEST(PlanCacheCommandsTest, planCacheClearAllShapes) {
auto txn = serviceContext.makeOperationContext();
// Create a canonical query
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(fromjson("{a: 1}"));
auto statusWithCQ = CanonicalQuery::canonicalize(
- txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
+ txn.get(), std::move(lpq), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -278,12 +282,16 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKey) {
auto txn = serviceContext.makeOperationContext();
// Create 2 canonical queries.
+ auto lpqA = stdx::make_unique<LiteParsedQuery>(nss);
+ lpqA->setFilter(fromjson("{a: 1}"));
auto statusWithCQA = CanonicalQuery::canonicalize(
- txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
+ txn.get(), std::move(lpqA), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQA.getStatus());
+ auto lpqB = stdx::make_unique<LiteParsedQuery>(nss);
+ lpqB->setFilter(fromjson("{b: 1}"));
unique_ptr<CanonicalQuery> cqA = std::move(statusWithCQA.getValue());
auto statusWithCQB = CanonicalQuery::canonicalize(
- txn.get(), nss, fromjson("{b: 1}"), ExtensionsCallbackDisallowExtensions());
+ txn.get(), std::move(lpqB), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQB.getStatus());
unique_ptr<CanonicalQuery> cqB = std::move(statusWithCQB.getValue());
@@ -404,8 +412,10 @@ TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) {
auto txn = serviceContext.makeOperationContext();
// Create a canonical query
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(fromjson("{a: 1}"));
auto statusWithCQ = CanonicalQuery::canonicalize(
- txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
+ txn.get(), std::move(lpq), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -427,8 +437,10 @@ TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionFalse) {
auto txn = serviceContext.makeOperationContext();
// Create a canonical query
+ auto lpq = stdx::make_unique<LiteParsedQuery>(nss);
+ lpq->setFilter(fromjson("{a: 1}"));
auto statusWithCQ = CanonicalQuery::canonicalize(
- txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions());
+ txn.get(), std::move(lpq), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());