MySQL 8.4.0
Source Code Documentation
Table_histograms_collection Class Reference

The Table_histograms_collection manages a collection of reference-counted snapshots of histogram statistics (Table_histograms objects) for a table. More...

#include <table_histograms.h>

Public Member Functions

 Table_histograms_collection ()
 
 Table_histograms_collection (Table_histograms_collection &&)=delete
 
Table_histograms_collectionoperator= (Table_histograms_collection &&)=delete
 
 Table_histograms_collection (const Table_histograms_collection &)=delete
 
Table_histograms_collectionoperator= (const Table_histograms_collection &)=delete
 
 ~Table_histograms_collection ()
 
const Table_histogramsacquire ()
 Acquire a pointer to the most recently inserted Table_histograms object. More...
 
void release (const Table_histograms *histograms)
 Release a previously acquired Table_histograms object, decreasing its reference count. More...
 
bool insert (Table_histograms *histograms)
 Attempt to insert the supplied Table_histograms object into the collection. More...
 
int total_reference_count () const
 Count the total number of TABLE objects referencing Table_histograms objects in the collection. More...
 
size_t size () const
 Counts the number of Table_histograms objects in the collection. More...
 

Private Member Functions

void free_table_histograms (size_t idx)
 Frees a Table_histograms object from the collection and sets its pointer to nullptr. More...
 

Private Attributes

std::array< Table_histograms *, kMaxNumberOfTableHistogramsInCollectionm_table_histograms
 
size_t m_current_index {0}
 

Detailed Description

The Table_histograms_collection manages a collection of reference-counted snapshots of histogram statistics (Table_histograms objects) for a table.

It is intended to live on the TABLE_SHARE and provide TABLE objects with reference-counted access to Table_histogram objects through the acquire() and release() methods. The motivation for this class is to decouple the lifetime of histogram statistics from the lifetime of the TABLE_SHARE, so that we avoid having to invalidate the TABLE_SHARE when updating/dropping histograms.

Multiple threads can be opening/closing tables concurrently. Member functions on the Table_histograms_collection should be protected by holding LOCK_open.

When the TABLE_SHARE is initialized and whenever the histograms associated with a table are updated, we create a new Table_histograms object, insert it into the collection, and mark it current.

Constructor & Destructor Documentation

◆ Table_histograms_collection() [1/3]

Table_histograms_collection::Table_histograms_collection ( )

◆ Table_histograms_collection() [2/3]

Table_histograms_collection::Table_histograms_collection ( Table_histograms_collection &&  )
delete

◆ Table_histograms_collection() [3/3]

Table_histograms_collection::Table_histograms_collection ( const Table_histograms_collection )
delete

◆ ~Table_histograms_collection()

Table_histograms_collection::~Table_histograms_collection ( )

Member Function Documentation

◆ acquire()

const Table_histograms * Table_histograms_collection::acquire ( )

Acquire a pointer to the most recently inserted Table_histograms object.

Increments the reference counter on the returned Table_histograms object.

Returns
Pointer to the current Table_histograms object or nullptr if none exists.

◆ free_table_histograms()

void Table_histograms_collection::free_table_histograms ( size_t  idx)
inlineprivate

Frees a Table_histograms object from the collection and sets its pointer to nullptr.

Parameters
idxIndex of the Table_histograms object to free.

◆ insert()

bool Table_histograms_collection::insert ( Table_histograms histograms)

Attempt to insert the supplied Table_histograms object into the collection.

The insertion will fail if the collection is full. If the insertion succeeds we mark the object as current and take ownership. The previous current object is deleted if it has a reference count of zero

Parameters
histogramsPointer to the Table_histograms object to be inserted.
Returns
False if the insertion took place, true otherwise.

◆ operator=() [1/2]

Table_histograms_collection & Table_histograms_collection::operator= ( const Table_histograms_collection )
delete

◆ operator=() [2/2]

Table_histograms_collection & Table_histograms_collection::operator= ( Table_histograms_collection &&  )
delete

◆ release()

void Table_histograms_collection::release ( const Table_histograms histograms)

Release a previously acquired Table_histograms object, decreasing its reference count.

If the reference count of a non-current Table_histograms object reaches zero we delete it. This frees up memory and makes room for a new Table_histograms object in the collection.

Parameters
histogramsPointer to a Table_histograms object to be released.

◆ size()

size_t Table_histograms_collection::size ( ) const

Counts the number of Table_histograms objects in the collection.

Primarily used for testing.

Returns
The count of non-null pointers to Table_histograms objects in the collection.

◆ total_reference_count()

int Table_histograms_collection::total_reference_count ( ) const

Count the total number of TABLE objects referencing Table_histograms objects in the collection.

Primarily used for testing.

Returns
The sum of Table_histogram reference counters. Zero if the collection is empty.

Member Data Documentation

◆ m_current_index

size_t Table_histograms_collection::m_current_index {0}
private

◆ m_table_histograms

std::array<Table_histograms *, kMaxNumberOfTableHistogramsInCollection> Table_histograms_collection::m_table_histograms
private

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