diff options
author | Daniel Gómez Ferro <daniel.gomezferro@mongodb.com> | 2022-02-07 15:29:29 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-07 18:50:45 +0000 |
commit | 7a2d86c376488cc756c0325e6edaf3406a86ec5d (patch) | |
tree | 660a74392777be30a2d629bde1951b21c3a61883 /src/mongo/dbtests | |
parent | 59e19dc9bff797fc1cff45d56942e5e61da36f1a (diff) | |
download | mongo-7a2d86c376488cc756c0325e6edaf3406a86ec5d.tar.gz |
SERVER-61939 Tighter bounds for clustered collection scans
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r-- | src/mongo/dbtests/query_stage_collscan.cpp | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp index c1aaff74825..fafbd58c0ef 100644 --- a/src/mongo/dbtests/query_stage_collscan.cpp +++ b/src/mongo/dbtests/query_stage_collscan.cpp @@ -209,10 +209,10 @@ public: _client.insert(ns.ns(), docs, ordered); } - // Returns the recordId generated by doc, assuming there's no collation and doc takes the shape - // of {<cluster key> : <value>}; - RecordId getRecordIdForClusteredDoc(const BSONObj& doc) { - return RecordId(record_id_helpers::keyForElem(doc.firstElement(), nullptr)); + // Returns the recordId generated by doc, assuming doc takes the shape of {<cluster key> : + // <value>}; + RecordIdBound getRecordIdForClusteredDoc(const BSONObj& doc) { + return RecordIdBound(record_id_helpers::keyForElem(doc.firstElement())); } // Performs a bounded collection scan from 'minRecord' to 'maxRecord' in the specified @@ -231,8 +231,8 @@ public: CollectionScanParams params; params.tailable = false; params.direction = direction; - params.minRecord = minRecord; - params.maxRecord = maxRecord; + params.minRecord = RecordIdBound(minRecord); + params.maxRecord = RecordIdBound(maxRecord); WorkingSet ws; auto scan = std::make_unique<CollectionScan>(_expCtx.get(), coll, params, &ws, nullptr); @@ -261,8 +261,8 @@ public: void runClusteredCollScanAndAssertContents( const NamespaceString& ns, CollectionScanParams::Direction direction, - boost::optional<RecordId> minRecord, - boost::optional<RecordId> maxRecord, + boost::optional<RecordIdBound> minRecord, + boost::optional<RecordIdBound> maxRecord, CollectionScanParams::ScanBoundInclusion boundInclusion, const vector<BSONObj>& expectedResults, const MatchExpression* filter = nullptr) { @@ -614,8 +614,8 @@ TEST_F(QueryStageCollectionScanTest, QueryTestCollscanClusteredMinMax) { CollectionScanParams params; params.direction = CollectionScanParams::FORWARD; params.tailable = false; - params.minRecord = recordIds[0]; - params.maxRecord = recordIds[recordIds.size() - 1]; + params.minRecord = RecordIdBound(recordIds[0]); + params.maxRecord = RecordIdBound(recordIds[recordIds.size() - 1]); WorkingSet ws; auto scan = std::make_unique<CollectionScan>(_expCtx.get(), coll, params, &ws, nullptr); @@ -768,8 +768,8 @@ TEST_F(QueryStageCollectionScanTest, QueryTestCollscanClusteredMinMaxDateExclusi params.tailable = false; params.direction = direction; - params.minRecord = record_id_helpers::keyForDate(minDate); - params.maxRecord = record_id_helpers::keyForDate(maxDate); + params.minRecord = RecordIdBound(record_id_helpers::keyForDate(minDate)); + params.maxRecord = RecordIdBound(record_id_helpers::keyForDate(maxDate)); // Exclude all but the record with _id 'middleDate' from the scan. StatusWithMatchExpression swMatch = MatchExpressionParser::parse( @@ -821,8 +821,8 @@ TEST_F(QueryStageCollectionScanTest, QueryTestCollscanClusteredReverse) { params.tailable = false; // The last entry in recordIds is the lowest record in the collection and the first entry is the // highest. - params.minRecord = recordIds[recordIds.size() - 1]; - params.maxRecord = recordIds[0]; + params.minRecord = RecordIdBound(recordIds[recordIds.size() - 1]); + params.maxRecord = RecordIdBound(recordIds[0]); WorkingSet ws; auto scan = std::make_unique<CollectionScan>(_expCtx.get(), coll, params, &ws, nullptr); @@ -865,8 +865,8 @@ TEST_F(QueryStageCollectionScanTest, QueryTestCollscanClusteredMinMaxFullObjectI params.tailable = false; // Expect to see all records. - params.minRecord = record_id_helpers::keyForOID(OID()); - params.maxRecord = record_id_helpers::keyForOID(OID::max()); + params.minRecord = RecordIdBound(record_id_helpers::keyForOID(OID())); + params.maxRecord = RecordIdBound(record_id_helpers::keyForOID(OID::max())); WorkingSet ws; auto scan = std::make_unique<CollectionScan>(_expCtx.get(), coll, params, &ws, nullptr); @@ -913,8 +913,8 @@ TEST_F(QueryStageCollectionScanTest, QueryTestCollscanClusteredInnerRange) { ASSERT_LT(startOffset, recordIds.size()); ASSERT_LT(endOffset, recordIds.size()); - params.minRecord = recordIds[startOffset]; - params.maxRecord = recordIds[endOffset]; + params.minRecord = RecordIdBound(recordIds[startOffset]); + params.maxRecord = RecordIdBound(recordIds[endOffset]); WorkingSet ws; auto scan = std::make_unique<CollectionScan>(_expCtx.get(), coll, params, &ws, nullptr); @@ -962,15 +962,20 @@ TEST_F(QueryStageCollectionScanTest, QueryTestCollscanClusteredInnerRangeExclusi ASSERT_LT(startOffset, recordIds.size()); ASSERT_LT(endOffset, recordIds.size()); - params.minRecord = recordIds[startOffset]; - params.maxRecord = recordIds[endOffset]; + params.minRecord = RecordIdBound(recordIds[startOffset]); + params.maxRecord = RecordIdBound(recordIds[endOffset]); // Provide RecordId bounds with exclusive filters. StatusWithMatchExpression swMatch = MatchExpressionParser::parse( - fromjson(fmt::sprintf( - "{_id: {$gt: ObjectId('%s'), $lt: ObjectId('%s')}}", - record_id_helpers::toBSONAs(*params.minRecord, "").firstElement().OID().toString(), - record_id_helpers::toBSONAs(*params.maxRecord, "").firstElement().OID().toString())), + fromjson(fmt::sprintf("{_id: {$gt: ObjectId('%s'), $lt: ObjectId('%s')}}", + record_id_helpers::toBSONAs(params.minRecord->recordId(), "") + .firstElement() + .OID() + .toString(), + record_id_helpers::toBSONAs(params.maxRecord->recordId(), "") + .firstElement() + .OID() + .toString())), _expCtx.get()); ASSERT_OK(swMatch.getStatus()); auto filter = std::move(swMatch.getValue()); @@ -1024,15 +1029,20 @@ TEST_F(QueryStageCollectionScanTest, QueryTestCollscanClusteredInnerRangeExclusi // The last entry in recordIds is the lowest record in the collection and the first entry is the // highest. - params.minRecord = recordIds[endOffset]; - params.maxRecord = recordIds[startOffset]; + params.minRecord = RecordIdBound(recordIds[endOffset]); + params.maxRecord = RecordIdBound(recordIds[startOffset]); // Provide RecordId bounds with exclusive filters. StatusWithMatchExpression swMatch = MatchExpressionParser::parse( - fromjson(fmt::sprintf( - "{_id: {$gt: ObjectId('%s'), $lt: ObjectId('%s')}}", - record_id_helpers::toBSONAs(*params.minRecord, "").firstElement().OID().toString(), - record_id_helpers::toBSONAs(*params.maxRecord, "").firstElement().OID().toString())), + fromjson(fmt::sprintf("{_id: {$gt: ObjectId('%s'), $lt: ObjectId('%s')}}", + record_id_helpers::toBSONAs(params.minRecord->recordId(), "") + .firstElement() + .OID() + .toString(), + record_id_helpers::toBSONAs(params.maxRecord->recordId(), "") + .firstElement() + .OID() + .toString())), _expCtx.get()); ASSERT_OK(swMatch.getStatus()); auto filter = std::move(swMatch.getValue()); |