12
12
You should have received a copy of the GNU General Public License
13
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 */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
16
/* Write a record to heap-databas */
35
33
HP_KEYDEF *keydef, *end;
36
34
unsigned char *pos;
37
HP_SHARE *share=info->getShare();
35
HP_SHARE *share=info->s;
36
uint32_t rec_length, chunk_count;
39
38
if ((share->records >= share->max_records && share->max_records) ||
40
39
(share->recordspace.total_data_length + share->index_length >= share->max_table_size))
42
return(errno=HA_ERR_RECORD_FILE_FULL);
41
return(my_errno=HA_ERR_RECORD_FILE_FULL);
45
if (!(pos=hp_allocate_chunkset(&share->recordspace, 1)))
44
rec_length = hp_get_encoded_data_length(share, record, &chunk_count);
46
if (!(pos=hp_allocate_chunkset(&share->recordspace, chunk_count)))
49
50
for (keydef = share->keydef, end = keydef + share->keys; keydef < end;
52
if (hp_write_key(info, keydef, record, pos))
53
if ((*keydef->write_key)(info, keydef, record, pos))
69
70
info->errkey= keydef - share->keydef;
72
We don't need to delete non-inserted key from rb-tree. Also, if
73
we got ENOMEM, the key wasn't inserted, so don't try to delete it
74
either. Otherwise for HASH index on HA_ERR_FOUND_DUPP_KEY the key
75
was inserted and we have to delete it.
77
if (keydef->algorithm == HA_KEY_ALG_BTREE || my_errno == ENOMEM)
70
81
while (keydef >= share->keydef)
72
if (hp_delete_key(info, keydef, record, pos, 0))
83
if ((*keydef->delete_key)(info, keydef, record, pos, 0))
77
88
hp_free_chunks(&share->recordspace, pos);
94
Write a key to rb_tree-index
97
int hp_rb_write_key(HP_INFO *info, HP_KEYDEF *keyinfo, const unsigned char *record,
98
unsigned char *recpos)
100
heap_rb_param custom_arg;
101
uint32_t old_allocated;
103
custom_arg.keyseg= keyinfo->seg;
104
custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos);
105
if (keyinfo->flag & HA_NOSAME)
107
custom_arg.search_flag= SEARCH_FIND | SEARCH_UPDATE;
108
keyinfo->rb_tree.flag= TREE_NO_DUPS;
112
custom_arg.search_flag= SEARCH_SAME;
113
keyinfo->rb_tree.flag= 0;
115
old_allocated= keyinfo->rb_tree.allocated;
116
if (!tree_insert(&keyinfo->rb_tree, (void*)info->recbuf,
117
custom_arg.key_length, &custom_arg))
119
my_errno= HA_ERR_FOUND_DUPP_KEY;
122
info->s->index_length+= (keyinfo->rb_tree.allocated-old_allocated);
83
127
Write a hash-key to the hash-index
85
129
info Heap table info
107
151
int hp_write_key(HP_INFO *info, HP_KEYDEF *keyinfo,
108
152
const unsigned char *record, unsigned char *recpos)
110
HP_SHARE *share = info->getShare();
154
HP_SHARE *share = info->s;
112
156
uint32_t halfbuff,hashnr,first_index;
113
157
unsigned char *ptr_to_rec= NULL,*ptr_to_rec2= NULL;
287
331
if (! hp_rec_key_cmp(keyinfo, record, pos->ptr_to_rec, 1))
289
return(errno=HA_ERR_FOUND_DUPP_KEY);
333
return(my_errno=HA_ERR_FOUND_DUPP_KEY);
291
335
} while ((pos=pos->next_key));