vectorSearch should not discard absorbed $limit when removing redundant $sort during optimization

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Integration
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      $vectorSearch::optimizeAt removes consecutive following sorts on "vectorSearchScore" on the assumption it is redundant. It does not check whether the $sort has already absorbed a trailing $limit into $_internalLimit.  Thus, if it removes  the $sort then the limit behavior won't apply, affecting performance.

      Instead of indiscriminately removing the redundant $sort with limit, the $sort's limit should be pushed down and then on a second pass in the RBR engine, the redundant $sort stage can be removed.

      A related ticket  will add a generic optimization to remove redundant $sorts that live on the $sort stage, then the $sort stage optimization itself can inspect its internals to determine if a $limit stage has been absorbed in its precondition. If so, the stage won't remove itself.

                                

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

              Created:
              Updated:
              Resolved: