MySQL 8.0.40
Source Code Documentation
Cost_constant_cache Class Reference

This class implements a cache for "cost constant sets". More...

#include <opt_costconstantcache.h>

Public Member Functions

 Cost_constant_cache ()
 Creates an empty cost constant cache. More...
 
 ~Cost_constant_cache ()
 Destructor for the cost constant cache. More...
 
void init ()
 Initialize the cost module. More...
 
void close ()
 Close the cost constant cache. More...
 
void reload ()
 Reload all cost constants from the configuration tables. More...
 
const Cost_model_constantsget_cost_constants ()
 Get the currently used set of cost constants. More...
 
void release_cost_constants (const Cost_model_constants *cost_constants)
 Releases the cost constant set. More...
 

Private Member Functions

Cost_model_constantscreate_defaults () const
 Create default cost constants. More...
 
void update_current_cost_constants (Cost_model_constants *new_cost_constants)
 Replace the current cost constants with a new set of cost constants. More...
 

Private Attributes

Cost_model_constantscurrent_cost_constants
 The current set of cost constants that will be used by new sessions. More...
 
mysql_mutex_t LOCK_cost_const
 Mutex protecting the pointer to the current cost constant set and reference counting on all cost constant sets. More...
 
bool m_inited
 

Detailed Description

This class implements a cache for "cost constant sets".

This cache is responsible for creating the set of cost constant, giving new sessions access to the latest versions of the cost constants, and for re-reading the cost constant tables in the case where these have been updated.

The cost constant cache keeps a copy of the current set of cost constants. Each time a new session initializes its Cost_model_server object (by calling Cost_model_server::init() in lex_start()), the Cost_model_server object will request the cost constant cache to give it the current version of the cost constants. This is done by calling Cost_constant_cache::get_cost_constants(). This function will just return a pointer to the current set of cost constants. As time goes, new cost constant sets might be created and added to the cost constant cache. In order to know when a cost constant set can be deleted, reference counting is used. Each time a session asks for the cost constants, the reference counter is incremented. When the session releases the cost constant set by calling release_cost_constants(), the reference counter will be decremented. When the reference counter becomes zero, the cost constant set is deleted.

Constructor & Destructor Documentation

◆ Cost_constant_cache()

Cost_constant_cache::Cost_constant_cache ( )

Creates an empty cost constant cache.

Minimal initialization of the object.

To initialize it with default cost constants, init() must be called. To use cost constants from the cost constant tables, reload() must be called.

The main initialization is done by calling init().

◆ ~Cost_constant_cache()

Cost_constant_cache::~Cost_constant_cache ( )

Destructor for the cost constant cache.

Before the cost constant cache is deleted, close() must have been called.

Member Function Documentation

◆ close()

void Cost_constant_cache::close ( void  )

Close the cost constant cache.

All resources owned by the cost constant cache are released.

◆ create_defaults()

Cost_model_constants * Cost_constant_cache::create_defaults ( ) const
private

Create default cost constants.

This will create cost constants based on default values defined in the source code.

◆ get_cost_constants()

const Cost_model_constants * Cost_constant_cache::get_cost_constants ( )
inline

Get the currently used set of cost constants.

This function will just return a pointer to a shared version of the cost constants. For tracking of how many sessions that is using the set and to be able to know when it is safe to delete the cost constant object, reference counting is used. This function will increase the ref count for the returned cost constant object. To decrease the reference counter when the cost constants are no longer used, release_cost_constants() must be called.

Note
To ensure that the reference counter is only incremented once for each session that uses the cost constant set, this function should only be called once per session.
Returns
pointer to the cost constants

◆ init()

void Cost_constant_cache::init ( )

Initialize the cost module.

The cost constants will be initialized with the default values found in the source code. To start using the cost constant values found in the configuration tables, the reload() function must be called.

◆ release_cost_constants()

void Cost_constant_cache::release_cost_constants ( const Cost_model_constants cost_constants)
inline

Releases the cost constant set.

This will decrement the reference counter on the cost constant set and if nobody is using it, it will be deleted. This function should be called each time a client (a session) no longer has any use for a cost constant set that it has previously gotten from calling get_cost_constants()

Parameters
cost_constantspointer to the cost constant set

◆ reload()

void Cost_constant_cache::reload ( )

Reload all cost constants from the configuration tables.

◆ update_current_cost_constants()

void Cost_constant_cache::update_current_cost_constants ( Cost_model_constants new_cost_constants)
private

Replace the current cost constants with a new set of cost constants.

Parameters
new_cost_constantsthe new cost constants

Member Data Documentation

◆ current_cost_constants

Cost_model_constants* Cost_constant_cache::current_cost_constants
private

The current set of cost constants that will be used by new sessions.

◆ LOCK_cost_const

mysql_mutex_t Cost_constant_cache::LOCK_cost_const
private

Mutex protecting the pointer to the current cost constant set and reference counting on all cost constant sets.

◆ m_inited

bool Cost_constant_cache::m_inited
private

The documentation for this class was generated from the following files: