[SERVER-38952] Prune redundant index bound Created: 11/Jan/19  Updated: 29/Oct/23  Resolved: 21/Feb/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.1.9

Type: Bug Priority: Major - P3
Reporter: Brigitte Lamarche (Inactive) Assignee: Arun Banala
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query 2019-01-28, Query 2019-02-25
Participants:
Linked BF Score: 45

 Description   

We hit this invariant when dealing with wildcard indexes and a query on a multikey field: 

https://github.com/10gen/mongo/blob/637adda0cefae579448117efcd868fa36f1010c0/src/mongo/db/query/index_bounds_builder.cpp#L1017

This will be hit because the list of index bounds for the wildcard index contains a redundant index bound, (a range of values is covered by two bounds).  

Reproduction: 

db.mycoll.drop();
db.mycoll.createIndex({"$**":1});
db.mycoll.insert({a:[1,2,3]});
db.mycoll.count({ 'a.0.0.0':{ $exists: true }});

This produces this failure:

INVALID BOUNDS: field #0['$_path']["a.0.0", "a.0.0"], ["a.0.0.", "a.0.0/"), ["a.0.0.0", "a.0.0.0"], ["a.0.0.0.", "a.0.0.0/"), field #1['a.0.0.0'][MinKey, MaxKey]kp = { $_path: 1.0, a.0.0.0: 1.0 }}}{{scanDir = 1

 These bounds are wrong because  "a.0.0/" in the second bound pair is greater than "a.0.0.0" in the third pair. (Comparison is done by string comparison). Check out attached BF for the full backtrace!

There exists code which is supposed to account for the case of redundant index bounds for a multi-key field, and prune the redundant index bound. 

https://github.com/mongodb/mongo/blob/d1f23f929359ab6a7a996cc35d1e063e0e9a12a3/src/mongo/db/query/planner_wildcard_helpers.cpp#L424-L443

However, this logic does not capture the case above. To complete this ticket will involve changing this logic to act correctly when seeing the case above. 

 

 

 

 

 



 Comments   
Comment by Githook User [ 21/Feb/19 ]

Author:

{'name': 'Arun Banala', 'username': 'banarun', 'email': 'arun.banala@mongodb.com'}

Message: SERVER-38952 Prune redundant index bound
Branch: master
https://github.com/mongodb/mongo/commit/8120e440ab45ab4bd8b1372aee23cae7fad6b01e

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