MySQL 8.2.0
Source Code Documentation
heapdef.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23/* This file is included in all heap-files */
24
25#include "heap.h" /* Structs & some defines */
26#include "my_base.h" /* This includes global */
27#include "my_sys.h"
28#include "my_thread.h"
29#include "my_thread_local.h"
30#include "my_tree.h"
31
32/*
33 When allocating keys /rows in the internal block structure, do it
34 within the following boundaries.
35
36 The challenge is to find the balance between allocate as few blocks
37 as possible and keep memory consumption down.
38*/
39
40#define HP_MIN_RECORDS_IN_BLOCK 16
41#define HP_MAX_RECORDS_IN_BLOCK 8192
42
43/* Some extern variables */
44
46
47#define test_active(info) \
48 if (!(info->update & HA_STATE_AKTIV)) { \
49 set_my_errno(HA_ERR_NO_ACTIVE_RECORD); \
50 return -1; \
51 }
52#define hp_find_hash(A, B) ((HASH_INFO *)hp_find_block((A), (B)))
53
54/* Find pos for record and update it in info->current_ptr */
55#define hp_find_record(info, pos) \
56 (info)->current_ptr = hp_find_block(&(info)->s->block, pos)
57
58struct HASH_INFO {
61 ulong hash; /* Cached key hash value. */
62};
63
64typedef struct {
69
70/* Prototypes for intern functions */
71
72extern HP_SHARE *hp_find_named_heap(const char *name);
73extern int hp_rectest(HP_INFO *info, const uchar *old);
74extern uchar *hp_find_block(HP_BLOCK *info, ulong pos);
75extern int hp_get_new_block(HP_BLOCK *info, size_t *alloc_length);
76extern void hp_free(HP_SHARE *info);
77extern uchar *hp_free_level(HP_BLOCK *block, uint level, HP_PTRS *pos,
78 uchar *last_pos);
79extern int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record,
80 uchar *recpos);
81extern int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
82 const uchar *record, uchar *recpos);
83extern int hp_rb_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo,
84 const uchar *record, uchar *recpos, int flag);
85extern int hp_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record,
86 uchar *recpos, int flag);
87extern HASH_INFO *_heap_find_hash(HP_BLOCK *block, ulong pos);
88extern uchar *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key,
89 uint nextflag);
90extern uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo,
91 const uchar *key, HASH_INFO *pos);
92extern uint64 hp_hashnr(HP_KEYDEF *keyinfo, const uchar *key);
93extern uint64 hp_rec_hashnr(HP_KEYDEF *keyinfo, const uchar *rec);
94extern uint64 hp_mask(uint64 hashnr, uint64 buffmax, uint64 maxlength);
95extern void hp_movelink(HASH_INFO *pos, HASH_INFO *next_link,
96 HASH_INFO *newlink);
97extern int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1,
98 const uchar *rec2);
99extern int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key);
100extern void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec);
101extern uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec,
102 uchar *recpos);
103extern uint hp_rb_key_length(HP_KEYDEF *keydef, const uchar *key);
104extern uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key);
105extern uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key);
106extern bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const uchar *record);
107extern int hp_close(HP_INFO *info);
108extern void hp_clear(HP_SHARE *info);
109extern void hp_clear_keys(HP_SHARE *info);
110extern uint hp_rb_pack_key(const HP_KEYDEF *keydef, uchar *key,
111 const uchar *old, key_part_map keypart_map);
112
114
119
120#ifdef HAVE_PSI_INTERFACE
121
122void init_heap_psi_keys();
123#endif /* HAVE_PSI_INTERFACE */
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:48
uchar * hp_free_level(HP_BLOCK *block, uint level, HP_PTRS *pos, uchar *last_pos)
Definition: hp_block.cc:131
LIST * heap_share_list
Definition: heapdef.h:45
uint64 hp_hashnr(HP_KEYDEF *keyinfo, const uchar *key)
Definition: hp_hash.cc:227
void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec)
Definition: hp_hash.cc:526
uint hp_rb_pack_key(const HP_KEYDEF *keydef, uchar *key, const uchar *old, key_part_map keypart_map)
Definition: hp_hash.cc:629
int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos)
Definition: hp_write.cc:203
int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1, const uchar *rec2)
Definition: hp_hash.cc:366
uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key)
Definition: hp_hash.cc:705
uint hp_rb_key_length(HP_KEYDEF *keydef, const uchar *key)
Definition: hp_hash.cc:690
uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec, uchar *recpos)
Definition: hp_hash.cc:557
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:41
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:175
int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos)
Definition: hp_write.cc:107
uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key)
Definition: hp_hash.cc:694
uchar * hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key, uint nextflag)
Definition: hp_hash.cc:106
void init_heap_psi_keys()
Definition: hp_static.cc:51
mysql_mutex_t THR_LOCK_heap
Definition: my_thr_init.cc:73
uint64 hp_mask(uint64 hashnr, uint64 buffmax, uint64 maxlength)
Definition: hp_hash.cc:204
int hp_rb_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos, int flag)
Definition: hp_delete.cc:75
int hp_rectest(HP_INFO *info, const uchar *old)
Definition: _rectest.cc:30
void hp_free(HP_SHARE *info)
Definition: hp_create.cc:311
uchar * hp_find_block(HP_BLOCK *info, ulong pos)
Definition: hp_block.cc:41
int hp_get_new_block(HP_BLOCK *info, size_t *alloc_length)
Definition: hp_block.cc:67
uint64 hp_rec_hashnr(HP_KEYDEF *keyinfo, const uchar *rec)
Definition: hp_hash.cc:294
bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const uchar *record)
Definition: hp_hash.cc:727
int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key)
Definition: hp_hash.cc:444
PSI_memory_key hp_key_memory_HP_SHARE
Definition: hp_static.cc:38
void hp_clear(HP_SHARE *info)
Definition: hp_clear.cc:37
HP_SHARE * hp_find_named_heap(const char *name)
Definition: hp_open.cc:136
void hp_clear_keys(HP_SHARE *info)
Definition: hp_clear.cc:82
int hp_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos, int flag)
Definition: hp_delete.cc:109
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:216
PSI_memory_key hp_key_memory_HP_INFO
Definition: hp_static.cc:39
static int flag
Definition: hp_test1.cc:39
This file includes constants used by all storage engines.
ulong key_part_map
Definition: my_base.h:1006
unsigned char uchar
Definition: my_inttypes.h:51
uint64_t uint64
Definition: my_inttypes.h:68
Common header for many mysys elements.
Defines to make different thread packages compatible.
Log info(cout, "NOTE")
static int record
Definition: mysqltest.cc:194
required string key
Definition: replication_asynchronous_connection_failover.proto:59
case opt name
Definition: sslopt-case.h:32
Definition: heapdef.h:58
HASH_INFO * next_key
Definition: heapdef.h:59
ulong hash
Definition: heapdef.h:61
uchar * ptr_to_rec
Definition: heapdef.h:60
Definition: my_compare.h:59
Definition: heap.h:108
Definition: heap.h:167
Definition: heap.h:120
Definition: heap.h:70
Definition: heap.h:140
Definition: my_list.h:35
Definition: heapdef.h:64
uint key_length
Definition: heapdef.h:66
uint search_flag
Definition: heapdef.h:67
HA_KEYSEG * keyseg
Definition: heapdef.h:65
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49