sto cercando di riprodurre il primo esempio di istruzione di indice di intersezione (http://docs.mongodb.org/manual/core/index-intersection/), ma di fronte a un problema: mongo non utilizza entrambi gli indiciPerché MongoDB non usa Index Intersection?
miei passi:
- Scarica mongo (3.0.3) e installarlo
- Run mongod: mongod.exe --dbpath d: \ dati (cartella è vuota)
- Run mongo: mongo.exe
aggiungere indici:
db.orders.ensureIndex({ qty: 1 }) db.orders.ensureIndex({ item: 1 }) db.orders.getIndexes() [{ "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.orders" }, { "v" : 1, "key" : { "qty" : 1 }, "name" : "qty_1", "ns" : "test.orders" }, { "v" : 1, "key" : { "item" : 1 }, "name" : "item_1", "ns" : "test.orders" }]
Controllare interrogazione spiega:
db.orders.find({ item: "abc123", qty: { $gt: 15 } }).explain() { "queryPlanner" : { "plannerVersion" : 1, "namespace" : "test.orders", "indexFilterSet" : false, "parsedQuery" : { "$and" : [ { "item" : { "$eq" : "abc123" } }, { "qty" : { "$gt" : 15 } } ] }, "winningPlan" : { "stage" : "KEEP_MUTATIONS", "inputStage" : { "stage" : "FETCH", "filter" : { "qty" : { "$gt" : 15 } }, "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "item" : 1 }, "indexName" : "item_1", "isMultiKey" : false, "direction" : "forward", "indexBounds" : { "item" : [ "[\"abc123\", \"abc123\"]" ] } } } }, "rejectedPlans" : [ { "stage" : "KEEP_MUTATIONS", "inputStage" : { "stage" : "FETCH", "filter" : { "item" : { "$eq" : "abc123" } }, "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "qty" : 1 }, "indexName" : "qty_1", "isMultiKey" : false, "direction" : "forward", "indexBounds" : { "qty" : [ "(15.0, 1.#INF]" ] } } } } ] }, "serverInfo" : { "host" : "localhost", "port" : 27017, "version" : "3.0.3", "gitVersion" : "b40106b36eecd1b4407eb1ad1af6bc60593c6105" }, "ok" : 1 }
Come si può vedere winningPlan contiene solo item_1 indice. C'è respinto Ples che contiene qty_1 indice. Ma non ci sono piani che contengano l'intersezione dell'indice. So che ci sono molte condizioni per selezionare un indice specifico. Ma nel mio caso, mongo non lo pianifica nemmeno!
Qualcuno potrebbe aiutarmi?
FWIW, funziona allo stesso modo con MongoDB 3.0.2 –
Quanti documenti ci sono nel database? Cosa dice 'explain (true)' say? Quanto dura la query? Qual è la distribuzione dei campi di dati, se presente? – mnemosyn