1
I haveread將索引放在低基數字段上是毫無意義的。 這會保持爲真爲一個複合索引這樣:MongoDB將低基數字段添加到複合索引?
db.perms.createIndex({"owner": 1, "object_type": 1, "target": 1});
隨着查詢,例如:
db.perms.find({"owner": "me", "object_type": "square"});
db.perms.find({"owner": "me", "object_type": "circle", "target": "you"});
的不同object_type
「第會隨時間而增加(量可能不超過10或20最大),但只會從大約2或3開始。
類似地,散列索引值得研究嗎?
UPDATE:
owner
和target
將大大增加。把它想象成一個文件系統,其中owner
將「擁有」一個target
(即文件)。但是,與unix系統一樣,文件可能是文件夾,符號鏈接或常規文件(因此是文件類型)。因此,雖然只有3 object_type
,但owner
和target
組合可能會有數千個條目均勻分佈。
我剛剛發佈了一個包含'cardinality'上的一些材料的答案,可以幫助你。 [Index Cardinality](http://stackoverflow.com/questions/33545339/how-does-the-order-of-compound-indexes-matter-in-mongodb-performance-wise/33546159#33546159) – inspired
此外,你可以不創建具有散列索引字段的複合索引。 https://docs.mongodb.org/manual/core/index-compound/#index-type-compound – inspired
這不是毫無意義,它只是...那麼,小心(與任何數據庫相同)。不要將它們作爲複合樹(索引)的頂層。至於你的索引:你有多少個「目標」值? – Sammaye