summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/pipeline_d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/pipeline_d.cpp')
-rw-r--r--src/mongo/db/pipeline/pipeline_d.cpp10
1 files changed, 10 insertions, 0 deletions
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<TrialStage*>(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