MySQL  8.0.18
Source Code Documentation
heapdef.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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 "m_string.h"
27 #include "my_base.h" /* This includes global */
28 #include "my_sys.h"
29 #include "my_thread.h"
30 #include "my_thread_local.h"
31 #include "my_tree.h"
32 
33 /*
34  When allocating keys /rows in the internal block structure, do it
35  within the following boundaries.
36 
37  The challenge is to find the balance between allocate as few blocks
38  as possible and keep memory consumption down.
39 */
40 
41 #define HP_MIN_RECORDS_IN_BLOCK 16
42 #define HP_MAX_RECORDS_IN_BLOCK 8192
43 
44 /* Some extern variables */
45 
47 
48 #define test_active(info) \
49  if (!(info->update & HA_STATE_AKTIV)) { \
50  set_my_errno(HA_ERR_NO_ACTIVE_RECORD); \
51  return -1; \
52  }
53 #define hp_find_hash(A, B) ((HASH_INFO *)hp_find_block((A), (B)))
54 
55 /* Find pos for record and update it in info->current_ptr */
56 #define hp_find_record(info, pos) \
57  (info)->current_ptr = hp_find_block(&(info)->s->block, pos)
58 
59 struct HASH_INFO {
62  ulong hash; /* Cached key hash value. */
63 };
64 
65 typedef struct {
70 
71 /* Prototypes for intern functions */
72 
73 extern HP_SHARE *hp_find_named_heap(const char *name);
74 extern int hp_rectest(HP_INFO *info, const uchar *old);
76 extern int hp_get_new_block(HP_BLOCK *info, size_t *alloc_length);
77 extern void hp_free(HP_SHARE *info);
78 extern uchar *hp_free_level(HP_BLOCK *block, uint level, HP_PTRS *pos,
79  uchar *last_pos);
80 extern int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record,
81  uchar *recpos);
83  const uchar *record, uchar *recpos);
85  const uchar *record, uchar *recpos, int flag);
86 extern int hp_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record,
87  uchar *recpos, int flag);
88 extern HASH_INFO *_heap_find_hash(HP_BLOCK *block, ulong pos);
90  uint nextflag);
92  const uchar *key, HASH_INFO *pos);
93 extern uint64 hp_hashnr(HP_KEYDEF *keyinfo, const uchar *key);
94 extern uint64 hp_rec_hashnr(HP_KEYDEF *keyinfo, const uchar *rec);
95 extern uint64 hp_mask(uint64 hashnr, uint64 buffmax, uint64 maxlength);
96 extern void hp_movelink(HASH_INFO *pos, HASH_INFO *next_link,
97  HASH_INFO *newlink);
98 extern int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1,
99  const uchar *rec2);
100 extern int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key);
101 extern void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec);
102 extern uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec,
103  uchar *recpos);
104 extern uint hp_rb_key_length(HP_KEYDEF *keydef, const uchar *key);
105 extern uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key);
106 extern uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key);
107 extern bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const uchar *record);
108 extern int hp_close(HP_INFO *info);
109 extern void hp_clear(HP_SHARE *info);
110 extern void hp_clear_keys(HP_SHARE *info);
111 extern uint hp_rb_pack_key(const HP_KEYDEF *keydef, uchar *key,
112  const uchar *old, key_part_map keypart_map);
113 
115 
120 
121 #ifdef HAVE_PSI_INTERFACE
122 
123 void init_heap_psi_keys();
124 #endif /* HAVE_PSI_INTERFACE */
uchar * hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key, HASH_INFO *pos)
Definition: hp_hash.cc:172
HASH_INFO * _heap_find_hash(HP_BLOCK *block, ulong pos)
int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos)
Definition: hp_write.cc:107
mysql_mutex_t THR_LOCK_heap
Definition: my_thr_init.cc:73
uchar * hp_free_level(HP_BLOCK *block, uint level, HP_PTRS *pos, uchar *last_pos)
Definition: hp_block.cc:131
unsigned char uchar
Definition: my_inttypes.h:51
void init_heap_psi_keys()
Definition: hp_static.cc:50
uchar * hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *key, uint nextflag)
Definition: hp_hash.cc:104
Definition: heap.h:167
uchar * ptr_to_rec
Definition: heapdef.h:61
Definition: heap.h:119
const string name("\ame\)
PSI_memory_key hp_key_memory_HP_INFO
Definition: hp_static.cc:38
Definition: mi_test3.cc:54
ulong key_part_map
Definition: my_base.h:998
void hp_clear(HP_SHARE *info)
Definition: hp_clear.cc:37
Definition: heapdef.h:65
LIST * heap_open_list
Definition: hp_static.cc:35
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:46
HA_KEYSEG * keyseg
Definition: heapdef.h:66
uint search_flag
Definition: heapdef.h:68
uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec, uchar *recpos)
Definition: hp_hash.cc:548
LIST * heap_share_list
Definition: hp_static.cc:35
This file includes constants used by all storage engines.
uint hp_rb_pack_key(const HP_KEYDEF *keydef, uchar *key, const uchar *old, key_part_map keypart_map)
Definition: hp_hash.cc:620
Definition: heap.h:140
char * pos
Definition: do_ctype.cc:76
int hp_rb_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos, int flag)
Definition: hp_delete.cc:75
uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key)
Definition: hp_hash.cc:696
Definition: heap.h:70
PSI_memory_key hp_key_memory_HP_KEYDEF
Definition: hp_static.cc:40
void hp_movelink(HASH_INFO *pos, HASH_INFO *next_link, HASH_INFO *newlink)
Definition: hp_hash.cc:213
void hp_free(HP_SHARE *info)
Definition: hp_create.cc:309
bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const uchar *record)
Definition: hp_hash.cc:718
uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key)
Definition: hp_hash.cc:685
int hp_delete_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos, int flag)
Definition: hp_delete.cc:109
void hp_make_key(HP_KEYDEF *keydef, uchar *key, const uchar *rec)
Definition: hp_hash.cc:521
Definition: heap.h:108
uint64 hp_rec_hashnr(HP_KEYDEF *keyinfo, const uchar *rec)
Definition: hp_hash.cc:291
ulong hash
Definition: heapdef.h:62
unsigned int uint
Definition: uca-dump.cc:29
int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const uchar *record, uchar *recpos)
Definition: hp_write.cc:203
Defines to make different thread packages compatible.
void hp_clear_keys(HP_SHARE *info)
Definition: hp_clear.cc:82
Common header for many mysys elements.
static const char * key
Definition: suite_stubs.c:14
int hp_rec_key_cmp(HP_KEYDEF *keydef, const uchar *rec1, const uchar *rec2)
Definition: hp_hash.cc:362
uint64 hp_mask(uint64 hashnr, uint64 buffmax, uint64 maxlength)
Definition: hp_hash.cc:201
PSI_memory_key hp_key_memory_HP_SHARE
Definition: hp_static.cc:37
HASH_INFO * next_key
Definition: heapdef.h:60
int hp_rectest(HP_INFO *info, const uchar *old)
Definition: _rectest.cc:30
static MI_KEYDEF keyinfo[10]
Definition: mi_test1.cc:46
static int flag
Definition: hp_test1.cc:39
uint hp_rb_key_length(HP_KEYDEF *keydef, const uchar *key)
Definition: hp_hash.cc:680
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
PSI_memory_key hp_key_memory_HP_PTRS
Definition: hp_static.cc:39
Definition: my_list.h:41
Definition: heapdef.h:59
uint key_length
Definition: heapdef.h:67
int hp_key_cmp(HP_KEYDEF *keydef, const uchar *rec, const uchar *key)
Definition: hp_hash.cc:440
int hp_get_new_block(HP_BLOCK *info, size_t *alloc_length)
Definition: hp_block.cc:67
Log info(cout, "NOTE")
HP_SHARE * hp_find_named_heap(const char *name)
Definition: hp_open.cc:136
uint64 hp_hashnr(HP_KEYDEF *keyinfo, const uchar *key)
Definition: hp_hash.cc:224
int hp_close(HP_INFO *info)
Definition: hp_close.cc:41
unsigned long ulong
Definition: my_inttypes.h:48
Definition: my_compare.h:58
uint64_t uint64
Definition: my_inttypes.h:68
uchar * hp_find_block(HP_BLOCK *info, ulong pos)
Definition: hp_block.cc:41