在查詢時(shí),僅使用了復(fù)合索引其中的一個(gè),會(huì)不會(huì)用到復(fù)合索引
mongodb創(chuàng)建一個(gè)復(fù)合索引,db.test.ensureIndex({x:1,y:1});
db.test.find({x:1});能用到這個(gè)復(fù)合索引么
mongodb創(chuàng)建一個(gè)復(fù)合索引,db.test.ensureIndex({x:1,y:1});
db.test.find({x:1});能用到這個(gè)復(fù)合索引么
2017-06-05
舉報(bào)
2017-06-06
復(fù)合索引中字段的組合順序很重要,這和數(shù)據(jù)庫(kù)索引一樣,索引的匹配仍然遵循“最左前綴”原則。
如你給的例子,
db.test.find({x:1,y:1});
db.test.find({x:1});
可以使用索引,但db.test.find({y:1});則不能使用索引