diff options
author | Ruoxin Xu <ruoxin.xu@mongodb.com> | 2023-02-14 21:07:42 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-02-15 02:01:24 +0000 |
commit | 97ec2c53fe594472ca3ff36f47f00128ec350382 (patch) | |
tree | bc0cc75acbcc4c8fb3c07b53bf58e4dc42b154b3 | |
parent | 77c03f9e26931596059122c251bf875c190123e3 (diff) | |
download | mongo-97ec2c53fe594472ca3ff36f47f00128ec350382.tar.gz |
SERVER-73980 Make IndexBounds for wildcard multikey path query respect the wildcard field's ordering
-rw-r--r-- | src/mongo/db/query/wildcard_multikey_paths.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/mongo/db/query/wildcard_multikey_paths.cpp b/src/mongo/db/query/wildcard_multikey_paths.cpp index 01c219a19ea..fe87babee8d 100644 --- a/src/mongo/db/query/wildcard_multikey_paths.cpp +++ b/src/mongo/db/query/wildcard_multikey_paths.cpp @@ -239,13 +239,14 @@ std::vector<Interval> getMultikeyPathIndexIntervalsForField(FieldRef field) { } /** - * Returns the postion of the wildcard field inside the Wildcard Index's keyPattern. + * Returns the postion of the wildcard field inside the Wildcard Index's keyPattern and the + * direction of 'IndexBounds' generated for querying multikey paths. */ -static size_t getWildcardFieldPosition(const BSONObj& keyPattern) { +static std::pair<size_t, bool> getWildcardFieldPosition(const BSONObj& keyPattern) { size_t pos = 0; for (const auto& field : keyPattern) { if (WildcardNames::isWildcardFieldName(field.fieldNameStringData())) { - return pos; + return {pos, field.numberInt() < 0}; } ++pos; } @@ -275,7 +276,7 @@ static IndexBounds buildMetadataKeysIndexBounds(const BSONObj& keyPattern, // 3. Add the multikey path. // 4. Add the number of suffixed MinKey values, which is 0 or more. - const size_t wildcardPosition = getWildcardFieldPosition(keyPattern); + const auto [wildcardPosition, shouldReverse] = getWildcardFieldPosition(keyPattern); // Step 1. Add the number of prefixed MinKey values, which is 0 or more. for (size_t i = 0; i < wildcardPosition; ++i) { @@ -301,6 +302,9 @@ static IndexBounds buildMetadataKeysIndexBounds(const BSONObj& keyPattern, // IndexBoundsBuilder::unionize() sorts the OrderedIntervalList allowing for in order index // traversal. IndexBoundsBuilder::unionize(&fieldNameOil); + if (shouldReverse) { + fieldNameOil.reverse(); + } indexBounds.fields.push_back(std::move(fieldNameOil)); // Step 4. Add the number of suffixed MinKey values, which is 0 or more. |