Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-73526

DocumentSourceGroup should spill in debug builds when allowDiskUse is true, not when allowDiskUse is false

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.0-rc0
    • Affects Version/s: None
    • Component/s: Query Execution
    • None
    • Fully Compatible
    • QE 2023-05-15

      There is longstanding behavior in which DocumentSourceGroup will spill eagerly in debug builds, even when the memory limit is not yet exhausted. (Similar behavior was added in SBE's HashAggStage as part of SERVER-70395.) The goal is to gain extra coverage of the spilling logic in test environments. We currently perform this test-only extraneous spilling only when allowDiskUse is false. See here:

      https://github.com/mongodb/mongo/blob/8a1ce1c8c1b902c60b421e14feca681bee735547/src/mongo/db/pipeline/document_source_group_base.cpp#L548

      This dates from the days when disk use was disallowed by default. The rationale was that when disk use is allowed, this means that the client has explicitly enabled spilling. and the query is likely trying to test spilling behavior explicitly. In such situations, the logic to spill eagerly did not kick in, as it could interfere with spilling-related tests. On the other hand, when disk use was not explicitly enabled, we would spill in the background, thus ensuring that all of our $group tests unrelated to spilling still work as expected even if spilling occurs.

      SERVER-63208 recently made queries allow disk use by default, which rendered the debug build behavior described above stale. We are now only getting additional spilling test coverage in debug builds for queries that pass allowDiskUse:false explicitly. This is presumably quite rare, and therefore we have lost useful test coverage. It is also arguably incorrect to spill to disk in debug builds even if spilling was explicitly prohibited by the client.

      The work for this ticket is to invert the logic so that the extra spilling in debug builds kicks in when allowDiskUse is true and not when allowDiskUse is false. This may require adjusting tests that make assertions about spill-related execution stats to either not run against debug builds, or to expect different spill behavior when running against a debug build.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: