MySQL 8.4.2
Source Code Documentation
hash_table_t Class Reference

#include <hash0hash.h>

Public Member Functions

 hash_table_t (size_t n)
 
 ~hash_table_t ()
 
size_t get_n_cells ()
 Returns number of cells in cells[] array. More...
 
const ut::fast_modulo_t get_n_cells_fast_modulo ()
 Returns a helper class for calculating fast modulo n_cells. More...
 
void set_n_cells (size_t n)
 Sets the number of n_cells, to the provided one. More...
 

Public Attributes

enum hash_table_sync_t type = HASH_TABLE_SYNC_NONE
 Either: a) HASH_TABLE_SYNC_NONE in which case n_sync_obj is 0 and rw_locks is nullptr or b) HASH_TABLE_SYNC_RW_LOCK in which case n_sync_obj > 0 is the number of rw_locks elements, each of which protects a disjoint fraction of cells. More...
 
bool adaptive = false
 
ut::unique_ptr< hash_cell_t[]> cells
 The pointer to the array of cells. More...
 
size_t n_sync_obj = 0
 if rw_locks != nullptr, then it's their number (must be a power of two). More...
 
rw_lock_trw_locks = nullptr
 nullptr, or an array of n_sync_obj rw_locks used to protect segments of the hash table. More...
 
mem_heap_theap = nullptr
 
uint32_t magic_n = HASH_TABLE_MAGIC_N
 

Static Public Attributes

static constexpr uint32_t HASH_TABLE_MAGIC_N = 76561114
 

Private Attributes

std::atomic< size_t > n_cells
 The number of cells in the hash table. More...
 
ut::mt_fast_modulo_t n_cells_fast_modulo
 Utility to calculate the modulo n_cells fast. More...
 

Constructor & Destructor Documentation

◆ hash_table_t()

hash_table_t::hash_table_t ( size_t  n)
inline

◆ ~hash_table_t()

hash_table_t::~hash_table_t ( )
inline

Member Function Documentation

◆ get_n_cells()

size_t hash_table_t::get_n_cells ( )
inline

Returns number of cells in cells[] array.

If type==HASH_TABLE_SYNC_RW_LOCK it can be used:

  • without any latches to peek a value, before hash_lock_[sx]_confirm
  • when holding S-latch for at least one n_sync_obj to get the "real" value
    Returns
    value of n_cells

◆ get_n_cells_fast_modulo()

const ut::fast_modulo_t hash_table_t::get_n_cells_fast_modulo ( )
inline

Returns a helper class for calculating fast modulo n_cells.

If type==HASH_TABLE_SYNC_RW_LOCK it can be used:

  • without any latches to peek a value, before hash_lock_[sx]_confirm
  • when holding S-latch for at least one n_sync_obj to get the "real" value

◆ set_n_cells()

void hash_table_t::set_n_cells ( size_t  n)
inline

Sets the number of n_cells, to the provided one.

If type==HASH_TABLE_SYNC_RW_LOCK it can be used only when holding x-latches on all shards.

Parameters
[in]nThe new size of cells[] array

Member Data Documentation

◆ adaptive

bool hash_table_t::adaptive = false

◆ cells

ut::unique_ptr<hash_cell_t[]> hash_table_t::cells

The pointer to the array of cells.

If type==HASH_TABLE_SYNC_RW_LOCK it is:

  • modified when holding X-latches on all n_sync_obj
  • read when holding an S-latch for at least one n_sync_obj

◆ HASH_TABLE_MAGIC_N

constexpr uint32_t hash_table_t::HASH_TABLE_MAGIC_N = 76561114
staticconstexpr

◆ heap

mem_heap_t* hash_table_t::heap = nullptr

◆ magic_n

uint32_t hash_table_t::magic_n = HASH_TABLE_MAGIC_N

◆ n_cells

std::atomic<size_t> hash_table_t::n_cells
private

The number of cells in the hash table.

If type==HASH_TABLE_SYNC_RW_LOCK it is:

  • modified when holding X-latches on all n_sync_obj
  • read
    • without any latches to peek a value, before hash_lock_[sx]_confirm
    • when holding S-latch for at least one n_sync_obj to get the "real" value

◆ n_cells_fast_modulo

ut::mt_fast_modulo_t hash_table_t::n_cells_fast_modulo
private

Utility to calculate the modulo n_cells fast.

It is set together with n_cells. It can be read without latches in parallel to set_n_cells, and as it is a complex object, it is not set atomically. Because of this the multi-threaded version is used.

◆ n_sync_obj

size_t hash_table_t::n_sync_obj = 0

if rw_locks != nullptr, then it's their number (must be a power of two).

Otherwise, 0. Is zero iff the type is HASH_TABLE_SYNC_NONE.

◆ rw_locks

rw_lock_t* hash_table_t::rw_locks = nullptr

nullptr, or an array of n_sync_obj rw_locks used to protect segments of the hash table.

Is nullptr iff the type is HASH_TABLE_SYNC_NONE.

◆ type

enum hash_table_sync_t hash_table_t::type = HASH_TABLE_SYNC_NONE

Either: a) HASH_TABLE_SYNC_NONE in which case n_sync_obj is 0 and rw_locks is nullptr or b) HASH_TABLE_SYNC_RW_LOCK in which case n_sync_obj > 0 is the number of rw_locks elements, each of which protects a disjoint fraction of cells.

The default type of hash_table is HASH_TABLE_SYNC_NONE i.e.: the caller is responsible for access control to the table.


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