[SERVER-58317] $planCacheStats can incorrectly filter out cached plans when hidden indexes exist Created: 07/Jul/21  Updated: 07/Jul/21  Resolved: 07/Jul/21

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 4.4.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alex Bevilacqua Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-13341 Cache single solution query plans Needs Scheduling
Related
Operating System: ALL
Participants:

 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" }



 Comments   
Comment by Alex Bevilacqua [ 07/Jul/21 ]

This is technically "as designed" as single solution query plans aren't cached.

Flagging this as duplicate and leaving it here in case it helps other discover SERVER-13341.

Generated at Thu Feb 08 05:44:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.