-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
Query Optimization
-
(copied to CRM)
Currently when an index is multikey the filter step for the regex match gets bumped out of the IXSCAN stage and into the FETCH stage. The logical reason for this is not immediately clear and it seems that this may be unnecessary. The result of this is that we fetch and examine documents that won't match the regex even though we could have concluded that based on information available during the IXSCAN.
diff:PRIMARY> db.version() 3.4.3 diff:PRIMARY> c.createIndex({x:1}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } diff:PRIMARY> c.find({x:/1/}).explain().queryPlanner.winningPlan { "stage" : "FETCH", "inputStage" : { "stage" : "IXSCAN", "filter" : { "x" : { "$regex" : "1" } }, "keyPattern" : { "x" : 1 }, "indexName" : "x_1", "isMultiKey" : false, "multiKeyPaths" : { "x" : [ ] }, "isUnique" : false, "isSparse" : false, "isPartial" : false, "indexVersion" : 2, "direction" : "forward", "indexBounds" : { "x" : [ "[\"\", {})", "[/1/, /1/]" ] } } } diff:PRIMARY> c.insert({x:[1,2]}) WriteResult({ "nInserted" : 1 }) diff:PRIMARY> c.find({x:/1/}).explain().queryPlanner.winningPlan { "stage" : "FETCH", "filter" : { "x" : { "$regex" : "1" } }, "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "x" : 1 }, "indexName" : "x_1", "isMultiKey" : true, "multiKeyPaths" : { "x" : [ "x" ] }, "isUnique" : false, "isSparse" : false, "isPartial" : false, "indexVersion" : 2, "direction" : "forward", "indexBounds" : { "x" : [ "[\"\", {})", "[/1/, /1/]" ] } } }
- is duplicated by
-
SERVER-43989 Regex query not matching correctly on compound index
- Closed