Add a rule to sort_rules.cpp that removes redundant $sorts with absorbed $limits

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

      SERVER-123972 adds a new REDUNDANT_SORT_REMOVAL rule that removes redundant $sorts by traversing the pipeline backwards. It currently skips optimizing $sorts with absorbed $limits to avoid silently erasing the $limit.

      This leaves an optimization gap for input pipelines with non-consecutive redundant $sorts that have absorbed $limits; ex: [$sort(a,b), $skip(2), $sort(a, $limit:5)] is never simplified because $sort's optimizeAt only coalesces adjacent sorts. The expected optimized pipeline is: [$sort(a,b), $skip(2), $limit(5)].

      This should be its own rule rather than an extension of REDUNDANT_SORT_REMOVAL, because its transform logic replaces the $sort with a bare $limit rather than erasing it.

            Assignee:
            Unassigned
            Reporter:
            Adithi Raghavan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: