[SERVER-13422] Planner can create incorrect ixscan leaves for index intersection w/ $elemMatch object Created: 31/Mar/14  Updated: 11/Jul/16  Resolved: 31/Mar/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.0-rc2
Fix Version/s: 2.6.0-rc3

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: David Storch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Participants:

 Description   

Repro with this script:

var t = db.t;
t.drop();
 
t.ensureIndex({"shortId": 1});
t.ensureIndex({"a.b.startDate": 1});
t.ensureIndex({"a.b.endDate": 1});
 
// Make _startDate and _endDate indices multikey.
t.save({a: [{b: {startDate: new Date(), endDate: new Date()}},
            {b: {startDate: new Date(), endDate: new Date()}}]});
 
t.find({"shortId": "aj72u4",
        _sites: { $in: [ "foo", "bar" ] },
        _allNamespaces: { $in: [ "1", "2", "3", "4" ] },
        "a.b": { $elemMatch: { startDate: { $lte: new Date(1388462400000) },
                               endDate: { $gt: new Date(1388462400000) },
                               _r: { $in: [ BinData(0,true) ] },
                               _p: { $in: [ BinData(0,true), BinData(0,true)  ] },
                               _o: { $in: [ BinData(0,true) ] } } }
        }).itcount();

The sixth and final indexed solution generated by the planner should have one index scan over "startDate" and one index scan over "endDate". Instead, both child index scans are over "startDate":

------------AND_HASH
---------------fetched = 0
---------------sortedByDiskLoc = 0
---------------getSort = [{ a.b.startDate: 1 }, ]
---------------Child 0:
---------------IXSCAN
------------------keyPattern = { a.b.startDate: 1.0 }
------------------direction = 1
------------------bounds = field #0['a.b.startDate']: (true, new Date(1388462400000)]
------------------fetched = 0
------------------sortedByDiskLoc = 0
------------------getSort = [{ a.b.startDate: 1 }, ]
---------------Child 1:
---------------IXSCAN
------------------keyPattern = { a.b.startDate: 1.0 }
------------------direction = 1
------------------bounds = field #0['a.b.startDate']: (new Date(1388462400000), new Date(9223372036854775807)]
------------------fetched = 0
------------------sortedByDiskLoc = 0
------------------getSort = [{ a.b.startDate: 1 }, ]



 Comments   
Comment by Githook User [ 31/Mar/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-13422 fix planning bug for elemMatch object index intersection

(cherry picked from commit 58f603c00d7ef8372c4f412755e43dee7d7f5ac9)
Branch: v2.6
https://github.com/mongodb/mongo/commit/67ec5c5b2926b682db1e21c22b1878043438827c

Comment by Githook User [ 31/Mar/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-13422 fix planning bug for elemMatch object index intersection
Branch: master
https://github.com/mongodb/mongo/commit/58f603c00d7ef8372c4f412755e43dee7d7f5ac9

Generated at Thu Feb 08 03:31:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.