indexing - mongodb: non-performant indexes -


after playing

db.largecollection.find( { $or : [ { identifierx : "sha1_hash123" } , { identifiery : "md5_hash456" } , { identifierz : "another_hash789" } ] } )

i checked indexes mongodb prepared automatically. in addition "single" ensureindex identifiers x/y/z, there identifierx_1_identifiery_1_identifierz_1 , performance down :-(

do have idea or tip how explain mongodb it's faster use indexes single identifiers because not have $and, $or queries?

thx

mongodb doesn't create indexes on own. it's application, user, or framework does. query, mongodb use index either of identifierx, identifiery or identifierz. however, if don't have such index of course none used. identifierx_1_identifiery_1_identifierz_1 index can not used query.

in case, need make index of identifiers:

db.ensureindex( { 'identifierx' : 1 } ); db.ensureindex( { 'identifiery' : 1 } ); db.ensureindex( { 'identifierz' : 1 } ); 

mongodb can use 1 index @ time, , try pick "best" one. try using explain see indexed being picked:

db.largecollection.find( { $or : [     { identifierx : "sha1_hash123" },     { identifiery : "md5_hash456" },     { identifierz : "another_hash789" } ] } ).explain(); 

that should give ideas on index being used.

there exception $or though, mongodb can use different index each of parts , de-dup you. it's here in docs. (of course) still not use compound index, , need indexes i've written here above.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -