Last active
April 1, 2016 20:25
-
-
Save rectalogic/07195f36fb4466b346a8f8cce559ee9b to your computer and use it in GitHub Desktop.
regex prefix on unique and nonunique indices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cureatr:PRIMARY> use test | |
cureatr:PRIMARY> db.foo.createIndex({prefix: 1, unique: 1}, {unique: true}) | |
cureatr:PRIMARY> db.foo.createIndex({prefix : 1, nonunique: 1}) | |
cureatr:PRIMARY> db.foo.explain().find({prefix: "a", nonunique: /^a/i}) | |
{ | |
"queryPlanner" : { | |
"plannerVersion" : 1, | |
"namespace" : "test.foo", | |
"indexFilterSet" : false, | |
"parsedQuery" : { | |
"$and" : [ | |
{ | |
"prefix" : { | |
"$eq" : "a" | |
} | |
}, | |
{ | |
"nonunique" : /^a/i | |
} | |
] | |
}, | |
"winningPlan" : { | |
"stage" : "FETCH", | |
"inputStage" : { | |
"stage" : "IXSCAN", | |
"filter" : { | |
"nonunique" : /^a/i | |
}, | |
"keyPattern" : { | |
"prefix" : 1, | |
"nonunique" : 1 | |
}, | |
"indexName" : "prefix_1_nonunique_1", | |
"isMultiKey" : false, | |
"direction" : "forward", | |
"indexBounds" : { | |
"prefix" : [ | |
"[\"a\", \"a\"]" | |
], | |
"nonunique" : [ | |
"[\"\", {})", | |
"[/^a/i, /^a/i]" | |
] | |
} | |
} | |
}, | |
"rejectedPlans" : [ | |
{ | |
"stage" : "KEEP_MUTATIONS", | |
"inputStage" : { | |
"stage" : "FETCH", | |
"filter" : { | |
"nonunique" : /^a/i | |
}, | |
"inputStage" : { | |
"stage" : "IXSCAN", | |
"keyPattern" : { | |
"prefix" : 1, | |
"unique" : 1 | |
}, | |
"indexName" : "prefix_1_unique_1", | |
"isMultiKey" : false, | |
"direction" : "forward", | |
"indexBounds" : { | |
"prefix" : [ | |
"[\"a\", \"a\"]" | |
], | |
"unique" : [ | |
"[MinKey, MaxKey]" | |
] | |
} | |
} | |
} | |
} | |
] | |
}, | |
"serverInfo" : { | |
"host" : "cureatr-vm", | |
"port" : 27017, | |
"version" : "3.0.5", | |
"gitVersion" : "8bc4ae20708dbb493cb09338d9e7be6698e4a3a3" | |
}, | |
"ok" : 1 | |
} | |
cureatr:PRIMARY> db.foo.explain().find({prefix: "a", unique: /^a/i}) | |
{ | |
"queryPlanner" : { | |
"plannerVersion" : 1, | |
"namespace" : "test.foo", | |
"indexFilterSet" : false, | |
"parsedQuery" : { | |
"$and" : [ | |
{ | |
"prefix" : { | |
"$eq" : "a" | |
} | |
}, | |
{ | |
"unique" : /^a/i | |
} | |
] | |
}, | |
"winningPlan" : { | |
"stage" : "KEEP_MUTATIONS", | |
"inputStage" : { | |
"stage" : "FETCH", | |
"filter" : { | |
"unique" : /^a/i | |
}, | |
"inputStage" : { | |
"stage" : "IXSCAN", | |
"keyPattern" : { | |
"prefix" : 1, | |
"nonunique" : 1 | |
}, | |
"indexName" : "prefix_1_nonunique_1", | |
"isMultiKey" : false, | |
"direction" : "forward", | |
"indexBounds" : { | |
"prefix" : [ | |
"[\"a\", \"a\"]" | |
], | |
"nonunique" : [ | |
"[MinKey, MaxKey]" | |
] | |
} | |
} | |
} | |
}, | |
"rejectedPlans" : [ | |
{ | |
"stage" : "FETCH", | |
"inputStage" : { | |
"stage" : "IXSCAN", | |
"filter" : { | |
"unique" : /^a/i | |
}, | |
"keyPattern" : { | |
"prefix" : 1, | |
"unique" : 1 | |
}, | |
"indexName" : "prefix_1_unique_1", | |
"isMultiKey" : false, | |
"direction" : "forward", | |
"indexBounds" : { | |
"prefix" : [ | |
"[\"a\", \"a\"]" | |
], | |
"unique" : [ | |
"[\"\", {})", | |
"[/^a/i, /^a/i]" | |
] | |
} | |
} | |
} | |
] | |
}, | |
"serverInfo" : { | |
"host" : "cureatr-vm", | |
"port" : 27017, | |
"version" : "3.0.5", | |
"gitVersion" : "8bc4ae20708dbb493cb09338d9e7be6698e4a3a3" | |
}, | |
"ok" : 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment