mongodb find rewrite
mongodb find 查询转换与重写,在语义和实际结果相同的前提下,实现
文章目录
mongodb find rewritewrite 1find coderesultexplain
write 2find coderesultexplain
write 3find coderesultexplain
write 1
find code
db.inventory.find
({$and:
[{qty:
{$gt:50,
$lt:100,
$type:1
}}]})
result
explain
> db.inventory.find
({$and:
[{qty:
{$gt:50,
$lt:100,
$type:1
}}]}).explain
()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "inventory.inventory",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"qty" : {
"$lt" : 100
}
},
{
"qty" : {
"$gt" : 50
}
},
{
"qty" : {
"$type" : [ 1
]
}
}
]
},
"queryHash" : "F8D429A6",
"planCacheKey" : "F8D429A6",
"winningPlan" : {
"stage" : "COLLSCAN",
"filter" : {
"$and" : [
{
"qty" : {
"$lt" : 100
}
},
{
"qty" : {
"$gt" : 50
}
},
{
"qty" : {
"$type" : [
1
]
}
}
]
},
"direction" : "forward"
},
"rejectedPlans" : [ ]
},
"serverInfo" : {
"host" : "node2",
"port" : 27017,
"version" : "4.2.7",
"gitVersion" : "51d9fe12b5d19720e72dcd7db0f2f17dd9a19212"
},
"ok" : 1
}
write 2
find code
db.inventory.find
({qty:
{$gt:50,
$lt:100,
$type:1
}})
result
explain
> db.inventory.find
({qty:
{$gt:50,
$lt:100,
$type:1
}}).explain
()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "inventory.inventory",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"qty" : {
"$lt" : 100
}
},
{
"qty" : {
"$gt" : 50
}
},
{
"qty" : {
"$type" : [
1
]
}
}
]
},
"queryHash" : "F8D429A6",
"planCacheKey" : "F8D429A6",
"winningPlan" : {
"stage" : "COLLSCAN",
"filter" : {
"$and" : [
{
"qty" : {
"$lt" : 100
}
},
{
"qty" : {
"$gt" : 50
}
},
{
"qty" : {
"$type" : [
1
]
}
}
]
},
"direction" : "forward"
},
"rejectedPlans" : [ ]
},
"serverInfo" : {
"host" : "node2",
"port" : 27017,
"version" : "4.2.7",
"gitVersion" : "51d9fe12b5d19720e72dcd7db0f2f17dd9a19212"
},
"ok" : 1
}
write 3
find code
db.inventory.find
({$and:
[{qty:
{$gt:50
}},
{qty:
{$lt:100
}},
{qty:
{$type:1
}}]})
result
explain
> db.inventory.find
({$and:
[{qty:
{$gt:50
}},
{qty:
{$lt:100
}},
{qty:
{$type:1
}}]}).explain
()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "inventory.inventory",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"qty" : {
"$lt" : 100
}
},
{
"qty" : {
"$gt" : 50
}
},
{
"qty" : {
"$type" : [
1
]
}
}
]
},
"queryHash" : "F8D429A6",
"planCacheKey" : "F8D429A6",
"winningPlan" : {
"stage" : "COLLSCAN",
"filter" : {
"$and" : [
{
"qty" : {
"$lt" : 100
}
},
{
"qty" : {
"$gt" : 50
}
},
{
"qty" : {
"$type" : [
1
]
}
}
]
},
"direction" : "forward"
},
"rejectedPlans" : [ ]
},
"serverInfo" : {
"host" : "node2",
"port" : 27017,
"version" : "4.2.7",
"gitVersion" : "51d9fe12b5d19720e72dcd7db0f2f17dd9a19212"
},
"ok" : 1
}