16
16
/* Update an old row in a MyISAM table */
18
#include "myisamdef.h"
19
#include <drizzled/util/test.h>
21
int mi_update(register MI_INFO *info, const unsigned char *oldrec, unsigned char *newrec)
20
int mi_update(register MI_INFO *info, const uchar *oldrec, uchar *newrec)
23
22
int flag,key_changed,save_errno;
24
23
register my_off_t pos;
26
unsigned char old_key[MI_MAX_KEY_BUFF],*new_key;
27
bool auto_key_changed=0;
25
uchar old_key[MI_MAX_KEY_BUFF],*new_key;
26
my_bool auto_key_changed=0;
29
28
MYISAM_SHARE *share= info->s;
30
29
ha_checksum old_checksum= 0;
30
DBUG_ENTER("mi_update");
32
DBUG_EXECUTE_IF("myisam_pretend_crashed_table_on_usage",
33
mi_print_error(info->s, HA_ERR_CRASHED);
34
DBUG_RETURN(my_errno= HA_ERR_CRASHED););
32
35
if (!(info->update & HA_STATE_AKTIV))
34
return(my_errno=HA_ERR_KEY_NOT_FOUND);
37
DBUG_RETURN(my_errno=HA_ERR_KEY_NOT_FOUND);
36
39
if (share->options & HA_OPTION_READ_ONLY_DATA)
38
return(my_errno=EACCES);
41
DBUG_RETURN(my_errno=EACCES);
40
43
if (info->state->key_file_length >= share->base.margin_key_file_length)
42
return(my_errno=HA_ERR_INDEX_FILE_FULL);
45
DBUG_RETURN(my_errno=HA_ERR_INDEX_FILE_FULL);
45
48
if (_mi_readinfo(info,F_WRLCK,1))
49
DBUG_RETURN(my_errno);
48
51
if (share->calc_checksum)
49
52
old_checksum=info->checksum=(*share->calc_checksum)(info,oldrec);
82
85
if (mi_is_key_active(share->state.key_map, i))
85
uint32_t new_length=_mi_make_key(info,i,new_key,newrec,pos);
86
uint32_t old_length=_mi_make_key(info,i,old_key,oldrec,pos);
87
if (share->keyinfo[i].flag & HA_FULLTEXT )
89
if (_mi_ft_cmp(info,i,oldrec, newrec))
91
if ((int) i == info->lastinx)
94
We are changeing the index we are reading on. Mark that
95
the index data has changed and we need to do a full search
98
key_changed|=HA_STATE_WRITTEN;
100
changed|=((ulonglong) 1 << i);
101
if (_mi_ft_update(info,i, old_key,oldrec,newrec,pos))
107
uint new_length=_mi_make_key(info,i,new_key,newrec,pos);
108
uint old_length=_mi_make_key(info,i,old_key,oldrec,pos);
88
110
/* The above changed info->lastkey2. Inform mi_rnext_same(). */
89
111
info->update&= ~HA_STATE_RNEXT_SAME;
91
113
if (new_length != old_length ||
92
memcmp(old_key,new_key,new_length))
114
memcmp((uchar*) old_key,(uchar*) new_key,new_length))
94
116
if ((int) i == info->lastinx)
95
117
key_changed|=HA_STATE_WRITTEN; /* Mark that keyfile changed */
96
changed|=((uint64_t) 1 << i);
118
changed|=((ulonglong) 1 << i);
97
119
share->keyinfo[i].version++;
98
120
if (share->keyinfo[i].ck_delete(info,i,old_key,old_length)) goto err;
99
121
if (share->keyinfo[i].ck_insert(info,i,new_key,new_length)) goto err;
107
129
If we are running with external locking, we must update the index file
108
130
that something has changed.
132
if (changed || !my_disable_locking)
111
133
key_changed|= HA_STATE_CHANGED;
113
135
if (share->calc_checksum)
125
147
ha_rows org_split;
126
148
my_off_t org_delete_link;
128
memcpy(&state, info->state, sizeof(state));
150
memcpy((char*) &state, (char*) info->state, sizeof(state));
129
151
org_split= share->state.split;
130
152
org_delete_link= share->state.dellink;
131
153
if ((*share->update_record)(info,pos,newrec))
133
155
if (!key_changed &&
134
(memcmp(&state, info->state, sizeof(state)) ||
156
(memcmp((char*) &state, (char*) info->state, sizeof(state)) ||
135
157
org_split != share->state.split ||
136
158
org_delete_link != share->state.dellink))
137
159
key_changed|= HA_STATE_CHANGED; /* Must update index file */
145
167
info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED | HA_STATE_AKTIV |
169
myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,0);
148
171
Every myisam function that updates myisam table must end with
149
172
call to _mi_writeinfo(). If operation (second param of
154
177
mi_update() must always pass !0 value as operation, since even if
155
178
there is no index change there could be data change.
157
_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE);
180
VOID(_mi_writeinfo(info, WRITEINFO_UPDATE_KEYFILE));
158
181
if (info->invalidator != 0)
183
DBUG_PRINT("info", ("invalidator... '%s' (update)", info->filename));
160
184
(*info->invalidator)(info->filename);
161
185
info->invalidator=0;
190
DBUG_PRINT("error",("key: %d errno: %d",i,my_errno));
166
191
save_errno=my_errno;
168
193
key_changed|= HA_STATE_CHANGED;
176
if (((uint64_t) 1 << i) & changed)
201
if (((ulonglong) 1 << i) & changed)
179
uint32_t new_length=_mi_make_key(info,i,new_key,newrec,pos);
180
uint32_t old_length= _mi_make_key(info,i,old_key,oldrec,pos);
203
if (share->keyinfo[i].flag & HA_FULLTEXT)
205
if ((flag++ && _mi_ft_del(info,i, new_key,newrec,pos)) ||
206
_mi_ft_add(info,i, old_key,oldrec,pos))
211
uint new_length=_mi_make_key(info,i,new_key,newrec,pos);
212
uint old_length= _mi_make_key(info,i,old_key,oldrec,pos);
181
213
if ((flag++ && _mi_ck_delete(info,i,new_key,new_length)) ||
182
214
_mi_ck_write(info,i,old_key,old_length))
197
_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
229
myisam_log_record(MI_LOG_UPDATE,info,newrec,info->lastpos,my_errno);
230
VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE));
198
231
if (save_errno == HA_ERR_KEY_NOT_FOUND)
200
233
mi_print_error(info->s, HA_ERR_CRASHED);
201
234
save_errno=HA_ERR_CRASHED;
203
return(my_errno=save_errno);
236
DBUG_RETURN(my_errno=save_errno);
204
237
} /* mi_update */