1
/* Copyright (C) 2000-2002, 2004 MySQL AB
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* This file is included in all heap-files */
18
#include <my_base.h> /* This includes global */
21
#include <my_pthread.h>
23
#include "heap.h" /* Structs & some defines */
27
When allocating keys /rows in the internal block structure, do it
28
within the following boundaries.
30
The challenge is to find the balance between allocate as few blocks
31
as possible and keep memory consumption down.
34
#define HP_MIN_RECORDS_IN_BLOCK 16
35
#define HP_MAX_RECORDS_IN_BLOCK 8192
37
/* Some extern variables */
39
extern LIST *heap_open_list,*heap_share_list;
41
#define test_active(info) \
42
if (!(info->update & HA_STATE_AKTIV))\
43
{ my_errno=HA_ERR_NO_ACTIVE_RECORD; DBUG_RETURN(-1); }
44
#define hp_find_hash(A,B) ((HASH_INFO*) hp_find_block((A),(B)))
46
/* Find pos for record and update it in info->current_ptr */
47
#define hp_find_record(info,pos) (info)->current_ptr= hp_find_block(&(info)->s->block,pos)
49
typedef struct st_hp_hash_info
51
struct st_hp_hash_info *next_key;
61
/* Prototypes for intern functions */
63
extern HP_SHARE *hp_find_named_heap(const char *name);
64
extern int hp_rectest(HP_INFO *info,const uchar *old);
65
extern uchar *hp_find_block(HP_BLOCK *info,ulong pos);
66
extern int hp_get_new_block(HP_BLOCK *info, size_t* alloc_length);
67
extern void hp_free(HP_SHARE *info);
68
extern uchar *hp_free_level(HP_BLOCK *block,uint level,HP_PTRS *pos,
70
extern int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
71
const uchar *record, uchar *recpos);
72
extern int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
73
const uchar *record, uchar *recpos);
74
extern int hp_rb_delete_key(HP_INFO *info,HP_KEYDEF *keyinfo,
75
const uchar *record,uchar *recpos,int flag);
76
extern int hp_delete_key(HP_INFO *info,HP_KEYDEF *keyinfo,
77
const uchar *record,uchar *recpos,int flag);
78
extern HASH_INFO *_heap_find_hash(HP_BLOCK *block,ulong pos);
79
extern uchar *hp_search(HP_INFO *info,HP_KEYDEF *keyinfo,const uchar *key,
81
extern uchar *hp_search_next(HP_INFO *info, HP_KEYDEF *keyinfo,
82
const uchar *key, HASH_INFO *pos);
83
extern ulong hp_hashnr(HP_KEYDEF *keyinfo,const uchar *key);
84
extern ulong hp_rec_hashnr(HP_KEYDEF *keyinfo,const uchar *rec);
85
extern ulong hp_mask(ulong hashnr,ulong buffmax,ulong maxlength);
86
extern void hp_movelink(HASH_INFO *pos,HASH_INFO *next_link,
88
extern int hp_rec_key_cmp(HP_KEYDEF *keydef,const uchar *rec1,
90
my_bool diff_if_only_endspace_difference);
91
extern int hp_key_cmp(HP_KEYDEF *keydef,const uchar *rec,
93
extern void hp_make_key(HP_KEYDEF *keydef,uchar *key,const uchar *rec);
94
extern uint hp_rb_make_key(HP_KEYDEF *keydef, uchar *key,
95
const uchar *rec, uchar *recpos);
96
extern uint hp_rb_key_length(HP_KEYDEF *keydef, const uchar *key);
97
extern uint hp_rb_null_key_length(HP_KEYDEF *keydef, const uchar *key);
98
extern uint hp_rb_var_key_length(HP_KEYDEF *keydef, const uchar *key);
99
extern my_bool hp_if_null_in_key(HP_KEYDEF *keyinfo, const uchar *record);
100
extern int hp_close(register HP_INFO *info);
101
extern void hp_clear(HP_SHARE *info);
102
extern void hp_clear_keys(HP_SHARE *info);
103
extern uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old,
104
key_part_map keypart_map);
106
extern pthread_mutex_t THR_LOCK_heap;
108
#define pthread_mutex_lock(A)
109
#define pthread_mutex_unlock(A)