diff options
author | Haley Connelly <haley.connelly@mongodb.com> | 2022-02-15 13:32:43 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-15 14:21:35 +0000 |
commit | 39490b3f61d308a100776cedc61073e0dcb21e01 (patch) | |
tree | c31267b7b39cf87f0cf470c9d2e6671a2d3c7861 | |
parent | d1b01bd5da2dee6a0252f1171777a3c1a53339c5 (diff) | |
download | mongo-39490b3f61d308a100776cedc61073e0dcb21e01.tar.gz |
SERVER-62899 Fix coverity defect in dbhelpers.cpp
-rw-r--r-- | src/mongo/db/dbhelpers.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index 3da676da060..8dd89b032dd 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -165,25 +165,30 @@ bool Helpers::findById(OperationContext* opCtx, const IndexCatalog* catalog = collection->getIndexCatalog(); const IndexDescriptor* desc = catalog->findIdIndex(opCtx); - if (!desc && !clustered_util::isClusteredOnId(collection->getClusteredInfo())) { + if (!desc) { + if (clustered_util::isClusteredOnId(collection->getClusteredInfo())) { + if (indexFound) { + // A collection clustered on _id implicitly has an _id index but no explicit + // IndexDescriptor tied to it. + *indexFound = 1; + } + + Snapshotted<BSONObj> doc; + if (collection->findDoc(opCtx, + record_id_helpers::keyForObj(IndexBoundsBuilder::objFromElement( + query["_id"], collection->getDefaultCollator())), + &doc)) { + result = std::move(doc.value()); + return true; + } + } + return false; } if (indexFound) *indexFound = 1; - if (collection->isClustered()) { - Snapshotted<BSONObj> doc; - if (collection->findDoc(opCtx, - record_id_helpers::keyForObj(IndexBoundsBuilder::objFromElement( - query["_id"], collection->getDefaultCollator())), - &doc)) { - result = std::move(doc.value()); - return true; - } - return false; - } - auto recordId = catalog->getEntry(desc)->accessMethod()->asSortedData()->findSingle( opCtx, collection, query["_id"].wrap()); if (recordId.isNull()) |