-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query planner generating wrong bounds for compound indexes #46
Comments
$and
predicate
$and
predicate
A simpler case that reproduces the bug db.test.remove()
db.test.drop_indexes()
db.test.insert({'A': 'hello', 'B': 'world', 'C': 'HELLO'})
db.test.create_index([('A', pymongo.ASCENDING), ('B', pymongo.ASCENDING)])
db.test.create_index([('A', pymongo.ASCENDING), ('B', pymongo.ASCENDING), ('C', pymongo.ASCENDING)]) A simple query on this that supposed to match the document returns nothing In [38]: for row in db.test.find({'A': 'hello', 'B': 'world', 'C': 'HELLO'}):
...: print row
...:
In [39]: db.test.find({'A': 'hello', 'B': 'world', 'C': 'HELLO'}).explain()
Out[39]:
{
"explanation":{
"source_plan":{
"projection":"{}",
"source_plan":{
"filter":"ANY(ExtPath((B\\x00) matching EQUALS(\"world\"))",
"source_plan":{
"bounds":{
"begin":"(hello\\x00(HELLO\\x00",
"end":"(hello\\x00(HELLO\\x00"
},
"index name":"A_1_B_1_C_1",
"type":"index scan"
},
"type":"filter"
},
"type":"projection"
},
"type":"non-isolated"
}
}
In [40]: If we drop the indexes and try again In [40]: db.test.drop_indexes()
In [41]: for row in db.test.find({'A': 'hello', 'B': 'world', 'C': 'HELLO'}):
...: print row
...:
{u'A': u'hello', u'C': u'HELLO', u'B': u'world', u'_id': ObjectId('5c5b62e2945b2617f81e60a6')}
In [42]: db.test.find({'A': 'hello', 'B': 'world', 'C': 'HELLO'}).explain()
Out[42]:
{
"explanation":{
"source_plan":{
"projection":"{}",
"source_plan":{
"filter":"AND(ANY(ExtPath((A\\x00) matching EQUALS(\"hello\")), ANY(ExtPath((C\\x00) matching EQUALS(\"HELLO\")), ANY(ExtPath((B\\x00) matching EQUALS(\"world\")))",
"source_plan":{
"type":"table scan"
},
"type":"filter"
},
"type":"projection"
},
"type":"non-isolated"
}
}
In [43]: That gives the correct result. The bug is in the compound index matching scheme - code handles term by term in a multi-term predicate and tries to extend index such that longest prefix is matched. We have a bug in prefix handling. In the above example after matching term on This part of the code is a bit of a mess. As we do store integer only field names as integers (instead of strings), we try to store the index prefixes as byte streams ( |
Found this against d2840e9. Consistently reproducible with the above seed.
The text was updated successfully, but these errors were encountered: