summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/planner_ixselect_test.cpp
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2018-12-14 19:36:29 -0500
committerGregory Wlodarek <gregory.wlodarek@mongodb.com>2018-12-14 19:36:29 -0500
commit54c2a4560cbcd5b652c3bdc8543404ea6cc2d485 (patch)
treebb465037becbdca37bf91adf0804b833a02ddfcf /src/mongo/db/query/planner_ixselect_test.cpp
parentbf6b9ac90bcc0d811f29b8695845ad7b584beb71 (diff)
downloadmongo-54c2a4560cbcd5b652c3bdc8543404ea6cc2d485.tar.gz
Revert "SERVER-38069 Ensure WT transactions are not re-opened during plan updates"
This reverts commit ac39ac47d776bbd0f442f945d4ae6091b73cfb03.
Diffstat (limited to 'src/mongo/db/query/planner_ixselect_test.cpp')
-rw-r--r--src/mongo/db/query/planner_ixselect_test.cpp213
1 files changed, 94 insertions, 119 deletions
diff --git a/src/mongo/db/query/planner_ixselect_test.cpp b/src/mongo/db/query/planner_ixselect_test.cpp
index 4c45dc7f3c4..d9acd0a2542 100644
--- a/src/mongo/db/query/planner_ixselect_test.cpp
+++ b/src/mongo/db/query/planner_ixselect_test.cpp
@@ -193,24 +193,6 @@ void findRelevantTaggedNodePathsAndIndices(MatchExpression* root,
}
/**
- * Make a minimal IndexEntry from just a key pattern. A dummy name will be added.
- */
-IndexEntry buildSimpleIndexEntry(const BSONObj& kp) {
- return {kp,
- IndexNames::nameToType(IndexNames::findPluginName(kp)),
- false,
- {},
- {},
- false,
- false,
- CoreIndexInfo::Identifier("test_foo"),
- nullptr,
- {},
- nullptr,
- nullptr};
-}
-
-/**
* Parses a MatchExpression from query string and passes that along with prefix, collator, and
* indices to rateIndices. Verifies results against list of expected paths and expected indices. In
* future, we may expand this test function to validate which indices are assigned to which node.
@@ -332,7 +314,7 @@ TEST(QueryPlannerIXSelectTest, RateIndicesTaggedNodePathArrayNegation) {
*/
TEST(QueryPlannerIXSelectTest, ElemMatchNotExistsShouldNotUseSparseIndex) {
std::vector<IndexEntry> indices;
- auto idxEntry = buildSimpleIndexEntry(BSON("a" << 1));
+ auto idxEntry = IndexEntry(BSON("a" << 1));
idxEntry.sparse = true;
indices.push_back(idxEntry);
std::set<size_t> expectedIndices;
@@ -349,7 +331,7 @@ TEST(QueryPlannerIXSelectTest, ElemMatchNotExistsShouldNotUseSparseIndex) {
*/
TEST(QueryPlannerIXSelectTest, ElemMatchInNullValueShouldUseSparseIndex) {
std::vector<IndexEntry> indices;
- auto idxEntry = buildSimpleIndexEntry(BSON("a" << 1));
+ auto idxEntry = IndexEntry(BSON("a" << 1));
idxEntry.sparse = true;
indices.push_back(idxEntry);
std::set<size_t> expectedIndices = {0};
@@ -362,7 +344,7 @@ TEST(QueryPlannerIXSelectTest, ElemMatchInNullValueShouldUseSparseIndex) {
*/
TEST(QueryPlannerIXSelectTest, ElemMatchGeoShouldNotUseBtreeIndex) {
std::vector<IndexEntry> indices;
- auto idxEntry = buildSimpleIndexEntry(BSON("a" << 1));
+ auto idxEntry = IndexEntry(BSON("a" << 1));
indices.push_back(idxEntry);
std::set<size_t> expectedIndices;
testRateIndices(R"({a: {$elemMatch: {$geoWithin: {$geometry: {type: 'Polygon',
@@ -379,7 +361,7 @@ TEST(QueryPlannerIXSelectTest, ElemMatchGeoShouldNotUseBtreeIndex) {
*/
TEST(QueryPlannerIXSelectTest, ElemMatchEqNullValueShouldUseSparseIndex) {
std::vector<IndexEntry> indices;
- auto idxEntry = buildSimpleIndexEntry(BSON("a" << 1));
+ auto idxEntry = IndexEntry(BSON("a" << 1));
idxEntry.sparse = true;
indices.push_back(idxEntry);
std::set<size_t> expectedIndices = {0};
@@ -392,7 +374,7 @@ TEST(QueryPlannerIXSelectTest, ElemMatchEqNullValueShouldUseSparseIndex) {
*/
TEST(QueryPlannerIXSelectTest, ElemMatchMultipleChildrenShouldRequireAllToBeCompatible) {
std::vector<IndexEntry> indices;
- auto idxEntry = buildSimpleIndexEntry(BSON("a" << 1));
+ auto idxEntry = IndexEntry(BSON("a" << 1));
idxEntry.sparse = true;
indices.push_back(idxEntry);
std::set<size_t> expectedIndices;
@@ -409,7 +391,7 @@ TEST(QueryPlannerIXSelectTest, ElemMatchMultipleChildrenShouldRequireAllToBeComp
*/
TEST(QueryPlannerIXSelectTest, NullCollatorsMatch) {
std::vector<IndexEntry> indices;
- indices.push_back(buildSimpleIndexEntry(BSON("a" << 1)));
+ indices.push_back(IndexEntry(BSON("a" << 1)));
std::set<size_t> expectedIndices = {0};
testRateIndices("{a: 'string'}", "", nullptr, indices, "a", expectedIndices);
}
@@ -420,7 +402,7 @@ TEST(QueryPlannerIXSelectTest, NullCollatorsMatch) {
TEST(QueryPlannerIXSelectTest, NonNullCollatorDoesNotMatchIndexWithNullCollator) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
std::vector<IndexEntry> indices;
- indices.push_back(buildSimpleIndexEntry(BSON("a" << 1)));
+ indices.push_back(IndexEntry(BSON("a" << 1)));
std::set<size_t> expectedIndices;
testRateIndices("{a: 'string'}", "", &collator, indices, "a", expectedIndices);
}
@@ -429,7 +411,7 @@ TEST(QueryPlannerIXSelectTest, NonNullCollatorDoesNotMatchIndexWithNullCollator)
* If the collator is null, we do not select the relevant index with a non-null collator.
*/
TEST(QueryPlannerIXSelectTest, NullCollatorDoesNotMatchIndexWithNonNullCollator) {
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kAlwaysEqual);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -443,7 +425,7 @@ TEST(QueryPlannerIXSelectTest, NullCollatorDoesNotMatchIndexWithNonNullCollator)
*/
TEST(QueryPlannerIXSelectTest, EqualCollatorsMatch) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kAlwaysEqual);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -457,7 +439,7 @@ TEST(QueryPlannerIXSelectTest, EqualCollatorsMatch) {
*/
TEST(QueryPlannerIXSelectTest, UnequalCollatorsDoNotMatch) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -471,7 +453,7 @@ TEST(QueryPlannerIXSelectTest, UnequalCollatorsDoNotMatch) {
*/
TEST(QueryPlannerIXSelectTest, NoStringComparison) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -482,7 +464,7 @@ TEST(QueryPlannerIXSelectTest, NoStringComparison) {
TEST(QueryPlannerIXSelectTest, StringInternalExprEqUnequalCollatorsCannotUseIndex) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -494,7 +476,7 @@ TEST(QueryPlannerIXSelectTest, StringInternalExprEqUnequalCollatorsCannotUseInde
TEST(QueryPlannerIXSelectTest, StringInternalExprEqEqualCollatorsCanUseIndex) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -505,7 +487,7 @@ TEST(QueryPlannerIXSelectTest, StringInternalExprEqEqualCollatorsCanUseIndex) {
TEST(QueryPlannerIXSelectTest, NestedObjectInternalExprEqUnequalCollatorsCannotUseIndex) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -517,7 +499,7 @@ TEST(QueryPlannerIXSelectTest, NestedObjectInternalExprEqUnequalCollatorsCannotU
TEST(QueryPlannerIXSelectTest, NestedObjectInternalExprEqEqualCollatorsCanUseIndex) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -531,7 +513,7 @@ TEST(QueryPlannerIXSelectTest, NestedObjectInternalExprEqEqualCollatorsCanUseInd
*/
TEST(QueryPlannerIXSelectTest, StringGTUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -545,7 +527,7 @@ TEST(QueryPlannerIXSelectTest, StringGTUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringGTEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -558,7 +540,7 @@ TEST(QueryPlannerIXSelectTest, StringGTEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, ArrayGTUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -572,7 +554,7 @@ TEST(QueryPlannerIXSelectTest, ArrayGTUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, ArrayGTEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -585,7 +567,7 @@ TEST(QueryPlannerIXSelectTest, ArrayGTEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, NestedObjectGTUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -599,7 +581,7 @@ TEST(QueryPlannerIXSelectTest, NestedObjectGTUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, NestedObjectGTEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -612,7 +594,7 @@ TEST(QueryPlannerIXSelectTest, NestedObjectGTEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringGTEUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -626,7 +608,7 @@ TEST(QueryPlannerIXSelectTest, StringGTEUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringGTEEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -639,7 +621,7 @@ TEST(QueryPlannerIXSelectTest, StringGTEEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringLTUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -653,7 +635,7 @@ TEST(QueryPlannerIXSelectTest, StringLTUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringLTEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -666,7 +648,7 @@ TEST(QueryPlannerIXSelectTest, StringLTEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringLTEUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -680,7 +662,7 @@ TEST(QueryPlannerIXSelectTest, StringLTEUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringLTEEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -693,7 +675,7 @@ TEST(QueryPlannerIXSelectTest, StringLTEEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, NoStringComparisonInExpression) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -707,7 +689,7 @@ TEST(QueryPlannerIXSelectTest, NoStringComparisonInExpression) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonInExpressionUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -721,7 +703,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonInExpressionUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonInExpressionEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -734,7 +716,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonInExpressionEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, NoStringComparisonNotExpression) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -748,7 +730,7 @@ TEST(QueryPlannerIXSelectTest, NoStringComparisonNotExpression) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonNotExpressionUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -762,7 +744,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonNotExpressionUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonNotExpressionEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -775,7 +757,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonNotExpressionEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, NoStringComparisonElemMatchValueExpression) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -789,7 +771,7 @@ TEST(QueryPlannerIXSelectTest, NoStringComparisonElemMatchValueExpression) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonElemMatchValueExpressionUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -804,7 +786,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonElemMatchValueExpressionUnequalCo
*/
TEST(QueryPlannerIXSelectTest, StringComparisonElemMatchValueExpressionEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -818,7 +800,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonElemMatchValueExpressionEqualColl
*/
TEST(QueryPlannerIXSelectTest, NoStringComparisonNotInExpression) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -832,7 +814,7 @@ TEST(QueryPlannerIXSelectTest, NoStringComparisonNotInExpression) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonNotInExpressionUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -846,7 +828,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonNotInExpressionUnequalCollators)
*/
TEST(QueryPlannerIXSelectTest, StringComparisonNotInExpressionEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -859,7 +841,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonNotInExpressionEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, NoStringComparisonNinExpression) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -873,7 +855,7 @@ TEST(QueryPlannerIXSelectTest, NoStringComparisonNinExpression) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonNinExpressionUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -887,7 +869,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonNinExpressionUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonNinExpressionEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -900,7 +882,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonNinExpressionEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonOrExpressionUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -914,7 +896,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonOrExpressionUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonOrExpressionEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -927,7 +909,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonOrExpressionEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonAndExpressionUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -941,7 +923,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonAndExpressionUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonAndExpressionEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -954,7 +936,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonAndExpressionEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonAllExpressionUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -968,7 +950,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonAllExpressionUnequalCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonAllExpressionEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -981,7 +963,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonAllExpressionEqualCollators) {
*/
TEST(QueryPlannerIXSelectTest, StringComparisonElemMatchObjectExpressionUnequalCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a.b" << 1));
+ IndexEntry index(BSON("a.b" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -996,7 +978,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonElemMatchObjectExpressionUnequalC
*/
TEST(QueryPlannerIXSelectTest, StringComparisonElemMatchObjectExpressionEqualCollators) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a.b" << 1));
+ IndexEntry index(BSON("a.b" << 1));
index.collator = &collator;
std::vector<IndexEntry> indices;
indices.push_back(index);
@@ -1010,7 +992,7 @@ TEST(QueryPlannerIXSelectTest, StringComparisonElemMatchObjectExpressionEqualCol
*/
TEST(QueryPlannerIXSelectTest, NoStringComparisonMod) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -1024,7 +1006,7 @@ TEST(QueryPlannerIXSelectTest, NoStringComparisonMod) {
*/
TEST(QueryPlannerIXSelectTest, NoStringComparisonExists) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -1038,7 +1020,7 @@ TEST(QueryPlannerIXSelectTest, NoStringComparisonExists) {
*/
TEST(QueryPlannerIXSelectTest, NoStringComparisonType) {
CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual);
- auto index = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry index(BSON("a" << 1));
CollatorInterfaceMock indexCollator(CollatorInterfaceMock::MockType::kReverseString);
index.collator = &indexCollator;
std::vector<IndexEntry> indices;
@@ -1057,30 +1039,23 @@ TEST(QueryPlannerIXSelectTest, NoStringComparisonType) {
std::pair<IndexEntry, std::unique_ptr<ProjectionExecAgg>> makeIndexEntry(
BSONObj keyPattern,
MultikeyPaths multiKeyPaths,
- std::set<FieldRef> multiKeyPathSet = {},
+ std::set<FieldRef> multikeyPathSet = {},
BSONObj infoObj = BSONObj()) {
auto projExec = (keyPattern.firstElement().fieldNameStringData().endsWith("$**"_sd)
? WildcardKeyGenerator::createProjectionExec(
keyPattern, infoObj.getObjectField("wildcardProjection"))
: nullptr);
- auto multiKey = !multiKeyPathSet.empty() ||
- std::any_of(multiKeyPaths.cbegin(), multiKeyPaths.cend(), [](const auto& entry) {
- return !entry.empty();
- });
- return {{keyPattern,
- IndexNames::nameToType(IndexNames::findPluginName(keyPattern)),
- multiKey,
- multiKeyPaths,
- multiKeyPathSet,
- false,
- false,
- CoreIndexInfo::Identifier("test_foo"),
- nullptr,
- {},
- nullptr,
- projExec.get()},
- std::move(projExec)};
+ IndexEntry entry{std::move(keyPattern)};
+ entry.multikeyPaths = std::move(multiKeyPaths);
+ entry.multikey =
+ !multikeyPathSet.empty() || std::any_of(entry.multikeyPaths.cbegin(),
+ entry.multikeyPaths.cend(),
+ [](const auto& entry) { return !entry.empty(); });
+ entry.multikeyPathSet = std::move(multikeyPathSet);
+ entry.wildcardProjection = projExec.get();
+ entry.infoObj = infoObj;
+ return {entry, std::move(projExec)};
}
TEST(QueryPlannerIXSelectTest, InternalExprEqCannotUseMultiKeyIndex) {
@@ -1102,7 +1077,7 @@ TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseNonMultikeyFieldOfMultikeyInd
}
TEST(QueryPlannerIXSelectTest, InternalExprEqCannotUseMultikeyIndexWithoutPathLevelMultikeyData) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry entry{BSON("a" << 1)};
entry.multikey = true;
std::vector<IndexEntry> indices;
indices.push_back(entry);
@@ -1112,7 +1087,7 @@ TEST(QueryPlannerIXSelectTest, InternalExprEqCannotUseMultikeyIndexWithoutPathLe
}
TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseNonMultikeyIndexWithNoPathLevelMultikeyData) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry entry{BSON("a" << 1)};
std::vector<IndexEntry> indices;
indices.push_back(entry);
std::set<size_t> expectedIndices = {0};
@@ -1121,8 +1096,8 @@ TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseNonMultikeyIndexWithNoPathLev
}
TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseHashedIndex) {
- auto entry = buildSimpleIndexEntry(BSON("a"
- << "hashed"));
+ IndexEntry entry{BSON("a"
+ << "hashed")};
std::vector<IndexEntry> indices;
indices.push_back(entry);
std::set<size_t> expectedIndices = {0};
@@ -1131,10 +1106,10 @@ TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseHashedIndex) {
}
TEST(QueryPlannerIXSelectTest, InternalExprEqCannotUseTextIndexPrefix) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1 << "_fts"
- << "text"
- << "_ftsx"
- << 1));
+ IndexEntry entry{BSON("a" << 1 << "_fts"
+ << "text"
+ << "_ftsx"
+ << 1)};
std::vector<IndexEntry> indices;
indices.push_back(entry);
std::set<size_t> expectedIndices;
@@ -1143,12 +1118,12 @@ TEST(QueryPlannerIXSelectTest, InternalExprEqCannotUseTextIndexPrefix) {
}
TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseTextIndexSuffix) {
- auto entry = buildSimpleIndexEntry(BSON("_fts"
- << "text"
- << "_ftsx"
- << 1
- << "a"
- << 1));
+ IndexEntry entry{BSON("_fts"
+ << "text"
+ << "_ftsx"
+ << 1
+ << "a"
+ << 1)};
std::vector<IndexEntry> indices;
indices.push_back(entry);
std::set<size_t> expectedIndices = {0};
@@ -1157,7 +1132,7 @@ TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseTextIndexSuffix) {
}
TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseSparseIndexWithComparisonToNull) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry entry{BSON("a" << 1)};
entry.sparse = true;
std::vector<IndexEntry> indices;
indices.push_back(entry);
@@ -1167,7 +1142,7 @@ TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseSparseIndexWithComparisonToNu
}
TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseSparseIndexWithComparisonToNonNull) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry entry{BSON("a" << 1)};
entry.sparse = true;
std::vector<IndexEntry> indices;
indices.push_back(entry);
@@ -1176,20 +1151,20 @@ TEST(QueryPlannerIXSelectTest, InternalExprEqCanUseSparseIndexWithComparisonToNo
"{a: {$_internalExprEq: 1}}", "", kSimpleCollator, indices, "a", expectedIndices);
}
TEST(QueryPlannerIXSelectTest, NotEqualsNullCanUseIndex) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry entry{BSON("a" << 1)};
std::set<size_t> expectedIndices = {0};
testRateIndices("{a: {$ne: null}}", "", kSimpleCollator, {entry}, "a,a", expectedIndices);
}
TEST(QueryPlannerIXSelectTest, NotEqualsNullCannotUseMultiKeyIndex) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry entry{BSON("a" << 1)};
entry.multikey = true;
std::set<size_t> expectedIndices = {};
testRateIndices("{a: {$ne: null}}", "", kSimpleCollator, {entry}, "a,a", expectedIndices);
}
TEST(QueryPlannerIXSelectTest, NotEqualsNullCannotUseDottedMultiKeyIndex) {
- auto entry = buildSimpleIndexEntry(BSON("a.b" << 1));
+ IndexEntry entry{BSON("a.b" << 1)};
entry.multikeyPaths = {{0}};
std::set<size_t> expectedIndices = {};
testRateIndices(
@@ -1197,21 +1172,21 @@ TEST(QueryPlannerIXSelectTest, NotEqualsNullCannotUseDottedMultiKeyIndex) {
}
TEST(QueryPlannerIXSelectTest, NotEqualsNullCanUseIndexWhichIsMultiKeyOnAnotherPath) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1 << "mk" << 1));
+ IndexEntry entry{BSON("a" << 1 << "mk" << 1)};
entry.multikeyPaths = {{}, {0}};
std::set<size_t> expectedIndices = {0};
testRateIndices("{a: {$ne: null}}", "", kSimpleCollator, {entry}, "a,a", expectedIndices);
}
TEST(QueryPlannerIXSelectTest, ElemMatchValueWithNotEqualsNullCanUseIndex) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry entry{BSON("a" << 1)};
std::set<size_t> expectedIndices = {0};
testRateIndices(
"{a: {$elemMatch: {$ne: null}}}", "", kSimpleCollator, {entry}, "a", expectedIndices);
}
TEST(QueryPlannerIXSelectTest, ElemMatchValueWithNotEqualsNullCanUseMultiKeyIndex) {
- auto entry = buildSimpleIndexEntry(BSON("a" << 1));
+ IndexEntry entry{BSON("a" << 1)};
entry.multikey = true;
std::set<size_t> expectedIndices = {0};
testRateIndices(
@@ -1219,7 +1194,7 @@ TEST(QueryPlannerIXSelectTest, ElemMatchValueWithNotEqualsNullCanUseMultiKeyInde
}
TEST(QueryPlannerIXSelectTest, ElemMatchObjectWithNotEqualNullCanUseIndex) {
- auto entry = buildSimpleIndexEntry(BSON("a.b" << 1));
+ IndexEntry entry{BSON("a.b" << 1)};
std::set<size_t> expectedIndices = {0};
testRateIndices("{a: {$elemMatch: {b: {$ne: null}}}}",
"",
@@ -1230,7 +1205,7 @@ TEST(QueryPlannerIXSelectTest, ElemMatchObjectWithNotEqualNullCanUseIndex) {
}
TEST(QueryPlannerIXSelectTest, ElemMatchObjectWithNotEqualNullCannotUseOldMultiKeyIndex) {
- auto entry = buildSimpleIndexEntry(BSON("a.b" << 1));
+ IndexEntry entry{BSON("a.b" << 1)};
entry.multikey = true;
std::set<size_t> expectedIndices = {};
testRateIndices("{a: {$elemMatch: {b: {$ne: null}}}}",
@@ -1242,7 +1217,7 @@ TEST(QueryPlannerIXSelectTest, ElemMatchObjectWithNotEqualNullCannotUseOldMultiK
}
TEST(QueryPlannerIXSelectTest, ElemMatchObjectWithNotEqualNullCanUseIndexMultikeyOnPrefix) {
- auto entry = buildSimpleIndexEntry(BSON("a.b.c.d" << 1));
+ IndexEntry entry{BSON("a.b.c.d" << 1)};
entry.multikeyPaths = {{0U}};
std::set<size_t> expectedIndices = {0U};
const auto query = "{'a.b': {$elemMatch: {'c.d': {$ne: null}}}}";
@@ -1262,7 +1237,7 @@ TEST(QueryPlannerIXSelectTest, ElemMatchObjectWithNotEqualNullCanUseIndexMultike
TEST(QueryPlannerIXSelectTest,
NestedElemMatchObjectWithNotEqualNullCanUseIndexMultikeyOnAnyPrefix) {
- auto entry = buildSimpleIndexEntry(BSON("a.b.c.d" << 1));
+ IndexEntry entry{BSON("a.b.c.d" << 1)};
entry.multikeyPaths = {{0U}};
std::set<size_t> expectedIndices = {0U};
const auto query = "{a: {$elemMatch: {b: {$elemMatch: {'c.d': {$ne: null}}}}}}";
@@ -1281,16 +1256,16 @@ TEST(QueryPlannerIXSelectTest,
}
TEST(QueryPlannerIXSelectTest, HashedIndexShouldNotBeRelevantForNotPredicate) {
- auto entry = buildSimpleIndexEntry(BSON("a"
- << "hashed"));
+ IndexEntry entry{BSON("a"
+ << "hashed")};
entry.type = IndexType::INDEX_HASHED;
std::set<size_t> expectedIndices = {};
testRateIndices("{a: {$ne: 4}}", "", kSimpleCollator, {entry}, "a,a", expectedIndices);
}
TEST(QueryPlannerIXSelectTest, HashedIndexShouldNotBeRelevantForNotEqualsNullPredicate) {
- auto entry = buildSimpleIndexEntry(BSON("a"
- << "hashed"));
+ IndexEntry entry{BSON("a"
+ << "hashed")};
entry.type = IndexType::INDEX_HASHED;
std::set<size_t> expectedIndices = {};
testRateIndices("{a: {$ne: null}}", "", kSimpleCollator, {entry}, "a,a", expectedIndices);