¿Por qué $ in es mucho más rápido que $ all?
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^soto/, /^nasi/] } }).limit(200);
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$in" : [/^soto/, /^nasi/] } }).limit(200);
Este es el resultado
/* 88 */
{
"ts" : ISODate("2012-09-11T06:57:26.801Z"),
"op" : "query",
"ns" : "newisikota.tablebusiness",
"query" : {
"LongitudeLatitude" : {
"$nearSphere" : [106.772835, -6.186753],
"$maxDistance" : 0.053980478460939611
},
"Prominent" : {
"$gte" : 15.0
},
"indexContents" : {
"$all" : [/^soto/, /^nasi/]
}
},
"ntoreturn" : 200,
"nscanned" : 48,
"nreturned" : 48,
"responseLength" : 60002,
"millis" : 3821,
"client" : "127.0.0.1",
"user" : ""
}
/* 89 */
{
"ts" : ISODate("2012-09-11T06:57:43.147Z"),
"op" : "query",
"ns" : "newisikota.tablebusiness",
"query" : {
"LongitudeLatitude" : {
"$nearSphere" : [106.772835, -6.186753],
"$maxDistance" : 0.053980478460939611
},
"Prominent" : {
"$gte" : 15.0
},
"indexContents" : {
"$in" : [/^soto/, /^nasi/]
}
},
"ntoreturn" : 200,
"nscanned" : 200,
"nreturned" : 200,
"responseLength" : 249598,
"millis" : 320,
"client" : "127.0.0.1",
"user" : ""
}
Nota: la consulta $ all puede ejecutarse durante 26 segundos de vez en cuando.
El resultado explicativo es el siguiente:
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^soto/, /^nasi/] } }).limit(200).explain();
{
"cursor" : "GeoSearchCursor",
"nscanned" : 48,
**"nscannedObjects" : 48,**
"n" : 48,
"millis" : 8563,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
>
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$in" : [/^soto/, /^nasi/] } }).limit(200).explain();
{
"cursor" : "GeoSearchCursor",
"nscanned" : 200,
**"nscannedObjects" : 200,**
"n" : 200,
"millis" : 516,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
Observe que los $ en la búsqueda escanean más objetos.
Lo peor es lo peor, mongdob podría hacer $ en la búsqueda y luego filtrar las cosas. La proporción no debería ser enorme.