1
/* Copyright (C) 2000-2002, 2004-2005 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
/* Update current record in heap-database */
20
int heap_update(HP_INFO *info, const uchar *old, const uchar *heap_new)
22
HP_KEYDEF *keydef, *end, *p_lastinx;
24
my_bool auto_key_changed= 0;
25
HP_SHARE *share= info->s;
26
DBUG_ENTER("heap_update");
29
pos=info->current_ptr;
31
if (info->opt_flag & READ_CHECK_USED && hp_rectest(info,old))
32
DBUG_RETURN(my_errno); /* Record changed */
33
if (--(share->records) < share->blength >> 1) share->blength>>= 1;
36
p_lastinx= share->keydef + info->lastinx;
37
for (keydef= share->keydef, end= keydef + share->keys; keydef < end; keydef++)
39
if (hp_rec_key_cmp(keydef, old, heap_new, 0))
41
if ((*keydef->delete_key)(info, keydef, old, pos, keydef == p_lastinx) ||
42
(*keydef->write_key)(info, keydef, heap_new, pos))
44
if (share->auto_key == (uint) (keydef - share->keydef + 1))
49
memcpy(pos,heap_new,(size_t) share->reclength);
50
if (++(share->records) == share->blength) share->blength+= share->blength;
52
#if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG)
53
DBUG_EXECUTE("check_heap",heap_check_heap(info, 0););
56
heap_update_auto_increment(info, heap_new);
60
if (my_errno == HA_ERR_FOUND_DUPP_KEY)
62
info->errkey = (int) (keydef - share->keydef);
63
if (keydef->algorithm == HA_KEY_ALG_BTREE)
65
/* we don't need to delete non-inserted key from rb-tree */
66
if ((*keydef->write_key)(info, keydef, old, pos))
68
if (++(share->records) == share->blength)
69
share->blength+= share->blength;
70
DBUG_RETURN(my_errno);
74
while (keydef >= share->keydef)
76
if (hp_rec_key_cmp(keydef, old, heap_new, 0))
78
if ((*keydef->delete_key)(info, keydef, heap_new, pos, 0) ||
79
(*keydef->write_key)(info, keydef, old, pos))
85
if (++(share->records) == share->blength)
86
share->blength+= share->blength;
87
DBUG_RETURN(my_errno);