#include "univ.i"
#include "rem0rec.h"
#include "dict0dict.h"
#include "btr0types.h"
#include "mtr0mtr.h"
#include "ha0ha.h"
Go to the source code of this file.
Classes | |
struct | btr_search_struct |
struct | btr_search_sys_struct |
Macros | |
#define | btr0sea_h |
#define | btr_search_validate() TRUE |
#define | btr_search_latch (*btr_search_latch_temp) |
#define | BTR_SEARCH_HASH_ANALYSIS 17 |
#define | BTR_SEARCH_ON_PATTERN_LIMIT 3 |
#define | BTR_SEARCH_ON_HASH_LIMIT 3 |
#define | BTR_SEA_TIMEOUT 10000 |
Typedefs | |
typedef struct btr_search_sys_struct | btr_search_sys_t |
Variables | |
bool | btr_search_enabled |
ibool | btr_search_fully_disabled |
btr_search_sys_t * | btr_search_sys |
rw_lock_t * | btr_search_latch_temp |
The latch protecting the adaptive search system. |
#define BTR_SEA_TIMEOUT 10000 |
We do this many searches before trying to keep the search latch
over calls from MySQL. If we notice someone waiting for the latch, we again set this much timeout. This is to reduce contention.
Definition at line 315 of file btr0sea.h.
Referenced by row_search_for_mysql(), and trx_create().
#define BTR_SEARCH_HASH_ANALYSIS 17 |
#define btr_search_latch (*btr_search_latch_temp) |
The latch protecting the adaptive search system
Definition at line 290 of file btr0sea.h.
Referenced by btr_cur_del_mark_set_clust_rec(), btr_cur_del_mark_set_sec_rec(), btr_cur_search_to_nth_level(), btr_cur_update_in_place(), btr_search_disable(), btr_search_drop_page_hash_index(), btr_search_enable(), btr_search_guess_on_hash(), btr_search_info_get_ref_count(), btr_search_move_or_delete_hash_entries(), btr_search_sys_create(), btr_search_sys_free(), btr_search_update_hash_node_on_insert(), btr_search_update_hash_on_delete(), btr_search_update_hash_on_insert(), buf_pool_drop_hash_index(), ha_clear(), page_set_max_trx_id(), row_search_for_mysql(), and trx_search_latch_release_if_reserved().
#define BTR_SEARCH_ON_HASH_LIMIT 3 |
#define BTR_SEARCH_ON_PATTERN_LIMIT 3 |
typedef struct btr_search_sys_struct btr_search_sys_t |
UNIV_INTERN void btr_search_disable | ( | void | ) |
Disable the adaptive hash search system and empty the index.
Definition at line 206 of file btr0sea.cc.
References btr_search_latch, and ut_ad.
UNIV_INTERN void btr_search_drop_page_hash_index | ( | buf_block_t * | block | ) |
Drops a page hash index. in: block containing index page, s- or x-latched, or an index page for which we know that block->buf_fix_count == 0
Drops a page hash index.
block | in: block containing index page, s- or x-latched, or an index page for which we know that block->buf_fix_count == 0 |
Definition at line 1020 of file btr0sea.cc.
References btr_page_get_index_id(), btr_search_latch, buf_page_struct::buf_fix_count, buf_block_struct::curr_n_bytes, buf_block_struct::curr_n_fields, dict_index_is_ibuf(), buf_block_struct::frame, btr_search_sys_struct::hash_index, dict_index_struct::id, buf_block_struct::index, buf_block_struct::is_hashed, buf_block_struct::lock, mem_free, mem_heap_free, dict_index_struct::name, buf_block_struct::page, page_get_n_recs(), page_is_comp(), page_rec_get_next_low(), page_rec_is_comp(), page_rec_is_supremum(), rec_fold(), rec_offs_n_fields(), btr_search_struct::ref_count, rw_lock_s_lock, dict_index_struct::search_info, ut_a, ut_ad, and ut_print_timestamp().
UNIV_INTERN void btr_search_drop_page_hash_when_freed | ( | ulint | space, |
ulint | zip_size, | ||
ulint | page_no | ||
) |
Drops a page hash index when a page is freed from a fseg to the file system. Drops possible hash index if the page happens to be in the buffer pool. in: page number
Drops a page hash index when a page is freed from a fseg to the file system. Drops possible hash index if the page happens to be in the buffer pool.
space | in: space id |
zip_size | in: compressed page size in bytes or 0 for uncompressed pages |
page_no | in: page number |
Definition at line 1188 of file btr0sea.cc.
References BUF_GET_IF_IN_POOL, mtr_commit(), and mtr_start().
UNIV_INTERN void btr_search_enable | ( | void | ) |
Enable the adaptive hash search system.
Definition at line 236 of file btr0sea.cc.
References btr_search_latch.
UNIV_INLINE btr_search_t* btr_search_get_info | ( | dict_index_t * | index | ) |
Returns search info for an index.
Referenced by btr_cur_search_to_nth_level().
UNIV_INTERN ibool btr_search_guess_on_hash | ( | dict_index_t * | index, |
btr_search_t * | info, | ||
const dtuple_t * | tuple, | ||
ulint | mode, | ||
ulint | latch_mode, | ||
btr_cur_t * | cursor, | ||
ulint | has_search_latch, | ||
mtr_t * | mtr | ||
) |
Tries to guess the right search position based on the hash search info of the index. Note that if mode is PAGE_CUR_LE, which is used in inserts, and the function returns TRUE, then cursor->up_match and cursor->low_match both have sensible values.
Tries to guess the right search position based on the hash search info of the index. Note that if mode is PAGE_CUR_LE, which is used in inserts, and the function returns TRUE, then cursor->up_match and cursor->low_match both have sensible values.
index | in: index |
info | in: index search info |
tuple | in: logical record |
mode | in: PAGE_CUR_L, ... |
latch_mode | in: BTR_SEARCH_LEAF, ...; NOTE that only if has_search_latch is 0, we will have a latch set on the cursor page, otherwise we assume the caller uses his search latch to protect the record! |
cursor | out: tree cursor |
has_search_latch | in: latch mode the caller currently has on btr_search_latch: RW_S_LATCH, RW_X_LATCH, or 0 |
mtr | in: mtr |
Definition at line 815 of file btr0sea.cc.
References btr_cur_get_rec(), BTR_CUR_HASH, BTR_CUR_HASH_FAIL, btr_cur_position(), btr_leaf_page_release(), BTR_MODIFY_LEAF, btr_page_get_index_id(), btr_pcur_get_rec(), btr_search_latch, BTR_SEARCH_LEAF, BUF_BLOCK_FILE_PAGE, buf_block_get_state(), BUF_BLOCK_REMOVE_HASH, BUF_MAKE_YOUNG, buf_page_peek_if_too_old(), buf_pool_from_bpage(), dtuple_fold(), dtuple_get_n_fields(), btr_cur_struct::flag, btr_cur_struct::fold, buf_block_struct::frame, ha_search_and_get_data(), btr_search_sys_struct::hash_index, dict_index_struct::id, btr_search_struct::last_hash_succ, btr_search_struct::n_bytes, btr_cur_struct::n_bytes, btr_search_struct::n_fields, btr_cur_struct::n_fields, btr_search_struct::n_hash_potential, buf_pool_stat_struct::n_page_gets, buf_block_struct::page, page_rec_is_supremum(), page_rec_is_user_rec(), rw_lock_get_reader_count(), rw_lock_get_writer(), rw_lock_s_lock, buf_pool_struct::stat, and ut_ad.
UNIV_INTERN btr_search_t* btr_search_info_create | ( | mem_heap_t * | heap | ) |
Creates and initializes a search info struct.
Creates and initializes a search info struct.
heap | in: heap where created |
Definition at line 254 of file btr0sea.cc.
References btr_search_struct::hash_analysis, btr_search_struct::last_hash_succ, btr_search_struct::left_side, mem_heap_alloc(), btr_search_struct::n_bytes, btr_search_struct::n_fields, btr_search_struct::n_hash_potential, btr_search_struct::ref_count, and btr_search_struct::root_guess.
UNIV_INTERN ulint btr_search_info_get_ref_count | ( | btr_search_t * | info | ) |
Returns the value of ref_count. The value is protected by btr_search_latch.
Returns the value of ref_count. The value is protected by btr_search_latch.
info | in: search info. |
Definition at line 296 of file btr0sea.cc.
References btr_search_latch, btr_search_struct::ref_count, rw_lock_s_lock, and ut_ad.
UNIV_INLINE void btr_search_info_update | ( | dict_index_t * | index, |
btr_cur_t * | cursor | ||
) |
Updates the search info. in: cursor which was just positioned
index | in: index of the cursor |
Referenced by btr_cur_search_to_nth_level().
UNIV_INTERN void btr_search_move_or_delete_hash_entries | ( | buf_block_t * | new_block, |
buf_block_t * | block, | ||
dict_index_t * | index | ||
) |
Moves or deletes hash entries for moved records. If new_page is already hashed, then the hash index for page, if any, is dropped. If new_page is not hashed, and page is hashed, then a new hash index is built to new_page with the same parameters as page (this often happens when a page is split). in: record descriptor
Moves or deletes hash entries for moved records. If new_page is already hashed, then the hash index for page, if any, is dropped. If new_page is not hashed, and page is hashed, then a new hash index is built to new_page with the same parameters as page (this often happens when a page is split).
new_block | in: records are copied to this page |
block | in: index page from which records were copied, and the copied records will be deleted from this page |
index | in: record descriptor |
Definition at line 1431 of file btr0sea.cc.
References btr_search_latch, buf_block_struct::curr_left_side, buf_block_struct::curr_n_bytes, buf_block_struct::curr_n_fields, dict_index_is_ibuf(), buf_block_struct::index, buf_block_struct::is_hashed, buf_block_struct::left_side, buf_block_struct::lock, buf_block_struct::n_bytes, buf_block_struct::n_fields, rw_lock_s_lock, ut_a, and ut_ad.
UNIV_INTERN void btr_search_sys_create | ( | ulint | hash_size | ) |
Creates and initializes the adaptive search system at a database start. in: hash index hash table size
Creates and initializes the adaptive search system at a database start.
hash_size | in: hash index hash table size |
Definition at line 167 of file btr0sea.cc.
References btr_search_latch, ha_create, btr_search_sys_struct::hash_index, and rw_lock_create.
UNIV_INTERN void btr_search_sys_free | ( | void | ) |
Frees the adaptive search system at a database shutdown.
Definition at line 190 of file btr0sea.cc.
References btr_search_latch, btr_search_sys_struct::hash_index, mem_free, and mem_heap_free.
UNIV_INTERN void btr_search_update_hash_node_on_insert | ( | btr_cur_t * | cursor | ) |
Updates the page hash index when a single record is inserted on a page. in: cursor which was positioned to the place to insert using btr_cur_search_..., and the new record has been inserted next to the cursor
Updates the page hash index when a single record is inserted on a page.
cursor | in: cursor which was positioned to the place to insert using btr_cur_search_..., and the new record has been inserted next to the cursor |
Definition at line 1546 of file btr0sea.cc.
References btr_cur_get_block(), btr_cur_get_rec(), BTR_CUR_HASH, btr_search_latch, buf_block_struct::curr_left_side, buf_block_struct::curr_n_bytes, buf_block_struct::curr_n_fields, dict_index_is_ibuf(), btr_cur_struct::flag, btr_cur_struct::fold, ha_search_and_update_if_found, btr_search_sys_struct::hash_index, btr_cur_struct::index, buf_block_struct::index, buf_block_struct::is_hashed, buf_block_struct::lock, btr_cur_struct::n_bytes, btr_cur_struct::n_fields, page_rec_get_next(), ut_a, and ut_ad.
UNIV_INTERN void btr_search_update_hash_on_delete | ( | btr_cur_t * | cursor | ) |
Updates the page hash index when a single record is deleted from a page. in: cursor which was positioned on the record to delete using btr_cur_search_..., the record is not yet deleted
Updates the page hash index when a single record is deleted from a page.
cursor | in: cursor which was positioned on the record to delete using btr_cur_search_..., the record is not yet deleted |
Definition at line 1494 of file btr0sea.cc.
References btr_cur_get_block(), btr_cur_get_rec(), btr_search_latch, buf_block_struct::curr_n_bytes, buf_block_struct::curr_n_fields, dict_index_is_ibuf(), ha_search_and_delete_if_found(), btr_search_sys_struct::hash_index, dict_index_struct::id, btr_cur_struct::index, buf_block_struct::index, buf_block_struct::is_hashed, buf_block_struct::lock, mem_heap_free, rec_fold(), ut_a, and ut_ad.
UNIV_INTERN void btr_search_update_hash_on_insert | ( | btr_cur_t * | cursor | ) |
Updates the page hash index when a single record is inserted on a page. in: cursor which was positioned to the place to insert using btr_cur_search_..., and the new record has been inserted next to the cursor
Updates the page hash index when a single record is inserted on a page.
cursor | in: cursor which was positioned to the place to insert using btr_cur_search_..., and the new record has been inserted next to the cursor |
Definition at line 1597 of file btr0sea.cc.
References btr_cur_get_block(), btr_cur_get_rec(), btr_search_latch, buf_block_struct::curr_left_side, buf_block_struct::curr_n_bytes, buf_block_struct::curr_n_fields, dict_index_is_ibuf(), ha_insert_for_fold, btr_search_sys_struct::hash_index, dict_index_struct::id, btr_cur_struct::index, buf_block_struct::index, buf_block_struct::is_hashed, buf_block_struct::lock, mem_heap_free, page_rec_get_next(), page_rec_is_infimum(), page_rec_is_supremum(), rec_fold(), ut_a, and ut_ad.
bool btr_search_enabled |
Flag: has the search system been enabled?
Protected by btr_search_latch and btr_search_enabled_mutex.
Definition at line 48 of file btr0sea.cc.
ibool btr_search_fully_disabled |
Flag: whether the search system has completed its disabling process,
It is set to TRUE right after buf_pool_drop_hash_index() in btr_search_disable(), indicating hash index entries are cleaned up. Protected by btr_search_latch and btr_search_enabled_mutex.
Definition at line 49 of file btr0sea.cc.
rw_lock_t* btr_search_latch_temp |
The latch protecting the adaptive search system.
This latch protects the (1) hash index; (2) columns of a record to which we have a pointer in the hash index;
but does NOT protect:
(3) next record offset field in a record; (4) next or previous records on the same page.
Bear in mind (3) and (4) when using the hash index.
The latch protecting the adaptive search system: this latch protects the
(1) positions of records on those pages where a hash index has been built. NOTE: It does not protect values of non-ordering fields within a record from being updated in-place! We can use fact (1) to perform unique searches to indexes.
Definition at line 77 of file btr0sea.cc.
btr_search_sys_t* btr_search_sys |
The adaptive hash index
Definition at line 84 of file btr0sea.cc.