MySQL 9.1.0
Source Code Documentation
|
INFORMATION SCHEMA innodb_trx, innodb_locks and innodb_lock_waits tables fetch code. More...
#include <sql_class.h>
#include <stdio.h>
#include "buf0buf.h"
#include "dict0dict.h"
#include "ha0storage.h"
#include "ha_prototypes.h"
#include "hash0hash.h"
#include "lock0iter.h"
#include "lock0lock.h"
#include "mem0mem.h"
#include "mysql/plugin.h"
#include "page0page.h"
#include "rem0rec.h"
#include "row0row.h"
#include "srv0srv.h"
#include "sync0rw.h"
#include "sync0sync.h"
#include "trx0i_s.h"
#include "trx0sys.h"
#include "trx0trx.h"
#include "ut0mem.h"
#include "storage/perfschema/pfs_data_lock.h"
Classes | |
struct | i_s_mem_chunk_t |
Memory for each table in the intermediate buffer is allocated in separate chunks. More... | |
struct | i_s_table_cache_t |
This represents one table's cache. More... | |
struct | trx_i_s_cache_t |
This structure describes the intermediate buffer. More... | |
Macros | |
#define | MAX_ALLOWED_FOR_STORAGE(cache) (TRX_I_S_MEM_LIMIT - (cache)->mem_allocd) |
Memory limit passed to ha_storage_put_memlim(). More... | |
#define | MAX_ALLOWED_FOR_ALLOC(cache) |
Memory limit in table_cache_create_empty_row(). More... | |
Functions | |
static ulint | wait_lock_get_heap_no (const lock_t *lock) |
For a record lock that is in waiting state retrieves the only bit that is set, for a table lock returns ULINT_UNDEFINED. More... | |
static void | table_cache_init (i_s_table_cache_t *table_cache, size_t row_size) |
Initializes the members of a table cache. More... | |
static void | table_cache_free (i_s_table_cache_t *table_cache) |
Frees a table cache. More... | |
static void * | table_cache_create_empty_row (i_s_table_cache_t *table_cache, trx_i_s_cache_t *cache) |
Returns an empty row from a table cache. More... | |
static bool | i_s_locks_row_validate (const i_s_locks_row_t *row) |
Validates a row in the locks cache. More... | |
static bool | fill_trx_row (i_s_trx_row_t *row, const trx_t *trx, trx_i_s_cache_t *cache) |
Fills i_s_trx_row_t object. More... | |
static ulint | put_nth_field (char *buf, ulint buf_size, ulint n, const dict_index_t *index, const rec_t *rec, const ulint *offsets) |
Format the nth field of "rec" and put it in "buf". More... | |
void | p_s_fill_lock_data (const char **lock_data, const lock_t *lock, ulint heap_no, PSI_server_data_lock_container *container) |
Fill performance schema lock data. More... | |
void | fill_locks_row (i_s_locks_row_t *row, const lock_t *lock, ulint heap_no) |
Fills i_s_locks_row_t object with data about the lock. More... | |
static bool | can_cache_be_updated (trx_i_s_cache_t *cache) |
Checks if the cache can safely be updated. More... | |
static void | trx_i_s_cache_clear (trx_i_s_cache_t *cache) |
Declare a cache empty, preparing it to be filled up. More... | |
template<typename Trx_list > | |
static void | fetch_data_into_cache_low (trx_i_s_cache_t *cache, Trx_list *trx_list) |
Fetches the data needed to fill the 3 INFORMATION SCHEMA tables into the table cache buffer. More... | |
static void | fetch_data_into_cache (trx_i_s_cache_t *cache) |
Fetches the data needed to fill the 3 INFORMATION SCHEMA tables into the table cache buffer. More... | |
int | trx_i_s_possibly_fetch_data_into_cache (trx_i_s_cache_t *cache) |
Update the transactions cache if it has not been read for some time. More... | |
bool | trx_i_s_cache_is_truncated (trx_i_s_cache_t *cache) |
Returns true if the data in the cache is truncated due to the memory limit posed by TRX_I_S_MEM_LIMIT. More... | |
void | trx_i_s_cache_init (trx_i_s_cache_t *cache) |
Initialize INFORMATION SCHEMA trx related cache. More... | |
void | trx_i_s_cache_free (trx_i_s_cache_t *cache) |
Free the INFORMATION SCHEMA trx related cache. More... | |
void | trx_i_s_cache_start_read (trx_i_s_cache_t *cache) |
Issue a shared/read lock on the tables cache. More... | |
void | trx_i_s_cache_end_read (trx_i_s_cache_t *cache) |
Release a shared/read lock on the tables cache. More... | |
void | trx_i_s_cache_start_write (trx_i_s_cache_t *cache) |
Issue an exclusive/write lock on the tables cache. More... | |
void | trx_i_s_cache_end_write (trx_i_s_cache_t *cache) |
Release an exclusive/write lock on the tables cache. More... | |
static i_s_table_cache_t * | cache_select_table (trx_i_s_cache_t *cache, enum i_s_table table) |
Selects a INFORMATION SCHEMA table cache from the whole cache. More... | |
ulint | trx_i_s_cache_get_rows_used (trx_i_s_cache_t *cache, enum i_s_table table) |
Retrieves the number of used rows in the cache for a given INFORMATION SCHEMA table. More... | |
void * | trx_i_s_cache_get_nth_row (trx_i_s_cache_t *cache, enum i_s_table table, ulint n) |
Retrieves the nth row (zero-based) in the cache for a given INFORMATION SCHEMA table. More... | |
char * | trx_i_s_create_lock_id (const i_s_locks_row_t &row, char *lock_id, size_t lock_id_size) |
Crafts a lock id string from a i_s_locks_row_t object. More... | |
int | trx_i_s_parse_lock_id (const char *lock_id, i_s_locks_row_t *row) |
Parses lock id into row. More... | |
Variables | |
constexpr uint32_t | TABLE_CACHE_INITIAL_ROWSNUM = 1024 |
Initial number of rows in the table cache. More... | |
constexpr uint32_t | MEM_CHUNKS_IN_TABLE_CACHE = 39 |
The maximum number of chunks to allocate for a table cache. More... | |
constexpr uint32_t | CACHE_STORAGE_INITIAL_SIZE = 1024 |
Initial size of the cache storage. More... | |
constexpr uint32_t | CACHE_STORAGE_HASH_CELLS = 2048 |
Number of hash cells in the cache storage. More... | |
static trx_i_s_cache_t | trx_i_s_cache_static |
This is the intermediate buffer where data needed to fill the INFORMATION SCHEMA tables is fetched and later retrieved by the C++ code in handler/i_s.cc. More... | |
trx_i_s_cache_t * | trx_i_s_cache = &trx_i_s_cache_static |
This is the intermediate buffer where data needed to fill the INFORMATION SCHEMA tables is fetched and later retrieved by the C++ code in handler/i_s.cc. More... | |
constexpr const char * | LOCK_RECORD_ID_FORMAT |
constexpr const int | LOCK_RECORD_ID_FORMAT_PARTS = 6 |
constexpr const char * | LOCK_TABLE_ID_FORMAT |
constexpr const int | LOCK_TABLE_ID_FORMAT_PARTS = 4 |
INFORMATION SCHEMA innodb_trx, innodb_locks and innodb_lock_waits tables fetch code.
The code below fetches information needed to fill those 3 dynamic tables and uploads it into a "transactions table cache" for later retrieval.
Created July 17, 2007 Vasil Dimov
#define MAX_ALLOWED_FOR_ALLOC | ( | cache | ) |
Memory limit in table_cache_create_empty_row().
cache | hash storage |
#define MAX_ALLOWED_FOR_STORAGE | ( | cache | ) | (TRX_I_S_MEM_LIMIT - (cache)->mem_allocd) |
Memory limit passed to ha_storage_put_memlim().
cache | hash storage |
|
static |
Selects a INFORMATION SCHEMA table cache from the whole cache.
cache | in: whole cache |
table | in: which table |
|
static |
Checks if the cache can safely be updated.
The minimum time that a cache must not be updated after it has been read for the last time. We use this technique to ensure that SELECTs which join several INFORMATION SCHEMA tables read the same version of the cache.
cache | in: cache |
|
static |
Fetches the data needed to fill the 3 INFORMATION SCHEMA tables into the table cache buffer.
Cache must be locked for write.
cache | in/out: cache |
|
static |
Fetches the data needed to fill the 3 INFORMATION SCHEMA tables into the table cache buffer.
Cache must be locked for write.
[in,out] | cache | the cache |
[in] | trx_list | the list to scan |
void fill_locks_row | ( | i_s_locks_row_t * | row, |
const lock_t * | lock, | ||
ulint | heap_no | ||
) |
Fills i_s_locks_row_t object with data about the lock.
[out] | row | Result object that's filled |
[in] | lock | Lock to get data from |
[in] | heap_no | Lock's record number or ULINT_UNDEFINED if the lock is a table lock |
|
static |
Fills i_s_trx_row_t object.
If memory can not be allocated then false is returned.
[out] | row | Result object that's filled |
[in] | trx | Transaction to get data from |
[in,out] | cache | The cache into which to copy volatile strings |
|
static |
Validates a row in the locks cache.
row | in: row to validate |
void p_s_fill_lock_data | ( | const char ** | lock_data, |
const lock_t * | lock, | ||
ulint | heap_no, | ||
PSI_server_data_lock_container * | container | ||
) |
Fill performance schema lock data.
Create a string that represents the LOCK_DATA column, for a given lock record.
[out] | lock_data | Lock data string |
[in] | lock | Lock to inspect |
[in] | heap_no | Lock heap number |
[in] | container | Data container to fill |
|
static |
Format the nth field of "rec" and put it in "buf".
The result is always NUL-terminated. Returns the number of bytes that were written to "buf" (including the terminating NUL).
buf | out: buffer |
buf_size | in: buffer size in bytes |
n | in: number of field |
index | in: index |
rec | in: record |
offsets | in: record offsets, returned by rec_get_offsets() |
|
static |
Returns an empty row from a table cache.
The row is allocated if no more empty rows are available. The number of used rows is incremented. If the memory limit is hit then NULL is returned and nothing is allocated.
table_cache | in/out: table cache |
cache | in/out: cache to record how many bytes are allocated |
|
static |
Frees a table cache.
table_cache | in/out: table cache |
|
static |
Initializes the members of a table cache.
table_cache | out: table cache |
row_size | in: the size of a row |
|
static |
Declare a cache empty, preparing it to be filled up.
Not all resources are freed because they can be reused.
cache | out: cache to clear |
void trx_i_s_cache_end_read | ( | trx_i_s_cache_t * | cache | ) |
Release a shared/read lock on the tables cache.
in: cache
cache | in: cache |
void trx_i_s_cache_end_write | ( | trx_i_s_cache_t * | cache | ) |
Release an exclusive/write lock on the tables cache.
in: cache
cache | in: cache |
void trx_i_s_cache_free | ( | trx_i_s_cache_t * | cache | ) |
Free the INFORMATION SCHEMA trx related cache.
in/out: cache to free
cache | in, own: cache to free |
void * trx_i_s_cache_get_nth_row | ( | trx_i_s_cache_t * | cache, |
enum i_s_table | table, | ||
ulint | n | ||
) |
Retrieves the nth row (zero-based) in the cache for a given INFORMATION SCHEMA table.
Retrieves the nth row in the cache for a given INFORMATION SCHEMA table.
cache | in: cache |
table | in: which table |
n | in: row number |
ulint trx_i_s_cache_get_rows_used | ( | trx_i_s_cache_t * | cache, |
enum i_s_table | table | ||
) |
Retrieves the number of used rows in the cache for a given INFORMATION SCHEMA table.
cache | in: cache |
table | in: which table |
void trx_i_s_cache_init | ( | trx_i_s_cache_t * | cache | ) |
Initialize INFORMATION SCHEMA trx related cache.
out: cache to init
cache | out: cache to init |
bool trx_i_s_cache_is_truncated | ( | trx_i_s_cache_t * | cache | ) |
Returns true if the data in the cache is truncated due to the memory limit posed by TRX_I_S_MEM_LIMIT.
[in] | cache | The cache |
void trx_i_s_cache_start_read | ( | trx_i_s_cache_t * | cache | ) |
Issue a shared/read lock on the tables cache.
in: cache
cache | in: cache |
void trx_i_s_cache_start_write | ( | trx_i_s_cache_t * | cache | ) |
Issue an exclusive/write lock on the tables cache.
in: cache
cache | in: cache |
char * trx_i_s_create_lock_id | ( | const i_s_locks_row_t & | row, |
char * | lock_id, | ||
size_t | lock_id_size | ||
) |
Crafts a lock id string from a i_s_locks_row_t object.
Returns its second argument. This function aborts if there is not enough space in lock_id. Be sure to provide at least TRX_I_S_LOCK_ID_MAX_LEN + 1 if you want to be 100% sure that it will not abort.
[in] | row | The description of the lock sufficient to populate a row |
[out] | lock_id | The buffer to store the resulting lock_id |
[in] | lock_id_size | The size of the lock_id buffer |
int trx_i_s_parse_lock_id | ( | const char * | lock_id, |
i_s_locks_row_t * | row | ||
) |
Parses lock id into row.
[in] | lock_id | Lock id generated with trx_i_s_create_lock_id |
[out] | row | Row to be filled in with data |
int trx_i_s_possibly_fetch_data_into_cache | ( | trx_i_s_cache_t * | cache | ) |
Update the transactions cache if it has not been read for some time.
Called from handler/i_s.cc.
cache | in/out: cache |
For a record lock that is in waiting state retrieves the only bit that is set, for a table lock returns ULINT_UNDEFINED.
lock | in: lock |
|
constexpr |
Number of hash cells in the cache storage.
|
constexpr |
Initial size of the cache storage.
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
The maximum number of chunks to allocate for a table cache.
The rows of a table cache are stored in a set of chunks. When a new row is added a new chunk is allocated if necessary. Assuming that the first one is 1024 rows (TABLE_CACHE_INITIAL_ROWSNUM) and each subsequent is N/2 where N is the number of rows we have allocated till now, then 39th chunk would accommodate 1677416425 rows and all chunks would accommodate 3354832851 rows.
|
constexpr |
Initial number of rows in the table cache.
trx_i_s_cache_t* trx_i_s_cache = &trx_i_s_cache_static |
This is the intermediate buffer where data needed to fill the INFORMATION SCHEMA tables is fetched and later retrieved by the C++ code in handler/i_s.cc.
|
static |
This is the intermediate buffer where data needed to fill the INFORMATION SCHEMA tables is fetched and later retrieved by the C++ code in handler/i_s.cc.