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

$sort with $group and $first and SBE does a full index scan

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 7.0.0
    • Component/s: None
    • Labels:
      None
    • Query Optimization
    • ALL

      db.index.explain().aggregate({$sort:{a:1}},{$group:{_id:0, a:{$first:"$a"}}})
      {
        explainVersion: '2',
        queryPlanner: {
          namespace: 'test.index',
          indexFilterSet: false,
          parsedQuery: {},
          queryHash: '5416DB9E',
          planCacheKey: '2C4F0CBD',
          optimizedPipeline: true,
          maxIndexedOrSolutionsReached: false,
          maxIndexedAndSolutionsReached: false,
          maxScansToExplodeReached: false,
          winningPlan: {
            queryPlan: {
              stage: 'GROUP',
              planNodeId: 3,
              inputStage: {
                stage: 'PROJECTION_COVERED',
                planNodeId: 2,
                transformBy: { a: true, _id: false },
                inputStage: {
                  stage: 'IXSCAN',
                  planNodeId: 1,
                  keyPattern: { a: 1, b: 1 },
                  indexName: 'a_1_b_1',
                  isMultiKey: false,
                  multiKeyPaths: { a: [], b: [] },
                  isUnique: false,
                  isSparse: false,
                  isPartial: false,
                  indexVersion: 2,
                  direction: 'forward',
                  indexBounds: { a: [ '[MinKey, MaxKey]' ], b: [ '[MinKey, MaxKey]' ] }
                }
              }
            },
            slotBasedPlan: {
              slots: '$$RESULT=s10 env: { s2 = Nothing (SEARCH_META), s4 = 1710513544145 (NOW), s1 = TimeZoneDatabase(Etc/GMT-14...Africa/Bujumbura) (timeZoneDB), s3 = Timestamp(1710513542, 1) (CLUSTER_TIME) }',
              stages: '[3] mkbson s10 [_id = s9, a = s7] true false \n' +
                '[3] project [s9 = 0] \n' +
                '[3] group [] [s7 = first((s5 ?: null))] spillSlots[s8] mergingExprs[first((s8 ?: null))] \n' +
                '[1] ixseek KS(0A0A0104) KS(F0F0FE04) none s6 none none lowPriority [s5 = 0] @"ba1ce78f-0524-475b-8c44-f2488f71f8aa" @"a_1_b_1" true '
            }
          },
          rejectedPlans: []
        },
       

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: