BugZero found this defect 70 days ago.
Data sources
All data on this page is proprietary to BugZero® or gathered from public sources
3/14/2024
MongoDB Server
No affected releases provided.
No fixed releases provided.
While distinct command may generate DISTINCT_SCAN plans, it doesn't do so in the case of views (including identity views).
const coll = assertDropAndRecreateCollection(db, "coll"); const viewName = "identityView"; assert.commandWorked(db.createView(viewName, coll.getName(), [])); assert.commandWorked(coll.createIndexes([{a: 1}])); // Performs DISTINCT_SCAN over 'a'. jsTestLog(coll.explain().distinct('a')); // Performs coll scan, while the rest of the work is done in agg. jsTestLog(db[viewName].explain().distinct('a')); // Performs index scan on 'a', while the rest of the work is done in agg. jsTestLog(db[viewName].explain().distinct('a', {}, {hint: 'a_1'}));