MySQL 9.1.0
Source Code Documentation
temptable Namespace Reference

Classes

struct  Allocation_scheme
 
class  Allocator
 Custom memory allocator. More...
 
class  AllocatorState
 Shared state between all instances of a given allocator. More...
 
class  Block
 Memory-block abstraction whose purpose is to serve as a building block for custom memory-allocator implementations. More...
 
class  Cell
 A cell is the intersection of a row and a column. More...
 
class  Cell_calculator
 Utility to perform calculations for a cell. More...
 
class  Chunk
 Chunk is an abstraction with the purpose of representing a smallest logical memory-unit within the Block. More...
 
class  Column
 A column class that describes the metadata of a column. More...
 
class  Cursor
 A cursor for iterating over an Index. More...
 
struct  Exponential_policy
 
class  Handler
 Temptable engine handler. More...
 
class  Hash_duplicates
 
class  Hash_unique
 
class  Header
 Header is an abstraction with the purpose of holding and maintaining the Block metadata. More...
 
class  Index
 Index interface. More...
 
class  Indexed_cells
 Indexed cells represent one or more cells that are covered by an index. More...
 
class  Indexed_cells_equal_to
 Indexed cells comparator (a == b). More...
 
class  Indexed_cells_hash
 Indexed cells hasher. More...
 
class  Indexed_cells_less
 Indexed cells comparator (a < b). More...
 
class  Indexed_column
 
class  Key_value_store
 Key-value store, a convenience wrapper class which models a thread-safe dictionary type. More...
 
class  Key_value_store_logger
 Default Key_value_store logging facility which turns to no-op in non-debug builds. More...
 
class  Key_value_store_logger< T, true >
 Key_value_store logging facility debug builds only. More...
 
struct  Key_value_store_stats
 This is a small convenience POD-like type which describes what kind of details we are interested in when monitoring the behavior of Key_value_store. More...
 
struct  Largest_lock_free_type_selector
 Largest lock-free type selector, a helper utility very much similar to Lock_free_type_selector with the difference being that it tries hard not to fail. More...
 
struct  Largest_lock_free_type_selector< T, typename std::enable_if< std::is_integral< T >::value >::type >
 Template-specialization for integral types. More...
 
struct  Largest_lock_free_type_selector< T, typename std::enable_if< std::is_pointer< T >::value >::type >
 Template-specialization for pointer types. More...
 
class  Lock_free_pool
 Lock-free pool which consists of POOL_SIZE Lock_free_type elements. More...
 
class  Lock_free_shared_block_pool
 Lock-free pool of POOL_SIZE Block elements. More...
 
struct  Lock_free_type
 Representation of an atomic type which is guaranteed to be always-lock-free. More...
 
struct  Lock_free_type< T, Alignment::L1_DCACHE_SIZE, TypeSelector >
 
struct  Lock_free_type_selector
 Lock-free type selector, a helper utility which evaluates during the compile-time whether the given type T has a property of being always-lock-free for given platform. More...
 
struct  Lock_free_type_selector< T, typename std::enable_if< std::is_class< T >::value and std::is_trivially_copyable< T >::value >::type >
 Template-specialization for trivially-copyable classes/structs. More...
 
struct  Lock_free_type_selector< T, typename std::enable_if< std::is_pointer< T >::value >::type >
 Template-specialization for pointer types. More...
 
struct  Lock_free_type_selector< T, typename std::enable_if< std::is_same< T, bool >::value >::type >
 Template-specialization for boolean types. More...
 
struct  Lock_free_type_selector< T, typename std::enable_if< std::is_same< T, char >::value or std::is_same< T, unsigned char >::value >::type >
 Template-specialization for char types. More...
 
struct  Lock_free_type_selector< T, typename std::enable_if< std::is_same< T, int >::value or std::is_same< T, unsigned int >::value >::type >
 Template-specialization for int types. More...
 
struct  Lock_free_type_selector< T, typename std::enable_if< std::is_same< T, long >::value or std::is_same< T, unsigned long >::value >::type >
 Template-specialization for long types. More...
 
struct  Lock_free_type_selector< T, typename std::enable_if< std::is_same< T, long long >::value or std::is_same< T, unsigned long long >::value >::type >
 Template-specialization for long long types. More...
 
struct  Lock_free_type_selector< T, typename std::enable_if< std::is_same< T, short >::value or std::is_same< T, unsigned short >::value >::type >
 Template-specialization for short types. More...
 
struct  Memory
 Primary-template (functor) class for memory-utils. More...
 
struct  Memory< Source::MMAP_FILE >
 Template specialization for MMAP-based allocation/deallocation. More...
 
struct  Memory< Source::RAM >
 Template specialization for RAM-based allocation/deallocation. More...
 
struct  MemoryMonitor
 
struct  Prefer_RAM_over_MMAP_policy
 
class  Row
 A row representation. More...
 
class  Sharded_key_value_store
 Sharded key-value store, a convenience wrapper class around Key_value_store that creates N_SHARDS instances of Key_value_store and exposes a simple interface to further manipulate with them. More...
 
struct  Sharded_key_value_store_logger
 Default Sharded_key_value_store logging facility which turns to no-op in non-debug builds. More...
 
struct  Sharded_key_value_store_logger< T, true >
 Sharded_key_value_store logging facility debug builds only. More...
 
class  Storage
 Storage container. More...
 
class  Table
 
class  TableResourceMonitor
 
class  Tree
 

Typedefs

using Exponential_growth_preferring_RAM_over_MMAP = Allocation_scheme< Exponential_policy, Prefer_RAM_over_MMAP_policy >
 
typedef std::vector< Column, Allocator< Column > > Columns
 A type that designates all the columns of a table. More...
 
typedef std::multiset< Indexed_cells, Indexed_cells_less, Allocator< Indexed_cells > > Tree_container
 The container used by tree unique and non-unique indexes. More...
 
typedef std::unordered_multiset< Indexed_cells, Indexed_cells_hash, Indexed_cells_equal_to, Allocator< Indexed_cells > > Hash_duplicates_container
 The container used by hash non-unique indexes. More...
 
typedef std::unordered_set< Indexed_cells, Indexed_cells_hash, Indexed_cells_equal_to, Allocator< Indexed_cells > > Hash_unique_container
 The container used by hash unique indexes. More...
 

Enumerations

enum class  Alignment { NATURAL , L1_DCACHE_SIZE }
 Enum class describing alignment-requirements. More...
 
enum class  Source { MMAP_FILE , RAM }
 Type of memory allocated. More...
 
enum class  Result {
  END_OF_FILE = HA_ERR_END_OF_FILE , FOUND_DUPP_KEY = HA_ERR_FOUND_DUPP_KEY , KEY_NOT_FOUND = HA_ERR_KEY_NOT_FOUND , NO_SUCH_TABLE = HA_ERR_NO_SUCH_TABLE ,
  OK = 0 , OUT_OF_MEM = HA_ERR_OUT_OF_MEM , RECORD_FILE_FULL = HA_ERR_RECORD_FILE_FULL , TABLE_CORRUPT = HA_ERR_TABLE_CORRUPT ,
  TABLE_EXIST = HA_ERR_TABLE_EXIST , TOO_BIG_ROW = HA_ERR_TOO_BIG_ROW , UNSUPPORTED = HA_ERR_UNSUPPORTED , WRONG_COMMAND = HA_ERR_WRONG_COMMAND ,
  WRONG_INDEX = HA_ERR_WRONG_INDEX
}
 

Functions

void Block_PSI_init ()
 Initialize the PSI memory engine. More...
 
void Block_PSI_track_logical_allocation (size_t size)
 Log logical (Chunk) memory allocation. More...
 
void Block_PSI_track_logical_deallocation (size_t size)
 Log logical (Chunk) memory deallocation. More...
 
void Block_PSI_track_physical_ram_allocation (void *ptr, size_t size)
 Log physical memory allocation of a Block located in RAM. More...
 
void Block_PSI_track_physical_ram_deallocation (uint8_t *ptr)
 Log physical memory deallocation of a Block located in RAM. More...
 
void Block_PSI_track_physical_disk_allocation (void *ptr, size_t size)
 Log physical memory allocation of a Block located in MMAP-ed file. More...
 
void Block_PSI_track_physical_disk_deallocation (uint8_t *ptr)
 Log physical memory deallocation of a Block located in MMAP-ed file. More...
 
static uint8_t * allocate_from (Source src, size_t size)
 
static void deallocate_from (Source src, size_t size, uint8_t *block_address)
 
constexpr unsigned long long operator""_KiB (unsigned long long n)
 Multiply a number by 1024. More...
 
constexpr unsigned long long operator""_MiB (unsigned long long n)
 Multiply a number by 1024 * 1024. More...
 
constexpr unsigned long long operator""_GiB (unsigned long long n)
 Multiply a number by 1024 * 1024 * 1024. More...
 
void kv_store_shards_debug_dump ()
 Small helper function which debug-prints the miscellaneous statistics which key-value store has collected. More...
 
void shared_block_pool_release (THD *thd)
 Small helper function which releases the slot (and memory occupied by the Block) in shared-block pool. More...
 
bool buf_is_inside_another (const unsigned char *small, size_t small_length, const unsigned char *big, size_t big_length)
 Check if a given buffer is inside another buffer. More...
 
const char * result_to_string (Result r)
 
static int show_count_hit_max_ram_var (THD *, SHOW_VAR *var, char *buff)
 
static void get_count_hit_max_ram (void *, measurement_delivery_callback_t delivery, void *delivery_context)
 

Variables

std::atomic_uint64_t count_hit_max_ram {}
 Status variable that counts the memory limit breaches. More...
 
constexpr size_t ALLOCATOR_MAX_BLOCK_MB_EXP = 9
 log2(allocator max block size in MiB). More...
 
constexpr size_t ALLOCATOR_MAX_BLOCK_BYTES
 Limit on the size of a block created by Allocator (in bytes). More...
 
constexpr size_t STORAGE_PAGE_SIZE = 64_KiB
 Storage page size. More...
 
constexpr size_t INDEX_DEFAULT_HASH_TABLE_BUCKETS = 1024
 Number of buckets to have by default in a hash index. More...
 
constexpr bool DEBUG_BUILD = true
 Store build-type information into the constexpr expression. More...
 
constexpr size_t L1_DCACHE_SIZE = CPU_LEVEL1_DCACHE_LINESIZE
 Store L1-dcache size information into the constexpr expression. More...
 
constexpr size_t KV_STORE_SHARDS_COUNT = 16 * 1024
 Number of shards in key-value store. More...
 
constexpr size_t SHARED_BLOCK_POOL_SIZE = 16 * 1024
 Size of a pool containing shared-blocks. More...
 
PSI_memory_key mem_key_physical_disk
 PFS key to account physical allocations and deallocations from disk. More...
 
PSI_memory_key mem_key_physical_ram
 PFS key to account physical allocations and deallocations from RAM. More...
 
PSI_memory_info pfs_info []
 Array of PFS keys. More...
 
const size_t pfs_info_num_elements = sizeof(pfs_info) / sizeof(pfs_info[0])
 Number of elements inside pfs_info[]. More...
 
static Sharded_key_value_store< KV_STORE_SHARDS_COUNTkv_store_shard
 Key-value store containing all tables for all existing connections. More...
 
static Lock_free_shared_block_pool< SHARED_BLOCK_POOL_SIZEshared_block_pool
 
static PSI_metric_info_v1 metrics []
 
static PSI_meter_info_v1 meter []
 
static SHOW_VAR status_variables []
 

Typedef Documentation

◆ Columns

typedef std::vector<Column, Allocator<Column> > temptable::Columns

A type that designates all the columns of a table.

◆ Exponential_growth_preferring_RAM_over_MMAP

◆ Hash_duplicates_container

The container used by hash non-unique indexes.

◆ Hash_unique_container

The container used by hash unique indexes.

◆ Tree_container

The container used by tree unique and non-unique indexes.

Enumeration Type Documentation

◆ Alignment

enum class temptable::Alignment
strong

Enum class describing alignment-requirements.

Enumerator
NATURAL 
L1_DCACHE_SIZE 

◆ Result

enum class temptable::Result
strong
Enumerator
END_OF_FILE 
FOUND_DUPP_KEY 
KEY_NOT_FOUND 
NO_SUCH_TABLE 
OK 
OUT_OF_MEM 
RECORD_FILE_FULL 
TABLE_CORRUPT 
TABLE_EXIST 
TOO_BIG_ROW 
UNSUPPORTED 
WRONG_COMMAND 
WRONG_INDEX 

◆ Source

enum class temptable::Source
strong

Type of memory allocated.

Enumerator
MMAP_FILE 

Memory is allocated on disk, using mmap()'ed file.

RAM 

Memory is allocated from RAM, using malloc() for example.

Function Documentation

◆ allocate_from()

static uint8_t * temptable::allocate_from ( Source  src,
size_t  size 
)
inlinestatic

◆ Block_PSI_init()

void temptable::Block_PSI_init ( )

Initialize the PSI memory engine.

◆ Block_PSI_track_logical_allocation()

void temptable::Block_PSI_track_logical_allocation ( size_t  size)

Log logical (Chunk) memory allocation.

[in] Number of bytes allocated

◆ Block_PSI_track_logical_deallocation()

void temptable::Block_PSI_track_logical_deallocation ( size_t  size)

Log logical (Chunk) memory deallocation.

[in] Number of bytes deallocated

◆ Block_PSI_track_physical_disk_allocation()

void temptable::Block_PSI_track_physical_disk_allocation ( void *  ptr,
size_t  size 
)

Log physical memory allocation of a Block located in MMAP-ed file.

[in] Pointer to user memory block [in] Number of bytes allocated

◆ Block_PSI_track_physical_disk_deallocation()

void temptable::Block_PSI_track_physical_disk_deallocation ( uint8_t *  ptr)

Log physical memory deallocation of a Block located in MMAP-ed file.

[in] Pointer to PSI header

◆ Block_PSI_track_physical_ram_allocation()

void temptable::Block_PSI_track_physical_ram_allocation ( void *  ptr,
size_t  size 
)

Log physical memory allocation of a Block located in RAM.

[in] Pointer to user memory block [in] Number of bytes allocated

◆ Block_PSI_track_physical_ram_deallocation()

void temptable::Block_PSI_track_physical_ram_deallocation ( uint8_t *  ptr)

Log physical memory deallocation of a Block located in RAM.

[in] Pointer to PSI header

◆ buf_is_inside_another()

bool temptable::buf_is_inside_another ( const unsigned char *  small,
size_t  small_length,
const unsigned char *  big,
size_t  big_length 
)
inline

Check if a given buffer is inside another buffer.

Returns
true if inside
Parameters
[in]smallFirst buffer, that should be inside the other.
[in]small_lengthFirst buffer length in bytes.
[in]bigSecond buffer, that should contain the other.
[in]big_lengthSecond buffer length in bytes.

◆ deallocate_from()

static void temptable::deallocate_from ( Source  src,
size_t  size,
uint8_t *  block_address 
)
inlinestatic

◆ get_count_hit_max_ram()

static void temptable::get_count_hit_max_ram ( void *  ,
measurement_delivery_callback_t  delivery,
void *  delivery_context 
)
static

◆ kv_store_shards_debug_dump()

void temptable::kv_store_shards_debug_dump ( )

Small helper function which debug-prints the miscellaneous statistics which key-value store has collected.

◆ operator""_GiB()

constexpr unsigned long long temptable::operator""_GiB ( unsigned long long  n)
inlineconstexpr

Multiply a number by 1024 * 1024 * 1024.

Returns
n * 1024 * 1024 * 1024.
Parameters
[in]nNumber to multiply.

◆ operator""_KiB()

constexpr unsigned long long temptable::operator""_KiB ( unsigned long long  n)
inlineconstexpr

Multiply a number by 1024.

Returns
n * 1024.
Parameters
[in]nNumber to multiply.

◆ operator""_MiB()

constexpr unsigned long long temptable::operator""_MiB ( unsigned long long  n)
inlineconstexpr

Multiply a number by 1024 * 1024.

Returns
n * 1024 * 1024.
Parameters
[in]nNumber to multiply.

◆ result_to_string()

const char * temptable::result_to_string ( Result  r)

◆ shared_block_pool_release()

void temptable::shared_block_pool_release ( THD thd)

Small helper function which releases the slot (and memory occupied by the Block) in shared-block pool.

◆ show_count_hit_max_ram_var()

static int temptable::show_count_hit_max_ram_var ( THD ,
SHOW_VAR var,
char *  buff 
)
static

Variable Documentation

◆ ALLOCATOR_MAX_BLOCK_BYTES

constexpr size_t temptable::ALLOCATOR_MAX_BLOCK_BYTES
constexpr
Initial value:
= 1_MiB
constexpr size_t ALLOCATOR_MAX_BLOCK_MB_EXP
log2(allocator max block size in MiB).
Definition: constants.h:60

Limit on the size of a block created by Allocator (in bytes).

A larger block could still be created if a single allocation request with bigger size is received.

◆ ALLOCATOR_MAX_BLOCK_MB_EXP

constexpr size_t temptable::ALLOCATOR_MAX_BLOCK_MB_EXP = 9
constexpr

log2(allocator max block size in MiB).

Ie. 2 ^ ALLOCATOR_MAX_BLOCK_MB_EXP * 1024^2 = ALLOCATOR_MAX_BLOCK_BYTES.

◆ count_hit_max_ram

std::atomic_uint64_t temptable::count_hit_max_ram {}

Status variable that counts the memory limit breaches.

◆ DEBUG_BUILD

constexpr bool temptable::DEBUG_BUILD = true
constexpr

Store build-type information into the constexpr expression.

◆ INDEX_DEFAULT_HASH_TABLE_BUCKETS

constexpr size_t temptable::INDEX_DEFAULT_HASH_TABLE_BUCKETS = 1024
constexpr

Number of buckets to have by default in a hash index.

◆ kv_store_shard

Sharded_key_value_store<KV_STORE_SHARDS_COUNT> temptable::kv_store_shard
static

Key-value store containing all tables for all existing connections.

See Sharded_key_value_store documentation for more details.

◆ KV_STORE_SHARDS_COUNT

constexpr size_t temptable::KV_STORE_SHARDS_COUNT = 16 * 1024
constexpr

Number of shards in key-value store.

◆ L1_DCACHE_SIZE

constexpr size_t temptable::L1_DCACHE_SIZE = CPU_LEVEL1_DCACHE_LINESIZE
constexpr

Store L1-dcache size information into the constexpr expression.

◆ mem_key_physical_disk

PSI_memory_key temptable::mem_key_physical_disk

PFS key to account physical allocations and deallocations from disk.

After we have allocated more than temptable_max_ram we start taking memory from the OS disk, using mmap()'ed files.

◆ mem_key_physical_ram

PSI_memory_key temptable::mem_key_physical_ram

PFS key to account physical allocations and deallocations from RAM.

Before we have allocated more than temptable_max_ram we take memory from the OS RAM, using e.g. malloc().

◆ meter

PSI_meter_info_v1 temptable::meter[]
static
Initial value:
= {
{.m_meter = "mysql.TempTable",
.m_description = "MySql TempTable metrics",
.m_frequency = 10,
.m_flags = 0,
.m_key = 0,
.m_metrics = metrics,
.m_metrics_size = std::size(metrics)},
}
size_t size(const char *const c)
Definition: base64.h:46
static PSI_metric_info_v1 metrics[]
Definition: plugin.cc:83

◆ metrics

PSI_metric_info_v1 temptable::metrics[]
static
Initial value:
= {
{.m_metric = "count_hit_max_ram",
.m_unit = "",
.m_description = "The number of times internal temp tables exceeded the "
"memory limit of engine",
.m_flags = 0,
.m_key = 0,
.m_measurement_callback = get_count_hit_max_ram,
.m_measurement_context = nullptr}}
static void get_count_hit_max_ram(void *, measurement_delivery_callback_t delivery, void *delivery_context)
Definition: plugin.cc:71
@ ASYNC_COUNTER
Definition: psi_metric_bits.h:33
@ METRIC_INTEGER
Definition: psi_metric_bits.h:38

◆ pfs_info

PSI_memory_info temptable::pfs_info[]
Initial value:
= {
}
#define PSI_DOCUMENT_ME
Definition: component_common.h:29
#define PSI_FLAG_MEM_COLLECT
Enable collecting the memory consumed by threads.
Definition: psi_bits.h:141
PSI_memory_key mem_key_physical_ram
PFS key to account physical allocations and deallocations from RAM.
Definition: block.cc:57
PSI_memory_key mem_key_physical_disk
PFS key to account physical allocations and deallocations from disk.
Definition: block.cc:52

Array of PFS keys.

◆ pfs_info_num_elements

const size_t temptable::pfs_info_num_elements = sizeof(pfs_info) / sizeof(pfs_info[0])

Number of elements inside pfs_info[].

◆ shared_block_pool

Lock_free_shared_block_pool<SHARED_BLOCK_POOL_SIZE> temptable::shared_block_pool
static

◆ SHARED_BLOCK_POOL_SIZE

constexpr size_t temptable::SHARED_BLOCK_POOL_SIZE = 16 * 1024
constexpr

Size of a pool containing shared-blocks.

◆ status_variables

SHOW_VAR temptable::status_variables[]
static
Initial value:
= {
{.name = "TempTable_count_hit_max_ram",
.value = (char *)&show_count_hit_max_ram_var,
.scope = SHOW_SCOPE_GLOBAL},
{.name = NullS,
.value = NullS,
.type = SHOW_FUNC,
.scope = SHOW_SCOPE_GLOBAL}}
static int show_count_hit_max_ram_var(THD *, SHOW_VAR *var, char *buff)
Definition: plugin.cc:60
#define NullS
Definition of the null string (a null pointer of type char *), used in some of our string handling co...
Definition: nulls.h:33
required string type
Definition: replication_group_member_actions.proto:34
@ SHOW_FUNC
Definition: status_var.h:39
@ SHOW_SCOPE_GLOBAL
Definition: status_var.h:70

◆ STORAGE_PAGE_SIZE

constexpr size_t temptable::STORAGE_PAGE_SIZE = 64_KiB
constexpr

Storage page size.