-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
None
-
Query
-
Fully Compatible
-
ALL
$nin always need to return most of the data.so collscan always more efficiency than index scan.as index scan need to query twice.
but have found mongo does not choose COLLSCAN for $nin operation.
have created a collection conn in mongo 3.4 env.
db.conn.insert({ sourceId: targetId: }) db.conn.createIndex({targetId:1})
but when I execute
db.conn.find({targetId: {$nin:['xxx']}}).explain("executionStats")
find that mongo choose IXSCAN instead of COLLSCAN stage.
when the document record is 100K,1M.
it always choose COLLSCAN.
and the result is that IXSCAN spend more time than COLLSCAN
COLLSCAN:
"executionStats" : { "executionSuccess" : true, "nReturned" : 999004, "executionTimeMillis" : 406, "totalKeysExamined" : 0, "totalDocsExamined" : 1000000, "executionStages" : { "stage" : "COLLSCAN", "filter" : { "$not" : { "targetId" : { "$in" : [ "abc1234" ] } } },
INSCAN:
"executionStats" : { "executionSuccess" : true, "nReturned" : 999004, "executionTimeMillis" : 1863, "totalKeysExamined" : 999005, "totalDocsExamined" : 999004, "executionStages" : {
can anyone help explain this?
- duplicates
-
SERVER-13065 Consider a collection scan even if indexed plans are available
- Backlog
- related to
-
SERVER-23406 index scan is slower than full collection scan in some scenarios
- Closed