MySQL 8.0.31
Source Code Documentation
ha0ha.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1994, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/ha0ha.h
28 The hash table with external chains
29
30 Created 8/18/1994 Heikki Tuuri
31 *******************************************************/
32
33#ifndef ha0ha_h
34#define ha0ha_h
35
36#include "univ.i"
37
38#include "buf0types.h"
39#include "hash0hash.h"
40#include "page0types.h"
41#include "rem0types.h"
42
43/** Looks for an element in a hash table.
44@param[in] table hash table
45@param[in] hash_value hashed value of the searched data
46@return pointer to the data of the first hash table node in chain
47having the hash number, NULL if not found */
48static inline const rec_t *ha_search_and_get_data(hash_table_t *table,
49 uint64_t hash_value);
50
51/** Looks for an element when we know the pointer to the data and updates
52 the pointer to data if found.
53 @param[in,out] table hash table
54 @param[in] hash_value hashed value of the searched data
55 @param[in] data pointer to the data
56 @param[in] new_block block containing new data
57 @param[in] new_data new pointer to the data
58 @return true if found */
60 uint64_t hash_value, const rec_t *data,
61 IF_AHI_DEBUG(buf_block_t *new_block, )
62 const rec_t *new_data);
63
64/** Looks for an element when we know the pointer to the data and
65updates the pointer to data if found.
66@param table in/out: hash table
67@param hash_value in: hashed value of the searched data
68@param data in: pointer to the data
69@param new_block in: block containing new_data
70@param new_data in: new pointer to the data */
72 uint64_t hash_value,
73 const rec_t *data,
74 buf_block_t *new_block,
75 const rec_t *new_data) {
76 return ha_search_and_update_if_found_func(table, hash_value, data,
77 IF_AHI_DEBUG(new_block, ) new_data);
78}
79/** Creates a hash table with at least n array cells. The actual number
80 of cells is chosen to be a prime number slightly bigger than n.
81 @param[in] n number of array cells
82 @param[in] id latch ID
83 @param[in] n_sync_obj Number of sync objects protecting the hash table.
84 Must be a power of 2, or 0.
85 @param[in] type type of datastructure for which the memory heap is going
86 to be used:
87 MEM_HEAP_FOR_BTR_SEARCH or
88 MEM_HEAP_FOR_PAGE_HASH
89 @return own: created table */
90hash_table_t *ib_create(size_t n, latch_id_t id, size_t n_sync_obj,
91 uint32_t type);
92
93/** Empties a hash table and frees the memory heaps. */
94void ha_clear(hash_table_t *table); /*!< in, own: hash table */
95
96/** Inserts an entry into a hash table. If an entry with the same hash number
97 is found, its node is updated to point to the new data, and no new node
98 is inserted. If btr_search_enabled is set to false, we will only allow
99 updating existing nodes, but no new node is allowed to be added.
100 @param[in] table hash table
101 @param[in] hash_value hashed value of data; if a node with the same hash value
102 already exists, it is updated to point to the same data, and no new node is
103 created!
104 @param[in] block buffer block containing the data
105 @param[in] data data, must not be NULL
106 @return true if succeeded, false if no more memory could be allocated */
107bool ha_insert_for_hash_func(hash_table_t *table, uint64_t hash_value,
108 IF_AHI_DEBUG(buf_block_t *block, )
109 const rec_t *data);
110
111/**
112Inserts an entry into a hash table. If an entry with the same hash number
113is found, its node is updated to point to the new data, and no new node
114is inserted.
115@param[in] t hash table
116@param[in] f hashed value of data
117@param[in] b buffer block containing the data
118@param[in] d data, must not be NULL */
119static inline void ha_insert_for_hash(hash_table_t *t, uint64_t f,
120 buf_block_t *b, const rec_t *d) {
123}
124
125/** Looks for an element when we know the pointer to the data and deletes it
126from the hash table if found.
127@param[in] table hash table
128@param[in] hash_value hashed value of the searched data
129@param[in] data pointer to the data
130@return true if found */
132 uint64_t hash_value,
133 const rec_t *data);
134
135#ifndef UNIV_HOTBACKUP
136
137/** Removes from the chain determined by hash value a single node whose data
138pointer points to the page given. Note that the node deleted can have a
139different hash value.
140@param[in] table Hash table
141@param[in] hash_value Hash value
142@param[in] page Buffer page */
143void ha_remove_a_node_to_page(hash_table_t *table, uint64_t hash_value,
144 const page_t *page);
145
146#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
147/** Validates a given range of the cells in hash table.
148@param[in] table Hash table
149@param[in] start_index Start index
150@param[in] end_index End index
151@return true if ok */
152bool ha_validate(hash_table_t *table, uint64_t start_index, uint64_t end_index);
153#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
154
155/** Prints info of a hash table.
156@param[in] file File where to print
157@param[in] table Hash table */
158void ha_print_info(FILE *file, hash_table_t *table);
159
160#endif /* !UNIV_HOTBACKUP */
161
162/** The hash table external chain node */
163struct ha_node_t {
164 /** hash value for the data */
165 uint64_t hash_value;
166 /** next chain node or NULL if none */
168#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
169 /** buffer block containing the data, or NULL */
171#endif
172 /** pointer to the data */
173 const rec_t *data;
174};
175
176#include "ha0ha.ic"
177
178#endif
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
The database buffer pool global types for the directory.
Definition: hash0hash.h:373
int page
Definition: ctype-mb.cc:1235
static void ha_insert_for_hash(hash_table_t *t, uint64_t f, buf_block_t *b, const rec_t *d)
Inserts an entry into a hash table.
Definition: ha0ha.h:119
void ha_print_info(FILE *file, hash_table_t *table)
Prints info of a hash table.
Definition: ha0ha.cc:322
void ha_remove_a_node_to_page(hash_table_t *table, uint64_t hash_value, const page_t *page)
Removes from the chain determined by hash value a single node whose data pointer points to the page g...
Definition: ha0ha.cc:258
static bool ha_search_and_delete_if_found(hash_table_t *table, uint64_t hash_value, const rec_t *data)
Looks for an element when we know the pointer to the data and deletes it from the hash table if found...
static const rec_t * ha_search_and_get_data(hash_table_t *table, uint64_t hash_value)
Looks for an element in a hash table.
hash_table_t * ib_create(size_t n, latch_id_t id, size_t n_sync_obj, uint32_t type)
Creates a hash table with at least n array cells.
Definition: ha0ha.cc:48
bool ha_insert_for_hash_func(hash_table_t *table, uint64_t hash_value, buf_block_t *block, const rec_t *data)
Inserts an entry into a hash table.
Definition: ha0ha.cc:103
bool ha_search_and_update_if_found_func(hash_table_t *table, uint64_t hash_value, const rec_t *data, buf_block_t *new_block, const rec_t *new_data)
Looks for an element when we know the pointer to the data and updates the pointer to data if found.
Definition: ha0ha.cc:220
static bool ha_search_and_update_if_found(hash_table_t *table, uint64_t hash_value, const rec_t *data, buf_block_t *new_block, const rec_t *new_data)
Looks for an element when we know the pointer to the data and updates the pointer to data if found.
Definition: ha0ha.h:71
void ha_clear(hash_table_t *table)
Empties a hash table and frees the memory heaps.
Definition: ha0ha.cc:78
bool ha_validate(hash_table_t *table, uint64_t start_index, uint64_t end_index)
Validates a given range of the cells in hash table.
Definition: ha0ha.cc:285
The hash table with external chains.
The simple hash table utility.
const std::string FILE("FILE")
Definition: os0file.h:85
Index page routines.
byte page_t
Type of the index page.
Definition: page0types.h:151
Record manager global types.
byte rec_t
Definition: rem0types.h:40
required string type
Definition: replication_group_member_actions.proto:33
#define MONITOR_ATOMIC_INC(monitor)
Atomically increment a monitor counter.
Definition: srv0mon.h:688
@ MONITOR_ADAPTIVE_HASH_ROW_ADDED
Definition: srv0mon.h:428
The buffer control block structure.
Definition: buf0buf.h:1664
The hash table external chain node.
Definition: ha0ha.h:163
ha_node_t * next
next chain node or NULL if none
Definition: ha0ha.h:167
const rec_t * data
pointer to the data
Definition: ha0ha.h:173
buf_block_t * block
buffer block containing the data, or NULL
Definition: ha0ha.h:170
uint64_t hash_value
hash value for the data
Definition: ha0ha.h:165
latch_id_t
Each latch has an ID.
Definition: sync0types.h:339
Version control for database, common definitions, and include files.
#define IF_AHI_DEBUG(...)
Definition: univ.i:693
int n
Definition: xcom_base.cc:505