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