Drizzled Public API Documentation

btr0sea.h File Reference
#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
 

Functions

UNIV_INTERN void btr_search_sys_create (ulint hash_size)
 
UNIV_INTERN void btr_search_sys_free (void)
 
UNIV_INTERN void btr_search_disable (void)
 
UNIV_INTERN void btr_search_enable (void)
 
UNIV_INLINE btr_search_tbtr_search_get_info (dict_index_t *index)
 
UNIV_INTERN btr_search_tbtr_search_info_create (mem_heap_t *heap)
 
UNIV_INTERN ulint btr_search_info_get_ref_count (btr_search_t *info)
 
UNIV_INLINE void btr_search_info_update (dict_index_t *index, btr_cur_t *cursor)
 
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)
 
UNIV_INTERN void btr_search_move_or_delete_hash_entries (buf_block_t *new_block, buf_block_t *block, dict_index_t *index)
 
UNIV_INTERN void btr_search_drop_page_hash_index (buf_block_t *block)
 
UNIV_INTERN void btr_search_drop_page_hash_when_freed (ulint space, ulint zip_size, ulint page_no)
 
UNIV_INTERN void btr_search_update_hash_node_on_insert (btr_cur_t *cursor)
 
UNIV_INTERN void btr_search_update_hash_on_insert (btr_cur_t *cursor)
 
UNIV_INTERN void btr_search_update_hash_on_delete (btr_cur_t *cursor)
 

Variables

bool btr_search_enabled
 
ibool btr_search_fully_disabled
 
btr_search_sys_tbtr_search_sys
 
rw_lock_tbtr_search_latch_temp
 The latch protecting the adaptive search system. More...
 

Detailed Description

The index tree adaptive search

Created 2/17/1996 Heikki Tuuri

Definition in file btr0sea.h.

Macro Definition Documentation

#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
After change in n_fields or n_bytes in info, this many rounds are waited

before starting the hash analysis again: this is to save CPU time when there is no hope in building a hash index.

Definition at line 302 of file btr0sea.h.

#define BTR_SEARCH_ON_HASH_LIMIT   3
Limit of consecutive searches for trying a search shortcut using

the hash index

Definition at line 310 of file btr0sea.h.

#define BTR_SEARCH_ON_PATTERN_LIMIT   3
Limit of consecutive searches for trying a search shortcut on the search

pattern

Definition at line 306 of file btr0sea.h.

Typedef Documentation

The hash index system

Definition at line 262 of file btr0sea.h.

Function Documentation

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.

Parameters
blockin: 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.

Parameters
spacein: space id
zip_sizein: compressed page size in bytes or 0 for uncompressed pages
page_noin: page number

Definition at line 1188 of file btr0sea.cc.

References BUF_PEEK_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.

Returns
search info; search mutex reserved in: 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.

Returns
TRUE if succeeded in: 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.

Returns
TRUE if succeeded
Parameters
indexin: index
infoin: index search info
tuplein: logical record
modein: PAGE_CUR_L, ...
latch_modein: 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!
cursorout: tree cursor
has_search_latchin: latch mode the caller currently has on btr_search_latch: RW_S_LATCH, RW_X_LATCH, or 0
mtrin: 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_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.

Returns
own: search info struct in: heap where created

Creates and initializes a search info struct.

Returns
own: search info struct
Parameters
heapin: 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
ref_count value. in: search info.

Returns the value of ref_count. The value is protected by btr_search_latch.

Returns
ref_count value.
Parameters
infoin: 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

Parameters
indexin: 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).

Parameters
new_blockin: records are copied to this page
blockin: index page from which records were copied, and the copied records will be deleted from this page
indexin: 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.

Parameters
hash_sizein: 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.

Parameters
cursorin: 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.

Parameters
cursorin: 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.

Parameters
cursorin: 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.

Variable Documentation

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.