summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests
diff options
context:
space:
mode:
authorTimour Katchaounov <timour.katchaounov@mongodb.com>2021-05-12 09:35:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-21 12:49:54 +0000
commit9fd5b3adca829fe003e58c5d9ba5e56f1ae18059 (patch)
tree84229e7b41e02b9c8ddffba2c22fe82cc882fca0 /src/mongo/dbtests
parenta603516c55a06b1e94a62b4fc693d5fe2ec2c274 (diff)
downloadmongo-9fd5b3adca829fe003e58c5d9ba5e56f1ae18059.tar.gz
SERVER-56192 Improve diagnosability of query planner unit tests
* Charlie's initial patch * Compile fixes * Made all error codes unique
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r--src/mongo/dbtests/plan_ranking.cpp74
-rw-r--r--src/mongo/dbtests/query_stage_multiplan.cpp24
-rw-r--r--src/mongo/dbtests/wildcard_access_method_test.cpp3
3 files changed, 56 insertions, 45 deletions
diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp
index f13eb4280e2..44bda3e5c70 100644
--- a/src/mongo/dbtests/plan_ranking.cpp
+++ b/src/mongo/dbtests/plan_ranking.cpp
@@ -240,10 +240,10 @@ public:
ASSERT(cq);
auto soln = pickBestPlan(cq.get());
- ASSERT(
- QueryPlannerTestLib::solutionMatches("{fetch: {filter: {a:1}, node: "
- "{ixscan: {filter: null, pattern: {d:1}}}}}",
- soln->root()));
+ ASSERT(QueryPlannerTestLib::solutionMatches("{fetch: {filter: {a:1}, node: "
+ "{ixscan: {filter: null, pattern: {d:1}}}}}",
+ soln->root())
+ .isOK());
AutoGetCollectionForReadCommand collection(&_opCtx, nss);
@@ -299,7 +299,8 @@ public:
// {a:100} is super selective so choose that.
auto soln = pickBestPlan(cq.get());
ASSERT(QueryPlannerTestLib::solutionMatches(
- "{fetch: {filter: {b:1}, node: {ixscan: {pattern: {a: 1}}}}}", soln->root()));
+ "{fetch: {filter: {b:1}, node: {ixscan: {pattern: {a: 1}}}}}", soln->root())
+ .isOK());
// Turn on the "force intersect" option.
// This will be reverted by PlanRankingTestBase's destructor when the test completes.
@@ -318,11 +319,11 @@ public:
// both the {a:1} and {b:1} indices even though it performs poorly.
soln = pickBestPlan(cq.get());
- ASSERT(
- QueryPlannerTestLib::solutionMatches("{fetch: {node: {andSorted: {nodes: ["
- "{ixscan: {filter: null, pattern: {a:1}}},"
- "{ixscan: {filter: null, pattern: {b:1}}}]}}}}",
- soln->root()));
+ ASSERT(QueryPlannerTestLib::solutionMatches("{fetch: {node: {andSorted: {nodes: ["
+ "{ixscan: {filter: null, pattern: {a:1}}},"
+ "{ixscan: {filter: null, pattern: {b:1}}}]}}}}",
+ soln->root())
+ .isOK());
}
};
@@ -354,11 +355,11 @@ public:
internalQueryForceIntersectionPlans.store(true);
auto soln = pickBestPlan(cq.get());
- ASSERT(
- QueryPlannerTestLib::solutionMatches("{fetch: {node: {andHash: {nodes: ["
- "{ixscan: {filter: null, pattern: {a:1}}},"
- "{ixscan: {filter: null, pattern: {b:1}}}]}}}}",
- soln->root()));
+ ASSERT(QueryPlannerTestLib::solutionMatches("{fetch: {node: {andHash: {nodes: ["
+ "{ixscan: {filter: null, pattern: {a:1}}},"
+ "{ixscan: {filter: null, pattern: {b:1}}}]}}}}",
+ soln->root())
+ .isOK());
// Confirm that a backup plan is available.
ASSERT(hasBackupPlan());
@@ -394,8 +395,9 @@ public:
// Prefer the fully covered plan.
ASSERT(QueryPlannerTestLib::solutionMatches(
- "{proj: {spec: {_id:0, a:1, b:1}, node: {ixscan: {pattern: {a: 1, b:1}}}}}",
- soln->root()));
+ "{proj: {spec: {_id:0, a:1, b:1}, node: {ixscan: {pattern: {a: 1, b:1}}}}}",
+ soln->root())
+ .isOK());
}
};
@@ -427,11 +429,11 @@ public:
auto soln = pickBestPlan(cq.get());
// Anti-prefer the intersection plan.
- bool bestIsScanOverA = QueryPlannerTestLib::solutionMatches(
+ auto bestIsScanOverA = QueryPlannerTestLib::solutionMatches(
"{fetch: {node: {ixscan: {pattern: {a: 1}}}}}", soln->root());
- bool bestIsScanOverB = QueryPlannerTestLib::solutionMatches(
+ auto bestIsScanOverB = QueryPlannerTestLib::solutionMatches(
"{fetch: {node: {ixscan: {pattern: {b: 1}}}}}", soln->root());
- ASSERT(bestIsScanOverA || bestIsScanOverB);
+ ASSERT(bestIsScanOverA.isOK() || bestIsScanOverB.isOK());
}
};
@@ -466,8 +468,9 @@ public:
auto soln = pickBestPlan(cq.get());
// Prefer the fully covered plan.
ASSERT(QueryPlannerTestLib::solutionMatches(
- "{proj: {spec: {_id:0, a:1, b:1}, node: {ixscan: {pattern: {a: 1, b:1}}}}}",
- soln->root()));
+ "{proj: {spec: {_id:0, a:1, b:1}, node: {ixscan: {pattern: {a: 1, b:1}}}}}",
+ soln->root())
+ .isOK());
}
};
@@ -499,7 +502,8 @@ public:
// {a: 100} is super selective so choose that.
auto soln = pickBestPlan(cq.get());
ASSERT(QueryPlannerTestLib::solutionMatches(
- "{fetch: {filter: {b:1}, node: {ixscan: {pattern: {a: 1}}}}}", soln->root()));
+ "{fetch: {filter: {b:1}, node: {ixscan: {pattern: {a: 1}}}}}", soln->root())
+ .isOK());
}
};
@@ -535,7 +539,8 @@ public:
// {a: 100} is super selective so choose that.
auto soln = pickBestPlan(cq.get());
ASSERT(QueryPlannerTestLib::solutionMatches(
- "{fetch: {filter: {b:1}, node: {ixscan: {pattern: {a: 1}}}}}", soln->root()));
+ "{fetch: {filter: {b:1}, node: {ixscan: {pattern: {a: 1}}}}}", soln->root())
+ .isOK());
}
};
@@ -565,10 +570,11 @@ public:
// The best must not be a collscan.
ASSERT(QueryPlannerTestLib::solutionMatches(
- "{sort: {pattern: {c: 1}, limit: 0, type:'simple', node:"
- "{fetch: {filter: null, node: "
- "{ixscan: {filter: null, pattern: {_id: 1}}}}}}}",
- soln->root()));
+ "{sort: {pattern: {c: 1}, limit: 0, type:'simple', node:"
+ "{fetch: {filter: null, node: "
+ "{ixscan: {filter: null, pattern: {_id: 1}}}}}}}",
+ soln->root())
+ .isOK());
}
};
@@ -595,7 +601,8 @@ public:
// The best must be a collscan.
ASSERT(QueryPlannerTestLib::solutionMatches("{cscan: {dir: 1, filter: {foo: 2001}}}",
- soln->root()));
+ soln->root())
+ .isOK());
}
};
@@ -632,7 +639,8 @@ public:
ASSERT(
QueryPlannerTestLib::solutionMatches("{fetch: {filter: {a:1}, node: "
"{ixscan: {filter: null, pattern: {d:1,e:1}}}}}",
- soln->root()));
+ soln->root())
+ .isOK());
}
};
@@ -665,7 +673,8 @@ public:
// Use index on 'b'.
auto soln = pickBestPlan(cq.get());
ASSERT(QueryPlannerTestLib::solutionMatches("{fetch: {node: {ixscan: {pattern: {b: 1}}}}}",
- soln->root()));
+ soln->root())
+ .isOK());
}
};
@@ -697,7 +706,8 @@ public:
// Expect to use index {a: 1, b: 1}.
auto soln = pickBestPlan(cq.get());
ASSERT(QueryPlannerTestLib::solutionMatches("{fetch: {node: {ixscan: {pattern: {a: 1}}}}}",
- soln->root()));
+ soln->root())
+ .isOK());
}
};
diff --git a/src/mongo/dbtests/query_stage_multiplan.cpp b/src/mongo/dbtests/query_stage_multiplan.cpp
index bb47733e27e..449202ca9f4 100644
--- a/src/mongo/dbtests/query_stage_multiplan.cpp
+++ b/src/mongo/dbtests/query_stage_multiplan.cpp
@@ -424,12 +424,12 @@ TEST_F(QueryStageMultiPlanTest, MPSBackupPlan) {
// We should have picked the index intersection plan due to forcing ixisect.
auto soln = static_cast<const MultiPlanStage*>(mps.get())->bestSolution();
- ASSERT(
- QueryPlannerTestLib::solutionMatches("{sort: {pattern: {b: 1}, limit: 0, node:"
- "{fetch: {node: {andSorted: {nodes: ["
- "{ixscan: {filter: null, pattern: {a:1}}},"
- "{ixscan: {filter: null, pattern: {b:1}}}]}}}}}}",
- soln->root()));
+ ASSERT(QueryPlannerTestLib::solutionMatches("{sort: {pattern: {b: 1}, limit: 0, node:"
+ "{fetch: {node: {andSorted: {nodes: ["
+ "{ixscan: {filter: null, pattern: {a:1}}},"
+ "{ixscan: {filter: null, pattern: {b:1}}}]}}}}}}",
+ soln->root())
+ .isOK());
// Get the resulting document.
PlanStage::StageState state = PlanStage::NEED_TIME;
@@ -448,12 +448,12 @@ TEST_F(QueryStageMultiPlanTest, MPSBackupPlan) {
// and the winning plan should still be the index intersection one.
ASSERT(!mps->hasBackupPlan());
soln = static_cast<const MultiPlanStage*>(mps.get())->bestSolution();
- ASSERT(
- QueryPlannerTestLib::solutionMatches("{sort: {pattern: {b: 1}, limit: 0, node:"
- "{fetch: {node: {andSorted: {nodes: ["
- "{ixscan: {filter: null, pattern: {a:1}}},"
- "{ixscan: {filter: null, pattern: {b:1}}}]}}}}}}",
- soln->root()));
+ ASSERT(QueryPlannerTestLib::solutionMatches("{sort: {pattern: {b: 1}, limit: 0, node:"
+ "{fetch: {node: {andSorted: {nodes: ["
+ "{ixscan: {filter: null, pattern: {a:1}}},"
+ "{ixscan: {filter: null, pattern: {b:1}}}]}}}}}}",
+ soln->root())
+ .isOK());
// Restore index intersection force parameter.
internalQueryForceIntersectionPlans.store(forceIxisectOldValue);
diff --git a/src/mongo/dbtests/wildcard_access_method_test.cpp b/src/mongo/dbtests/wildcard_access_method_test.cpp
index 4f12d060582..0cf7c3d0a98 100644
--- a/src/mongo/dbtests/wildcard_access_method_test.cpp
+++ b/src/mongo/dbtests/wildcard_access_method_test.cpp
@@ -50,7 +50,8 @@ void assertCorrectMultikeyMetadataPathBoundsGenerated(StringData field,
const bool kDoNotRelaxBoundsCheck = false;
ASSERT(QueryPlannerTestLib::boundsMatch(
- expectedBounds, std::move(indexBounds), kDoNotRelaxBoundsCheck));
+ expectedBounds, std::move(indexBounds), kDoNotRelaxBoundsCheck)
+ .isOK());
}
TEST(WildcardAccessMethodTest, FieldGeneratesExpectedMultikeyPathBounds) {