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

Missing optimization in the time-series unpack bucket stage

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

      The unpack bucket stage first checks if any rewrites are possible , if so, does push downs, and only after this tries to optimize the end of the pipeline. This results in sub-optimal scenarios. For example, for `db.coll.aggregate([\{$sort: {"m": 1}}, \{$skip: 1}, \{$limit: 1}])`, `$sort` gets pushed down before `_internalUnpackBucket` instead of topKSort. However, in cases such as

      db.coll.aggregate([
          {
              "$match": {
                  "$nor": [
                      {"t": {"$in": []}},
                  ]
              }
          },
          {"$sort": {"m": 1}},
          {"$skip": 1},
          {"$limit": 1}
      ]
      )

      topKSort is pushed down because the presence of `$match` stage between  `_internalUnpackBucket` and `$sort` results in the optimization of the end of the pipeline.

            Assignee:
            Unassigned Unassigned
            Reporter:
            sopho.kevlishvili@mongodb.com Sopho Kevlishvili
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None