diff options
author | Bernard Gorman <bernard.gorman@gmail.com> | 2018-10-15 14:13:53 -0400 |
---|---|---|
committer | Bernard Gorman <bernard.gorman@gmail.com> | 2018-10-23 00:19:01 +0100 |
commit | 1e19472175d9f8c26d2cc1a80e108a0a4a761213 (patch) | |
tree | ff798bd9801eb65585ee8096a86f0461373f1833 /src/mongo/db/query/plan_cache_indexability_test.cpp | |
parent | 10ec78a0ea0adca815df5a5cb9f3bf9f7d2221f6 (diff) | |
download | mongo-1e19472175d9f8c26d2cc1a80e108a0a4a761213.tar.gz |
SERVER-37566 Avoid recreating ProjectionExecAgg on each expansion of a wildcard index
Diffstat (limited to 'src/mongo/db/query/plan_cache_indexability_test.cpp')
-rw-r--r-- | src/mongo/db/query/plan_cache_indexability_test.cpp | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/src/mongo/db/query/plan_cache_indexability_test.cpp b/src/mongo/db/query/plan_cache_indexability_test.cpp index 4ab15f30ac1..dc67fd8c30a 100644 --- a/src/mongo/db/query/plan_cache_indexability_test.cpp +++ b/src/mongo/db/query/plan_cache_indexability_test.cpp @@ -30,6 +30,7 @@ #include "mongo/platform/basic.h" +#include "mongo/db/index/wildcard_key_generator.h" #include "mongo/db/json.h" #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/pipeline/expression_context_for_test.h" @@ -53,6 +54,24 @@ std::unique_ptr<MatchExpression> parseMatchExpression(const BSONObj& obj, return std::move(status.getValue()); } +// Helper which constructs a $** IndexEntry and returns it along with an owned ProjectionExecAgg. +// The latter simulates the ProjectionExecAgg which, during normal operation, is owned and +// maintained by the $** index's IndexAccessMethod, and is required because the plan cache will +// obtain unowned pointers to it. +std::pair<IndexEntry, std::unique_ptr<ProjectionExecAgg>> makeWildcardEntry( + BSONObj keyPattern, const MatchExpression* filterExpr = nullptr) { + auto projExec = WildcardKeyGenerator::createProjectionExec(keyPattern, {}); + return {IndexEntry(keyPattern, + false, // multikey + false, // sparse + false, // unique + IndexEntry::Identifier{"indexName"}, + filterExpr, + BSONObj(), + projExec.get()), + std::move(projExec)}; +} + // Test sparse index discriminators for a simple sparse index. TEST(PlanCacheIndexabilityTest, SparseIndexSimple) { PlanCacheIndexabilityState state; @@ -413,13 +432,8 @@ TEST(PlanCacheIndexabilityTest, CompoundIndexCollationDiscriminator) { TEST(PlanCacheIndexabilityTest, WildcardDiscriminator) { PlanCacheIndexabilityState state; - state.updateDiscriminators({IndexEntry(BSON("a.$**" << 1), - false, // multikey - false, // sparse - false, // unique - IndexEntry::Identifier{"indexName"}, - nullptr, - BSONObj())}); + auto entryProjExecPair = makeWildcardEntry(BSON("a.$**" << 1)); + state.updateDiscriminators({entryProjExecPair.first}); const auto unindexedPathDiscriminators = state.buildWildcardDiscriminators("notIndexed"); ASSERT_EQ(0U, unindexedPathDiscriminators.size()); @@ -466,16 +480,10 @@ TEST(PlanCacheIndexabilityTest, WildcardDiscriminator) { TEST(PlanCacheIndexabilityTest, WildcardWithCollationDiscriminator) { PlanCacheIndexabilityState state; - IndexEntry entry(BSON("a.$**" << 1), - false, // multikey - false, // sparse - false, // unique - IndexEntry::Identifier{"indexName"}, - nullptr, - BSONObj()); + auto entryProjExecPair = makeWildcardEntry(BSON("a.$**" << 1)); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - entry.collator = &collator; - state.updateDiscriminators({entry}); + entryProjExecPair.first.collator = &collator; + state.updateDiscriminators({entryProjExecPair.first}); const auto unindexedPathDiscriminators = state.buildWildcardDiscriminators("notIndexed"); ASSERT_EQ(0U, unindexedPathDiscriminators.size()); @@ -501,14 +509,8 @@ TEST(PlanCacheIndexabilityTest, WildcardPartialIndexDiscriminator) { // expression will store (unowned) pointers into it. BSONObj filterObj = fromjson("{a: {$gt: 5}}"); auto filterExpr = parseMatchExpression(filterObj); - IndexEntry entry(BSON("$**" << 1), - false, // multikey - false, // sparse - false, // unique - IndexEntry::Identifier{"indexName"}, - filterExpr.get(), - BSONObj()); - state.updateDiscriminators({entry}); + auto entryProjExecPair = makeWildcardEntry(BSON("$**" << 1), filterExpr.get()); + state.updateDiscriminators({entryProjExecPair.first}); auto discriminatorsA = state.buildWildcardDiscriminators("a"); ASSERT_EQ(1U, discriminatorsA.size()); @@ -528,13 +530,8 @@ TEST(PlanCacheIndexabilityTest, WildcardPartialIndexDiscriminator) { TEST(PlanCacheIndexabilityTest, WildcardIndexDiscriminatesBetweenEqualityToEmptyObjAndOtherObjComparisons) { PlanCacheIndexabilityState state; - state.updateDiscriminators({IndexEntry(BSON("a.$**" << 1), - false, // multikey - false, // sparse - false, // unique - IndexEntry::Identifier{"indexName"}, - nullptr, - BSONObj())}); + auto entryProjExecPair = makeWildcardEntry(BSON("a.$**" << 1)); + state.updateDiscriminators({entryProjExecPair.first}); auto discriminatorsA = state.buildWildcardDiscriminators("a"); ASSERT_EQ(1U, discriminatorsA.size()); |