Operational Defect Database

BugZero found this defect 65 days ago.

MongoDB | 2609976

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

Last update date:

3/16/2024

Affected products:

MongoDB Server

Affected releases:

7.0.0

Fixed releases:

No fixed releases provided.

Description:

Info

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: [] },

Top User Comments

asya commented on Fri, 15 Mar 2024 14:59:25 +0000: Ok I think I used the wrong test here - when grouping by a and getting first of b it correctly uses DISTINCT_SCAN with both engines.

Steps to Reproduce


Additional Resources / Links

Share:

BugZero® Risk Score

What's this?

Coming soon

Status

Closed

Learn More

Search:

...