[SERVER-75037] CWI: count on non-wildcard field returns incorrect results when CWI is used Created: 20/Mar/23  Updated: 29/Oct/23  Resolved: 20/Mar/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Alexander Ignatyev Assignee: Alexander Ignatyev
Resolution: Fixed Votes: 0
Labels: M4
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

function reproduce(coll, indexKeyPattern, doc, filter) {
    coll.drop();
    coll.createIndex(indexKeyPattern);
    coll.insertOne(doc);
    const findCount = coll.find(filter).count();
    const aggregateCount = coll.aggregate([{$match: filter}, {$count: "count"}]).toArray();
    console.log('==============================================');
    console.log(JSON.stringify(doc, null, 2));
    console.log(findCount);
    console.log(JSON.stringify(aggregateCount, null, 2));
}
 
const docs = [
    {
        _id: 269,
        obj: {
            obj: {
                date: ISODate("2019-06-24T22:40:06.624Z"),
                obj: {
                    _id: 273,
                    str: 'Zimbabwe Svalbard & Jan Mayen Islands Personal Loan Account',
                    date: null,
                },
            }
        }
    },
    {
        _id: 269,
        obj: {
            obj: {
                date: ISODate("2019-06-24T22:40:06.624Z"),
                obj: {
                    _id: 273,
                    str: 'Zimbabwe Svalbard & Jan Mayen Islands Personal Loan Account',
                    date: null,
                    array: null,
                    obj: {
                        _id: 274,
                        str: 'partnerships',
                        date: ISODate("2019-07-24T16:08:45.196Z"),
                        array: [],
                        geoJson: {type: 'Point', coordinates: [Array]},
                        any: 'virtual intangible Chair'
                    }
                }
            },
        }
    },
];
 
const indexKeyPattern = {
    'obj.obj.date': -1,
    'obj.obj.obj.$**': -1
};
 
const filter = {
    'obj.obj.date': {'$lte': ISODate("2019-10-06T22:12:37.493Z")}
};
 
for (const doc of docs) {
    reproduce(db.testColl, indexKeyPattern, doc, filter);
}

Sprint: QO 2023-04-03
Participants:
Linked BF Score: 135

 Description   

count on non-wildcard field returns incorrect results when a compound wildcard index is used

https://evergreen.mongodb.com/task/mongodb_mongo_master_enterprise_rhel_80_64_bit_dynamic_all_feature_flags_required_display_aggregation_wildcard_fuzzer_ca31ca64604313d363ade31d3db52225b570ff18_23_03_15_14_53_24

Running Aggregation: 3149



 Comments   
Comment by Githook User [ 20/Mar/23 ]

Author:

{'name': 'Alexander Ignatyev', 'email': 'alexander.ignatyev@mongodb.com', 'username': 'aligusnet'}

Message: SERVER-75037 Fix COUNT_SCAN stage when CWI is used.
Branch: master
https://github.com/mongodb/mongo/commit/8f52dfc86326c394a4c3ef71cd9aac8c62494b2e

Generated at Thu Feb 08 06:29:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.