From d63bbceedef055476559998b183f97f1ede8b49f Mon Sep 17 00:00:00 2001 From: Eric Cox Date: Mon, 2 Aug 2021 21:58:29 +0000 Subject: SERVER-59044 Bailout early if a time series collection is empty when building a TrialStage (cherry picked from commit bb6ec30bcbbb7b16f9f1c80cc3c9a99efcd5687c) --- src/mongo/db/pipeline/pipeline_d.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp index dca31cd55b0..28c870d99d8 100644 --- a/src/mongo/db/pipeline/pipeline_d.cpp +++ b/src/mongo/db/pipeline/pipeline_d.cpp @@ -185,6 +185,16 @@ createRandomCursorExecutor(const CollectionPtr& coll, minAdvancedToWorkRatio); trialStage = static_cast(root.get()); } else if (expCtx->ns.isTimeseriesBucketsCollection()) { + // We can't take ARHASH optimization path for a direct $sample on the system.buckets + // collection because data is in compressed form. If we did have a direct $sample on the + // system.buckets collection, then the 'bucketUnpacker' would not be set up properly. We + // also should bail out early if a $sample is made against a time series collection that is + // empty. If we don't the 'minAdvancedToWorkRatio' can be nan/-nan depending on the + // architecture. + if (!(bucketUnpacker && numRecords)) { + return std::pair{nullptr, false}; + } + // Use a 'TrialStage' to run a trial between 'SampleFromTimeseriesBucket' and // 'UnpackTimeseriesBucket' with $sample left in the pipeline in-place. If the buckets are // not sufficiently full, or the 'SampleFromTimeseriesBucket' plan draws too many -- cgit v1.2.1