[SERVER-59332] Convert PlanCache to a template class Created: 12/Aug/21  Updated: 29/Oct/23  Resolved: 27/Aug/21

Status: Closed
Project: Core Server
Component/s: Query Planning
Affects Version/s: None
Fix Version/s: 5.1.0-rc0

Type: Task Priority: Major - P3
Reporter: David Storch Assignee: Joshua Lapacik (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: QE 2021-09-06
Participants:

 Description   

We plan to make the current PlanCache more generic so that it can be used to implement both the existing plan cache for the classic engine, as well as the SBE plan cache. We will have a PlanCacheBase<KeyType, CachedPlanType> base class which has template parameters for the type of the plan cache key as well as the type of cached plan. The SBE/classic plan classes will each instantiate this template class.

As a first step, we need to do a bit of surgery to the current PlanCache in order to turn it into a template class. We should try to do this as mechanically as possible to keep this first patch relatively simple. A few notes:

  • There will be a lot of code motion here. We need to move most of the code in plan_cache.cpp into the header file in order to templatize the necessary types.
  • Right now you can't use logv2 from a header file. We'll have to deal with this. We handled this elsewhere by making the templated code call simple helper functions to do the logging. Example here.
  • You'll need to turn not only PlanCache but also CachedSolution and PlanCacheEntry into template classes.
  • This patch won't actually interact at all with the SBE plan cache just yet. We will have template instantiations only for the classic engine. This is just prep work.


 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by David Storch [ 27/Aug/21 ]

acm, I don't think there is a fundamental reason that we are not implementing this with runtime polymorphism, but in my experiments with the code the template-based approach seemed easier to implement. If I recall correctly, this had to do with the fact that the underlying data structure which backs the plan cache is already a the template class LRUKeyValue<K, V>.

Comment by Githook User [ 25/Aug/21 ]

Author:

{'name': '80741223+jlap199@users.noreply.github.com', 'email': '80741223+jlap199@users.noreply.github.com', 'username': 'jlap199'}

Message: SERVER-59332 Convert PlanCache to a template class
Branch: master
https://github.com/mongodb/mongo/commit/3820bd5558ccc46958cba972676501c1e9b56330

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