The query shape serialization mechanism will map distinct query shapes to the same plan cache key. This can cause cache thrashing for the plan cache.
The encoding of plan cache keys for queries needs to (1) group lists, (2) perform escaping, and (3/4) delimit the query/sort/projection sections. See examples below.
// 1. db.foo.find({$or:[{a:1},{b:1},{c:1}],d:1}) // plan cache key = anoreqaeqbeqceqd db.foo.find({$or:[{a:1},{b:1}],c:1,d:1}) // plan cache key = anoreqaeqbeqceqd // 2. db.foo.find({a:1,b:1,c:1}) // plan cache key = aneqaeqbeqc db.foo.find({a:1,beqc:1}) // plan cache key = aneqaeqbeqc // 3. db.foo.find({a:1},{a:NumberInt(1)}) // plan cache key = eqap1a db.foo.find({ap1a:1}) // plan cache key = eqap1a // 4. db.foo.find({a:1}).sort({b:1}) // plan cache key = eqaab db.foo.find({aab:1}) // plan cache key = eqaab
- related to
-
SERVER-17158 sort component of internal plan cache key syntax is ambiguous
- Closed