Use distinct scan for $group+$top/$bottom and $sort when sort orders are compatible

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

      When the distinct scan shard filtering feature is enabled (featureFlagShardFilteringDistinctScan from SPM-3182), $sort + $group pipelines fail to generate the DistinctScan plan. Instead, they opt in for less efficient IndexScan or CollScan plans (when an index is unavailable), even if a DistinctScan plan is available and chosen when the feature is disabled. This results in a significant performance hit.

        1. explain_without.txt
          4 kB
        2. explain_with.txt
          6 kB

            Assignee:
            Unassigned
            Reporter:
            Alexander Ignatyev
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: