-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
The $sample stage is implemented as a random sort + limit (when N > %5 of documents in the collection, more details here). This sort is subject to the sort memory restrictions (100MB before spilling to disk). In the case that allowDiskUse is false and this limit is hit, the error message isĀ
PlanExecutor error during aggregation :: caused by :: Sort exceeded memory limit of 33554432 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.
This is a confusing error message to see for a $sample query as it requires in-depth knowledge of $sample's implementation. We should improve it to be clearer.