MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
heapdef.h
1 /* Copyright (c) 2000, 2011, 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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 /* This file is included in all heap-files */
17 
18 #include <my_base.h> /* This includes global */
19 C_MODE_START
20 #include <my_pthread.h>
21 #include "heap.h" /* Structs & some defines */
22 #include "my_tree.h"
23 
24 /*
25  When allocating keys /rows in the internal block structure, do it
26  within the following boundaries.
27 
28  The challenge is to find the balance between allocate as few blocks
29  as possible and keep memory consumption down.
30 */
31 
32 #define HP_MIN_RECORDS_IN_BLOCK 16
33 #define HP_MAX_RECORDS_IN_BLOCK 8192
34 
35  /* Some extern variables */
36 
37 extern LIST *heap_open_list,*heap_share_list;
38 
39 #define test_active(info) \
40 if (!(info->update & HA_STATE_AKTIV))\
41 { my_errno=HA_ERR_NO_ACTIVE_RECORD; DBUG_RETURN(-1); }
42 #define hp_find_hash(A,B) ((HASH_INFO*) hp_find_block((A),(B)))
43 
44  /* Find pos for record and update it in info->current_ptr */
45 #define hp_find_record(info,pos) (info)->current_ptr= hp_find_block(&(info)->s->block,pos)
46 
47 typedef struct st_hp_hash_info
48 {
49  struct st_hp_hash_info *next_key;
50  uchar *ptr_to_rec;
51 } HASH_INFO;
52 
53 typedef struct {
54  HA_KEYSEG *keyseg;
55  uint key_length;
56  uint search_flag;
58 
59  /* Prototypes for intern functions */
60 
61 extern HP_SHARE *hp_find_named_heap(const char *name);
62 extern int hp_rectest(HP_INFO *info,const uchar *old);
63 extern uchar *hp_find_block(HP_BLOCK *info,ulong pos);
64 extern int hp_get_new_block(HP_BLOCK *info, size_t* alloc_length);
65 extern void hp_free(HP_SHARE *info);
66 extern uchar *hp_free_level(HP_BLOCK *block,uint level,HP_PTRS *pos,
67  uchar *last_pos);
68 extern int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
69  const uchar *record, uchar *recpos);
70 extern int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
71  const uchar *record, uchar *recpos);
72 extern int hp_rb_delete_key(HP_INFO *info,HP_KEYDEF *keyinfo,
73  const uchar *record,uchar *recpos,int flag);
74 extern int hp_delete_key(HP_INFO *info,HP_KEYDEF *keyinfo,
75  const uchar *record,uchar *recpos,int flag);
76 extern HASH_INFO *_heap_find_hash(HP_BLOCK *block,ulong pos);
77 extern uchar *hp_search(HP_INFO *info,HP_KEYDEF *keyinfo,const uchar *key,
78  uint nextflag);
79 extern uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo,
80  const uchar *key, HASH_INFO *pos);
81 extern ulong hp_hashnr(HP_KEYDEF *keyinfo,const uchar *key);
82 extern ulong hp_rec_hashnr(HP_KEYDEF *keyinfo,const uchar *rec);
83 extern ulong hp_mask(ulong hashnr,ulong buffmax,ulong maxlength);
84 extern void hp_movelink(HASH_INFO *pos,HASH_INFO *next_link,
85  HASH_INFO *newlink);
86 extern int hp_rec_key_cmp(HP_KEYDEF *keydef,const uchar *rec1,
87  const uchar *rec2,
88  my_bool diff_if_only_endspace_difference);
89 extern int hp_key_cmp(HP_KEYDEF *keydef,const uchar *rec,
90  const uchar *key);
91 extern void hp_make_key(HP_KEYDEF *keydef,uchar *key,const uchar *rec);
92 extern uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key,
93  const uchar *rec, uchar *recpos);
94 extern uint hp_rb_key_length(HP_KEYDEF *keydef, const uchar *key);
95 extern uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key);
96 extern uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key);
97 extern my_bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const uchar *record);
98 extern int hp_close(register HP_INFO *info);
99 extern void hp_clear(HP_SHARE *info);
100 extern void hp_clear_keys(HP_SHARE *info);
101 extern uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old,
102  key_part_map keypart_map);
103 
104 extern mysql_mutex_t THR_LOCK_heap;
105 
106 #ifdef HAVE_PSI_INTERFACE
107 extern PSI_mutex_key hp_key_mutex_HP_SHARE_intern_lock;
108 void init_heap_psi_keys();
109 #endif /* HAVE_PSI_INTERFACE */
110 
111 C_MODE_END