我通过散列 _id 对我的 mongoDB 集群进行了分片。我检查了索引大小,有一个 _id_hashed 索引占用了很多空间:
"indexSizes" : { "_id_" : 14060169088, "_id_hashed" : 9549780576 },
mongoDB 手册说,如果您对集合进行分片,则会在分片键上创建一个索引。我想这就是 _id_hashed 索引存在的原因。
我的问题是:如果我只通过 _id 字段查询文档,那么 _id_hashed 索引是什么?我可以删除它吗?因为它占用太多空间。
ps:似乎mongoDB在查询时使用_id索引,而不是_id_hashed索引。查询的执行计划:
"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