-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Index Maintenance
-
Minor Change
-
ALL
-
v4.2
-
-
Query 2019-06-17
-
(copied to CRM)
At present it is possible to generate an index with an empty string as the key type (eg a definition of {x:""}). The optimizer seems to be able to use this index when the key is a predicate in the query:
> db.repro.find({x:123}).explain() { "queryPlanner" : { "plannerVersion" : 1, "namespace" : "repro.repro", "indexFilterSet" : false, "parsedQuery" : { "x" : { "$eq" : 123 } }, "queryHash" : "716F281A", "planCacheKey" : "0FA0E5FD", "winningPlan" : { "stage" : "FETCH", "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "x" : "" }, "indexName" : "x_", "isMultiKey" : false, "multiKeyPaths" : { "x" : [ ] }, "isUnique" : false, "isSparse" : false, "isPartial" : false, "indexVersion" : 2, "direction" : "forward", "indexBounds" : { "x" : [ "[123.0, 123.0]" ] } } }, "rejectedPlans" : [ ] }, "serverInfo" : { "host" : "Chriss-MacBook-Pro.local", "port" : 27017, "version" : "4.1.10", "gitVersion" : "8cdc51e7810f7fd8898a4c60b935e389f04659ee" }, "ok" : 1 }
However it is unable to use the index to sort:
> db.repro.find({x:123}).sort({x:1}).explain() { "queryPlanner" : { "plannerVersion" : 1, "namespace" : "repro.repro", "indexFilterSet" : false, "parsedQuery" : { "x" : { "$eq" : 123 } }, "queryHash" : "87B348CE", "planCacheKey" : "F46EA305", "winningPlan" : { "stage" : "FETCH", "inputStage" : { "stage" : "SORT", "sortPattern" : { "x" : 1 }, "inputStage" : { "stage" : "SORT_KEY_GENERATOR", "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "x" : "" }, "indexName" : "x_", "isMultiKey" : false, "multiKeyPaths" : { "x" : [ ] }, "isUnique" : false, "isSparse" : false, "isPartial" : false, "indexVersion" : 2, "direction" : "forward", "indexBounds" : { "x" : [ "[123.0, 123.0]" ] } } } } }, "rejectedPlans" : [ ] }, "serverInfo" : { "host" : "Chriss-MacBook-Pro.local", "port" : 27017, "version" : "4.1.10", "gitVersion" : "8cdc51e7810f7fd8898a4c60b935e389f04659ee" }, "ok" : 1 } > db.repro.find().sort({x:1}).explain() { "queryPlanner" : { "plannerVersion" : 1, "namespace" : "repro.repro", "indexFilterSet" : false, "parsedQuery" : { }, "queryHash" : "B7791BAD", "planCacheKey" : "B7791BAD", "winningPlan" : { "stage" : "SORT", "sortPattern" : { "x" : 1 }, "inputStage" : { "stage" : "SORT_KEY_GENERATOR", "inputStage" : { "stage" : "COLLSCAN", "direction" : "forward" } } }, "rejectedPlans" : [ ] }, "serverInfo" : { "host" : "Chriss-MacBook-Pro.local", "port" : 27017, "version" : "4.1.10", "gitVersion" : "8cdc51e7810f7fd8898a4c60b935e389f04659ee" }, "ok" : 1 }
This type of index should fail validation and not be created.