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

Parse firstN/lastN/minN/maxN/topN/bottomN with n = 1 into a corresponding first/last/min/max/top/bottom

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 8.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • Fully Compatible
    • QO 2024-07-08, QO 2024-07-22
    • 0

      For example, $topN: {n: 1, ...} would have the exactly same semantics as $top: {...}. The single element accumulators would not need a mechanism to maintain multiple values. So, it would slightly perform better to process $top than $topN with n=1.

      On top of this, thanks to SERVER-87589/SERVER-84347, $sort + $group with $first/$last can be optimized into $group with $top/$bottom and $group with $top/$bottom can leverage DISTINCT_SCAN when there's a proper index but $group with $firstN, $lastN, $topN, and/or $bottomN can't.

      This ticket will extend the applicability of SERVER-87589/SERVER-84347 optimizations.

      I think that this would be better to be done in the parsing phase to avoid rewriting overhead than in the optimization phase since rewriting may also incur overhead and therefore it may affect very short-running pipeline performance.

            Assignee:
            alya.berciu@mongodb.com Alya Berciu
            Reporter:
            yoonsoo.kim@mongodb.com Yoon Soo Kim
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: