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

$planCacheStats can incorrectly filter out cached plans when hidden indexes exist

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 4.4.6
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL

      Description

      Hiding an index can result in cached plans no longer being accessible via the $planCacheStats pipeline stage.

      db.foo.drop();
      db.foo.insert({ a: 1, b: 1 });
      db.foo.createIndex({ a: 1 });
      db.foo.createIndex({ a: 1, b: 1 })
       
      var q = { a: { $gte: 1 }, b: 1 };
       
      db.foo.count(q);
      var key = db.foo.explain().count(q).queryPlanner.planCacheKey;
      //=> E7DCAC4F
       
      db.foo.aggregate([{ $planCacheStats: {} }, { $match: { planCacheKey: key } }, {$project: { plan: "$cachedPlan.indexName" } } ])
      //=> { "plan" : "a_1_b_1" }
       
      db.foo.hideIndex({ a: 1 })
       
      db.foo.count(q);
      var key2 = db.foo.explain().count(q).queryPlanner.planCacheKey;
      //=> E7DCAC4F
       
      db.foo.aggregate([{ $planCacheStats: {} }, { $match: { planCacheKey: key2 } }, {$project: { plan: "$cachedPlan.indexName" } } ])
      //=> no results
       
      db.foo.unhideIndex({ a: 1 })
       
      db.foo.count(q);
      var key3 = db.foo.explain().count(q).queryPlanner.planCacheKey;
      //=> E7DCAC4F
       
      db.foo.aggregate([{ $planCacheStats: {} }, { $match: { planCacheKey: key3 } }, {$project: { plan: "$cachedPlan.indexName" } } ])
      //=> { "plan" : "a_1_b_1" }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              alex.bevilacqua Alex Bevilacqua
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: