MySQL 8.0.40
Source Code Documentation
heapdef.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24/* This file is included in all heap-files */
25
26#include "heap.h" /* Structs & some defines */
27#include "m_string.h"
28#include "my_base.h" /* This includes global */
29#include "my_sys.h"
30#include "my_thread.h"
31#include "my_thread_local.h"
32#include "my_tree.h"
33
34/*
35 When allocating keys /rows in the internal block structure, do it
36 within the following boundaries.
37
38 The challenge is to find the balance between allocate as few blocks
39 as possible and keep memory consumption down.
40*/
41
42#define HP_MIN_RECORDS_IN_BLOCK 16
43#define HP_MAX_RECORDS_IN_BLOCK 8192
44
45/* Some extern variables */
46
48
49#define test_active(info) \
50 if (!(info->update & HA_STATE_AKTIV)) { \
51 set_my_errno(HA_ERR_NO_ACTIVE_RECORD); \
52 return -1; \
53 }
54#define hp_find_hash(A, B) ((HASH_INFO *)hp_find_block((A), (B)))
55
56/* Find pos for record and update it in info->current_ptr */
57#define hp_find_record(info, pos) \
58 (info)->current_ptr = hp_find_block(&(info)->s->block, pos)
59
60struct HASH_INFO {
63 ulong hash; /* Cached key hash value. */
64};
65
66typedef struct {
71
72/* Prototypes for intern functions */
73
74extern HP_SHARE *hp_find_named_heap(const char *name);
75extern int hp_rectest(HP_INFO *info, const uchar *old);
76extern uchar *hp_find_block(HP_BLOCK *info, ulong pos);
77extern int hp_get_new_block(HP_BLOCK *info, size_t *alloc_length);
78extern void hp_free(HP_SHARE *info);
79extern uchar *hp_free_level(HP_BLOCK *block, uint level, HP_PTRS *pos,
80 uchar *last_pos);
81extern int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record,
82 uchar *recpos);
83extern int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
84 const uchar *record, uchar *recpos);
85extern int hp_rb_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo,
86 const uchar *record, uchar *recpos, int flag);
87extern int hp_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record,
88 uchar *recpos, int flag);
89extern HASH_INFO *_heap_find_hash(HP_BLOCK *block, ulong pos);
90extern uchar *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
91 uint nextflag);
92extern uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo,
93 const uchar *key, HASH_INFO *pos);
94extern uint64 hp_hashnr(HP_KEYDEF *keyinfo, const uchar *key);
95extern uint64 hp_rec_hashnr(HP_KEYDEF *keyinfo, const uchar *rec);
96extern uint64 hp_mask(uint64 hashnr, uint64 buffmax, uint64 maxlength);
97extern void hp_movelink(HASH_INFO *pos, HASH_INFO *next_link,
98 HASH_INFO *newlink);
99extern int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1,
100 const uchar *rec2);
101extern int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key);
102extern void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec);
103extern uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec,
104 uchar *recpos);
105extern uint hp_rb_key_length(HP_KEYDEF *keydef, const uchar *key);
106extern uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key);
107extern uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key);
108extern bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const uchar *record);
109extern int hp_close(HP_INFO *info);
110extern void hp_clear(HP_SHARE *info);
111extern void hp_clear_keys(HP_SHARE *info);
112extern uint hp_rb_pack_key(const HP_KEYDEF *keydef, uchar *key,
113 const uchar *old, key_part_map keypart_map);
114
116
121
122#ifdef HAVE_PSI_INTERFACE
123
124void init_heap_psi_keys();
125#endif /* HAVE_PSI_INTERFACE */
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
uchar * hp_free_level(HP_BLOCK *block, uint level, HP_PTRS *pos, uchar *last_pos)
Definition: hp_block.cc:132
LIST * heap_share_list
Definition: heapdef.h:47
uint64 hp_hashnr(HP_KEYDEF *keyinfo, const uchar *key)
Definition: hp_hash.cc:228
void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec)
Definition: hp_hash.cc:527
uint hp_rb_pack_key(const HP_KEYDEF *keydef, uchar *key, const uchar *old, key_part_map keypart_map)
Definition: hp_hash.cc:630
int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos)
Definition: hp_write.cc:204
int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1, const uchar *rec2)
Definition: hp_hash.cc:367
uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key)
Definition: hp_hash.cc:706
uint hp_rb_key_length(HP_KEYDEF *keydef, const uchar *key)
Definition: hp_hash.cc:691
uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec, uchar *recpos)
Definition: hp_hash.cc:558
LIST * heap_open_list
Definition: hp_static.cc:36
PSI_memory_key hp_key_memory_HP_KEYDEF
Definition: hp_static.cc:41
int hp_close(HP_INFO *info)
Definition: hp_close.cc:42
PSI_memory_key hp_key_memory_HP_PTRS
Definition: hp_static.cc:40
uchar * hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key, HASH_INFO *pos)
Definition: hp_hash.cc:176
int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos)
Definition: hp_write.cc:108
uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key)
Definition: hp_hash.cc:695
uchar * hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key, uint nextflag)
Definition: hp_hash.cc:107
void init_heap_psi_keys()
Definition: hp_static.cc:51
mysql_mutex_t THR_LOCK_heap
Definition: my_thr_init.cc:74
uint64 hp_mask(uint64 hashnr, uint64 buffmax, uint64 maxlength)
Definition: hp_hash.cc:205
int hp_rb_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos, int flag)
Definition: hp_delete.cc:76
int hp_rectest(HP_INFO *info, const uchar *old)
Definition: _rectest.cc:31
void hp_free(HP_SHARE *info)
Definition: hp_create.cc:312
uchar * hp_find_block(HP_BLOCK *info, ulong pos)
Definition: hp_block.cc:42
int hp_get_new_block(HP_BLOCK *info, size_t *alloc_length)
Definition: hp_block.cc:68
uint64 hp_rec_hashnr(HP_KEYDEF *keyinfo, const uchar *rec)
Definition: hp_hash.cc:295
bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const uchar *record)
Definition: hp_hash.cc:728
int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key)
Definition: hp_hash.cc:445
PSI_memory_key hp_key_memory_HP_SHARE
Definition: hp_static.cc:38
void hp_clear(HP_SHARE *info)
Definition: hp_clear.cc:38
HP_SHARE * hp_find_named_heap(const char *name)
Definition: hp_open.cc:137
void hp_clear_keys(HP_SHARE *info)
Definition: hp_clear.cc:83
int hp_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos, int flag)
Definition: hp_delete.cc:110
HASH_INFO * _heap_find_hash(HP_BLOCK *block, ulong pos)
void hp_movelink(HASH_INFO *pos, HASH_INFO *next_link, HASH_INFO *newlink)
Definition: hp_hash.cc:217
PSI_memory_key hp_key_memory_HP_INFO
Definition: hp_static.cc:39
static int flag
Definition: hp_test1.cc:40
This file includes constants used by all storage engines.
ulong key_part_map
Definition: my_base.h:1007
unsigned char uchar
Definition: my_inttypes.h:52
uint64_t uint64
Definition: my_inttypes.h:69
Common header for many mysys elements.
Defines to make different thread packages compatible.
Log info(cout, "NOTE")
static int record
Definition: mysqltest.cc:188
required string key
Definition: replication_asynchronous_connection_failover.proto:60
case opt name
Definition: sslopt-case.h:33
Definition: heapdef.h:60
HASH_INFO * next_key
Definition: heapdef.h:61
ulong hash
Definition: heapdef.h:63
uchar * ptr_to_rec
Definition: heapdef.h:62
Definition: my_compare.h:60
Definition: heap.h:109
Definition: heap.h:168
Definition: heap.h:121
Definition: heap.h:71
Definition: heap.h:141
Definition: my_list.h:36
Definition: heapdef.h:66
uint key_length
Definition: heapdef.h:68
uint search_flag
Definition: heapdef.h:69
HA_KEYSEG * keyseg
Definition: heapdef.h:67
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
unsigned int uint
Definition: uca9-dump.cc:75