-
Notifications
You must be signed in to change notification settings - Fork 852
Indexes not used when boolean operation is not explicit #1413
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
Comments
I can confirm that for a condition such as Consider this example: // create a test collection and insert a few values into it
db._drop("test");
db._create("test");
var values = [ null, false, true, -1, 0, 1, 2, "", " ", "1", "foo", [ ], [ 0 ], [ 1 ] ];
values.forEach(function(value) {
db.test.insert({ value: value });
});
// now query the collection using a boolean condition
db._query("FOR doc IN idx FILTER doc.value SORT doc.value RETURN doc.value").toArray(); This will match the following values and not only the boolean [
true,
-1,
1,
2,
" ",
"1",
"foo",
[ ],
[
0
],
[
1
]
] The values that are excluded here are If you need to compare the value to just a boolean |
Thanks. I was seeing the problem only within the context of my current use case. |
If you do |
@CoDEmanX : I don't think so. |
It seems that the query optimizer doesn't understand that a boolean variable is the equivalent of an equality operation, thereby ignoring valid indexes under the following circumstances.
I have a collection 'clients' with the following index:
indexes: [{type: 'hash', fields: ['online','userid'], minLength: 3, unique : false}]
(online is a boolean, and userid is a string)
when I call:
the plan uses the correct index like this:
However when I call:
The execution plan resorts to a full collection scan:
The text was updated successfully, but these errors were encountered: