Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-13007

Query plan cache key not unique to query shape

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.0-rc1
    • Affects Version/s: 2.6.0-rc0
    • Component/s: Querying
    • Fully Compatible
    • ALL

      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
      

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: