summaryrefslogtreecommitdiff
path: root/src/mongo/db/index_builds_coordinator.cpp
diff options
context:
space:
mode:
authorKevin Cherkauer <kevin.cherkauer@mongodb.com>2023-01-27 22:08:41 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-01-27 22:49:40 +0000
commitd0c617dbf2dfbd15e30dc33102cdfde5113e44bb (patch)
treea369c547acc6d454b99ecf59a651b545bbfb91b2 /src/mongo/db/index_builds_coordinator.cpp
parent2c476fca4c0ee33312acd7591e8a0a2d7ac9020e (diff)
downloadmongo-d0c617dbf2dfbd15e30dc33102cdfde5113e44bb.tar.gz
SERVER-67446 Ensure consistent wildcardProjection specs in catalog
Diffstat (limited to 'src/mongo/db/index_builds_coordinator.cpp')
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index f16e991ffcd..b4fd8d4c5a4 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -3018,6 +3018,7 @@ std::vector<BSONObj> IndexBuildsCoordinator::prepareSpecListForCreate(
return resultSpecs;
}
+// Returns normalized versions of 'indexSpecs' for the catalog.
std::vector<BSONObj> IndexBuildsCoordinator::normalizeIndexSpecs(
OperationContext* opCtx,
const CollectionPtr& collection,
@@ -3039,26 +3040,13 @@ std::vector<BSONObj> IndexBuildsCoordinator::normalizeIndexSpecs(
// for clients to validate (via the listIndexes output) whether a given partialFilterExpression
// is equivalent to the filter that they originally submitted. Omitting this normalization does
// not impact our internal index comparison semantics, since we compare based on the parsed
- // MatchExpression trees rather than the serialized BSON specs. See SERVER-54357.
-
- // If any of the specs describe wildcard indexes, normalize the wildcard projections if present.
- // This will change all specs of the form {"a.b.c": 1} to normalized form {a: {b: {c : 1}}}.
- std::transform(normalSpecs.begin(), normalSpecs.end(), normalSpecs.begin(), [](auto& spec) {
- const auto kProjectionName = IndexDescriptor::kPathProjectionFieldName;
- const auto pathProjectionSpec = spec.getObjectField(kProjectionName);
- static const auto kWildcardKeyPattern = BSON("$**" << 1);
- // It's illegal for the user to explicitly specify an empty wildcardProjection for creating
- // a {"$**":1} index, and specify any wildcardProjection for a {"field.$**": 1} index. If
- // the projection is empty, then it means that there is no projection to normalize.
- if (pathProjectionSpec.isEmpty()) {
- return spec;
- }
- auto wildcardProjection =
- WildcardKeyGenerator::createProjectionExecutor(kWildcardKeyPattern, pathProjectionSpec);
- auto normalizedProjection =
- wildcardProjection.exec()->serializeTransformation(boost::none).toBson();
- return spec.addField(BSON(kProjectionName << normalizedProjection).firstElement());
- });
+ // MatchExpression trees rather than the serialized BSON specs.
+ //
+ // For similar reasons we do not normalize index projection objects here, if any, so their
+ // original forms get persisted in the catalog. Projection normalization to detect whether a
+ // candidate new index would duplicate an existing index is done only in the memory-only
+ // 'IndexDescriptor._normalizedProjection' field.
+
return normalSpecs;
}