summaryrefslogtreecommitdiff
path: root/src/mongo/db/dbhelpers.cpp
diff options
context:
space:
mode:
authorHaley Connelly <haley.connelly@mongodb.com>2022-01-21 14:05:48 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-21 14:45:39 +0000
commitbba68085962f35a9ffce3f6c33edd9bdd54498a3 (patch)
tree5da5386e0c7708d4ac65c670ab18f51307b94db4 /src/mongo/db/dbhelpers.cpp
parentf64289f53ad05760a805f57e5524a60d44daec8d (diff)
downloadmongo-bba68085962f35a9ffce3f6c33edd9bdd54498a3.tar.gz
SERVER-62828 Allow Helpers::findById to search by clustered index
Diffstat (limited to 'src/mongo/db/dbhelpers.cpp')
-rw-r--r--src/mongo/db/dbhelpers.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp
index 66a79fabb58..e36026fca0a 100644
--- a/src/mongo/db/dbhelpers.cpp
+++ b/src/mongo/db/dbhelpers.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/dbhelpers.h"
+#include "mongo/db/catalog/clustered_collection_util.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/exec/working_set_common.h"
#include "mongo/db/index/btree_access_method.h"
@@ -163,21 +164,19 @@ bool Helpers::findById(OperationContext* opCtx,
const IndexCatalog* catalog = collection->getIndexCatalog();
const IndexDescriptor* desc = catalog->findIdIndex(opCtx);
- bool isTimeseriesBucketNs = nss.isTimeseriesBucketsCollection();
- if (!desc && !isTimeseriesBucketNs) {
+ if (!desc && !clustered_util::isClusteredOnId(collection->getClusteredInfo())) {
return false;
}
if (indexFound)
*indexFound = 1;
- // A time-series buckets collection does not have an index on _id. However, the RecordId can be
- // constructed using the _id field. So we can retrieve the document by using the RecordId
- // instead.
- if (isTimeseriesBucketNs) {
+ if (collection->isClustered()) {
Snapshotted<BSONObj> doc;
- if (collection->findDoc(
- opCtx, RecordId(record_id_helpers::keyForOID(query["_id"].OID())), &doc)) {
+ if (collection->findDoc(opCtx,
+ RecordId(record_id_helpers::keyForElem(
+ query["_id"], collection->getDefaultCollator())),
+ &doc)) {
result = std::move(doc.value());
return true;
}
@@ -198,6 +197,13 @@ RecordId Helpers::findById(OperationContext* opCtx,
verify(collection);
const IndexCatalog* catalog = collection->getIndexCatalog();
const IndexDescriptor* desc = catalog->findIdIndex(opCtx);
+ if (!desc && clustered_util::isClusteredOnId(collection->getClusteredInfo())) {
+ // There is no explicit IndexDescriptor for _id on a collection clustered by _id. However,
+ // the RecordId can be constructed directly from the input.
+ return RecordId(
+ record_id_helpers::keyForElem(idquery["_id"], collection->getDefaultCollator()));
+ }
+
uassert(13430, "no _id index", desc);
return catalog->getEntry(desc)->accessMethod()->findSingle(
opCtx, collection, idquery["_id"].wrap());