[SERVER-25442] OR query does not use middle field of a compound index Created: 04/Aug/16  Updated: 04/Aug/16  Resolved: 04/Aug/16

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 3.2.8
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Simon Cooper Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-13732 Predicates in top-level implicit AND ... Closed
Operating System: ALL
Steps To Reproduce:

db.test.insert({f1: 10, f2: 10, f3: 20 })
db.test.insert({f1: 10, f2: 30, f3: 20 })
db.test.createIndex({f2: 1, f1: 1, f3: 1})
 
db.test.find({ f1: 10, $or: [ { f2: 10, f3: 20 }, {f2: 30, f3: 20 } ] })

The query plan will have two index scans with the following bounds:

"indexBounds" : {
        "f2" : [
                "[30.0, 30.0]"
        ],
        "f1" : [
                "[MinKey, MaxKey]"
        ],
        "f3" : [
                "[20.0, 20.0]"
        ]
}

Note the [MinKey, MaxKey] on the bounds for f1. This should be [10, 10], from the condition in the query

Participants:

 Description   

When doing an OR query with an equality match, if the equality match is on one of the fields of a compound index, bounds are not applied to that index correctly



 Comments   
Comment by Kelsey Schubert [ 04/Aug/16 ]

Hi thecoop1984,

Thanks for the report. This issue is tracked in SERVER-13732 and a workaround in the application layer is presented. Please feel to vote for SERVER-13732 and watch it for updates.

Kind regards,
Thomas

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