What is the _id_hashed index for in mongoDB? -
i sharded mongodb cluster hashed _id. checked index size, there lies _id_hashed index taking space:
"indexsizes" : { "_id_" : 14060169088, "_id_hashed" : 9549780576 },
mongodb manual says index on sharded key created if shard collection. guess reason _id_hashed index out there.
my question : _id_hashed index if query document _id field? can delete it? takes space.
ps: seems mongodb use _id index when query, not _id_hashed index. execution plan query:
"clusteredtype" : "parallelsort", "shards" : { "rs1/192.168.62.168:27017,192.168.62.181:27017" : [ { "cursor" : "btreecursor _id_", "ismultikey" : false, "n" : 0, "nscannedobjects" : 0, "nscanned" : 1, "nscannedobjectsallplans" : 0, "nscannedallplans" : 1, "scanandorder" : false, "indexonly" : false, "nyields" : 0, "nchunkskips" : 0, "millis" : 0, "indexbounds" : { "start" : { "_id" : "spiderman_task_captainstatus_30491467_2387600" }, "end" : { "_id" : "spiderman_task_captainstatus_30491467_2387600" } }, "server" : "localhost:27017" } ] }, "cursor" : "btreecursor _id_", "n" : 0, "nchunkskips" : 0, "nyields" : 0, "nscanned" : 1, "nscannedallplans" : 1, "nscannedobjects" : 0, "nscannedobjectsallplans" : 0, "millisshardtotal" : 0, "millisshardavg" : 0, "numqueries" : 1, "numshards" : 1, "indexbounds" : { "start" : { "_id" : "spiderman_task_captainstatus_30491467_2387600" }, "end" : { "_id" : "spiderman_task_captainstatus_30491467_2387600" } }, "millis" : 574
mongodb uses range based sharding approach. if choose use hashed based sharding, must have hashed index on shard key , cannot drop since used determine shard use subsequent queries ( note there open ticket allow drop _id index once hashed indexes allowed unique server-8031 ).
as why query appears using _id index rather _id_hashed index - ran tests , think optimizer choosing _id index because unique , results in more efficient plan. can see similar behavior if shard on key has pre-existing unique index.
Comments
Post a Comment