1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*****************************************************************************
Copyright (c) 1996, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License, version 2.0, as published by the
Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
/** @file include/btr0sea.ic
The index tree adaptive search
Created 2/17/1996 Heikki Tuuri
*************************************************************************/
#include "btr0cur.h"
#include "buf0buf.h"
#include "dict0mem.h"
#include "sync0rw.h"
/** Updates the search info statistics following a search in B-tree that was
performed not using or not finding row with the AHI index. It may decide to try
to update the searched record on which the supplied cursor in positioned at, or
add the whole page to AHI.
@param[in] cursor cursor which was just positioned */
void btr_search_info_update_slow(btr_cur_t *cursor);
static inline void btr_search_info_update(btr_cur_t *cursor) {
const auto index = cursor->index;
ut_ad(!rw_lock_own(btr_get_search_latch(index), RW_LOCK_S));
ut_ad(!rw_lock_own(btr_get_search_latch(index), RW_LOCK_X));
if (dict_index_is_spatial(index) || !btr_search_enabled) {
return;
}
if (cursor->flag == BTR_CUR_HASH_NOT_ATTEMPTED) {
return;
}
const auto hash_analysis_value = ++index->search_info->hash_analysis;
if (hash_analysis_value < BTR_SEARCH_HASH_ANALYSIS) {
/* Do nothing */
return;
}
ut_ad(cursor->flag != BTR_CUR_HASH);
btr_search_info_update_slow(cursor);
}
static inline void btr_search_x_lock(const dict_index_t *index,
ut::Location location) {
rw_lock_x_lock_gen(btr_get_search_latch(index), 0, location);
}
static inline bool btr_search_x_lock_nowait(const dict_index_t *index,
ut::Location location) {
return rw_lock_x_lock_nowait(btr_get_search_latch(index), location);
}
static inline void btr_search_x_unlock(const dict_index_t *index) {
rw_lock_x_unlock(btr_get_search_latch(index));
}
static inline void btr_search_x_lock_all(ut::Location location) {
for (ulint i = 0; i < btr_ahi_parts; ++i) {
rw_lock_x_lock_gen(&btr_search_sys->parts[i].latch, 0, location);
}
}
static inline void btr_search_x_unlock_all() {
for (ulint i = 0; i < btr_ahi_parts; ++i) {
rw_lock_x_unlock(&btr_search_sys->parts[i].latch);
}
}
static inline void btr_search_s_lock(const dict_index_t *index,
ut::Location location) {
rw_lock_s_lock_gen(btr_get_search_latch(index), 0, location);
}
static inline bool btr_search_s_lock_nowait(const dict_index_t *index,
ut::Location location) {
return rw_lock_s_lock_nowait(btr_get_search_latch(index), location);
}
static inline void btr_search_s_unlock(const dict_index_t *index) {
rw_lock_s_unlock(btr_get_search_latch(index));
}
static inline void btr_search_s_lock_all(ut::Location location) {
for (ulint i = 0; i < btr_ahi_parts; ++i) {
rw_lock_s_lock_gen(&btr_search_sys->parts[i].latch, 0, location);
}
}
static inline void btr_search_s_unlock_all() {
for (ulint i = 0; i < btr_ahi_parts; ++i) {
rw_lock_s_unlock(&btr_search_sys->parts[i].latch);
}
}
#ifdef UNIV_DEBUG
static inline bool btr_search_own_all(ulint mode) {
for (ulint i = 0; i < btr_ahi_parts; ++i) {
if (!rw_lock_own(&btr_search_sys->parts[i].latch, mode)) {
return (false);
}
}
return (true);
}
static inline bool btr_search_own_any(ulint mode) {
for (ulint i = 0; i < btr_ahi_parts; ++i) {
if (rw_lock_own(&btr_search_sys->parts[i].latch, mode)) {
return (true);
}
}
return (false);
}
#endif /* UNIV_DEBUG */
static inline size_t btr_search_hash_index_id(const dict_index_t *index) {
return ut::hash_uint64_pair(index->space, index->id);
}
static inline btr_search_sys_t::search_part_t &btr_get_search_part(
const dict_index_t *index) {
ut_ad(index != nullptr);
const auto index_slot =
btr_search_hash_index_id(index) % btr_ahi_parts_fast_modulo;
return btr_search_sys->parts[index_slot];
}
static inline rw_lock_t *btr_get_search_latch(const dict_index_t *index) {
return &btr_get_search_part(index).latch;
}
|