$and operator seems to be causing mongo to not use index.

34 views
Skip to first unread message

Sam Martin

unread,
Sep 29, 2012, 3:01:17 PM9/29/12
to mongod...@googlegroups.com
Hi all,

got a wierd problem,

using simple find on indexed attribute

{ "myatt":1234}

explained, all good using BTree index 

do an
 
{$and :[ {myattr:1234},{myatt:1234}]}

reverts to basic cursor

any ideas?

thanks,
sam

Sam Martin

unread,
Sep 29, 2012, 6:08:53 PM9/29/12
to mongod...@googlegroups.com
still cannot suss this one out.

Explain returns...

BasicCursor, nscanned 1M+

{ "$and" : 
[{ "kw" :/^term }
]}


whereas

{ "kw" :/^term }

is instant, and uses the Btree cursor multi


any ideas?

Thanks

Stephen Steneker

unread,
Sep 29, 2012, 11:31:15 PM9/29/12
to mongod...@googlegroups.com
still cannot suss this one out.

Hi Sam,

In your first example you were using two different fields (*myattr" and "myatt")  .. are both included in the index?

Can you include the full queries and the result of explain(true) for each?  Explain with the extra option will show all plans considered.

Cheers,
Stephen
Reply all
Reply to author
Forward
0 new messages