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

Properly set the ‘preserveOrderAndMetadata’ field for common aggregation states

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Integration

      The field 'preserveOrderAndMetadata' on the StageConstraints struct describes, as the name suggests, whether any given stage preserves the ordering of the documents it outputs and preserves the metadata on those documents.

       

      The StageConstraints struct is available for any DocumentSource, and must be implemented by any concrete DocumentSource.

      Currently, there are many stages that do not specify that they preserveOrderAndMetadata when they do. We need as many stages as possible properly tagged with this field, so that we can perform a generic optimization related removing $sorts. Specifically, if we know that a stage outputs documents in a sorted order, any number of stages that all preserve the sort order should be able to be placed between that stage and a $sort stage that sorts on the same criteria for the $sort to be safely removed.

      This ticket enables previous optimizations in SERVER-96059, SERVER-96064, & SERVER-96065 to be further generalized to more pipeline types.

      Were most interested in tagging the most commonly used stages in this PR, and we should aim to be as exhaustive as possible while not blocking on obscure stages. Some stages of interest might be: $match, $limit, $skip, $lookup.

       

      We may also consider introducing a second field that specifics if the stage preserves the order, if the ordering is on metadata. Some stages can't guarantee that the result order will be preserved on a normal field, but could, if the ordering was on a metadata fields like: $project, $addFields, $set, $replaceWith, $unwind.

            Assignee:
            Unassigned Unassigned
            Reporter:
            joseph.shalabi@mongodb.com Joe Shalabi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: