18
18
#include "heapdef.h"
20
int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new)
20
int heap_update(HP_INFO *info, const uchar *old_record, const uchar *new_record)
22
22
HP_KEYDEF *keydef, *end, *p_lastinx;
24
24
my_bool auto_key_changed= 0;
25
25
HP_SHARE *share= info->s;
26
uint old_length, new_length;
27
uint old_chunk_count, new_chunk_count;
28
30
pos=info->current_ptr;
30
if (info->opt_flag & READ_CHECK_USED)
32
if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old_record))
31
33
return(my_errno); /* Record changed */
35
old_length = hp_get_encoded_data_length(share, old_record, &old_chunk_count);
36
new_length = hp_get_encoded_data_length(share, new_record, &new_chunk_count);
38
if (new_chunk_count > old_chunk_count) {
39
/* extend the old chunkset size as necessary, but do not shrink yet */
40
if (hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos)) {
41
return(my_errno); /* Out of memory or table space */
32
45
if (--(share->records) < share->blength >> 1) share->blength>>= 1;
35
48
p_lastinx= share->keydef + info->lastinx;
36
49
for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
38
if (hp_rec_key_cmp(keydef, old, heap_new, 0))
51
if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
40
if ((*keydef->delete_key)(info, keydef, old, pos, keydef == p_lastinx) ||
41
(*keydef->write_key)(info, keydef, heap_new, pos))
53
if ((*keydef->delete_key)(info, keydef, old_record, pos, keydef == p_lastinx) ||
54
(*keydef->write_key)(info, keydef, new_record, pos))
43
56
if (share->auto_key == (uint) (keydef - share->keydef + 1))
44
57
auto_key_changed= 1;
48
memcpy(pos,heap_new,(size_t) share->reclength);
60
hp_copy_record_data_to_chunkset(share, new_record, pos);
49
61
if (++(share->records) == share->blength) share->blength+= share->blength;
63
if (new_chunk_count < old_chunk_count) {
64
/* Shrink the chunkset to its new size */
65
hp_reallocate_chunkset(&share->recordspace, new_chunk_count, pos);
51
68
if (auto_key_changed)
52
heap_update_auto_increment(info, heap_new);
69
heap_update_auto_increment(info, new_record);
59
76
if (keydef->algorithm == HA_KEY_ALG_BTREE)
61
78
/* we don't need to delete non-inserted key from rb-tree */
62
if ((*keydef->write_key)(info, keydef, old, pos))
79
if ((*keydef->write_key)(info, keydef, old_record, pos))
64
81
if (++(share->records) == share->blength)
65
82
share->blength+= share->blength;
70
87
while (keydef >= share->keydef)
72
if (hp_rec_key_cmp(keydef, old, heap_new, 0))
89
if (hp_rec_key_cmp(keydef, old_record, new_record, 0))
74
if ((*keydef->delete_key)(info, keydef, heap_new, pos, 0) ||
75
(*keydef->write_key)(info, keydef, old, pos))
91
if ((*keydef->delete_key)(info, keydef, new_record, pos, 0) ||
92
(*keydef->write_key)(info, keydef, old_record, pos))
81
99
if (++(share->records) == share->blength)
82
100
share->blength+= share->blength;
102
if (new_chunk_count > old_chunk_count) {
103
/* Shrink the chunkset to its original size */
104
hp_reallocate_chunkset(&share->recordspace, old_chunk_count, pos);
84
108
} /* heap_update */