20
20
/* Read a record using key */
21
21
/* Ordinary search_flag is 0 ; Give error if no record with key */
23
int mi_rkey(MI_INFO *info, unsigned char *buf, int inx, const unsigned char *key,
23
int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key,
24
24
key_part_map keypart_map, enum ha_rkey_function search_flag)
26
unsigned char *key_buff;
27
27
MYISAM_SHARE *share=info->s;
28
28
MI_KEYDEF *keyinfo;
29
29
HA_KEYSEG *last_used_keyseg;
30
uint32_t pack_key_length, use_key_length, nextflag;
31
uint32_t myisam_search_flag;
30
uint pack_key_length, use_key_length, nextflag;
31
uint myisam_search_flag;
33
DBUG_ENTER("mi_rkey");
34
DBUG_PRINT("enter", ("base: 0x%lx buf: 0x%lx inx: %d search_flag: %d",
35
(long) info, (long) buf, inx, search_flag));
34
37
if ((inx = _mi_check_index(info,inx)) < 0)
38
DBUG_RETURN(my_errno);
37
40
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
38
41
info->last_key_func= search_flag;
48
51
key_buff=info->lastkey+info->s->base.max_key_length;
49
52
pack_key_length= keypart_map;
50
memcpy(key_buff, key, pack_key_length);
53
bmove(key_buff, key, pack_key_length);
51
54
last_used_keyseg= info->s->keyinfo[inx].seg + info->last_used_keyseg;
58
DBUG_ASSERT(keypart_map);
56
59
/* Save the packed key for later use in the second buffer of lastkey. */
57
60
key_buff=info->lastkey+info->s->base.max_key_length;
58
pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (unsigned char*) key,
61
pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (uchar*) key,
59
62
keypart_map, &last_used_keyseg);
60
63
/* Save packed_key_length for use by the MERGE engine. */
61
64
info->pack_key_length= pack_key_length;
62
info->last_used_keyseg= (uint16_t) (last_used_keyseg -
65
info->last_used_keyseg= (uint16) (last_used_keyseg -
63
66
info->s->keyinfo[inx].seg);
67
DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE, keyinfo->seg,
68
key_buff, pack_key_length););
66
71
if (fast_mi_readinfo(info))
104
109
(info->index_cond_func &&
105
110
!(res= mi_check_index_cond(info, inx, buf))))
107
uint32_t not_used[2];
109
114
Skip rows that are inserted by other threads since we got a lock
110
115
Note that this can only happen if we are not searching after an
135
140
info->lastpos= HA_OFFSET_ERROR;
136
141
if (share->concurrent_insert)
137
142
rw_unlock(&share->key_root_lock[inx]);
138
return((my_errno= HA_ERR_KEY_NOT_FOUND));
143
DBUG_RETURN((my_errno= HA_ERR_KEY_NOT_FOUND));
141
146
Error if no row found within the data file. (Bug #29838)
163
168
/* Check if we don't want to have record back, only error message */
165
return(info->lastpos == HA_OFFSET_ERROR ? my_errno : 0);
170
DBUG_RETURN(info->lastpos == HA_OFFSET_ERROR ? my_errno : 0);
167
172
if (!(*info->read_record)(info,info->lastpos,buf))
169
174
info->update|= HA_STATE_AKTIV; /* Record is read */
173
178
info->lastpos = HA_OFFSET_ERROR; /* Didn't find key */
175
180
/* Store last used key as a base for read next */
176
181
memcpy(info->lastkey,key_buff,pack_key_length);
177
182
info->last_rkey_length= pack_key_length;
178
memset(info->lastkey+pack_key_length, 0, info->s->base.rec_reflength);
183
bzero((char*) info->lastkey+pack_key_length,info->s->base.rec_reflength);
179
184
info->lastkey_length=pack_key_length+info->s->base.rec_reflength;
181
186
if (search_flag == HA_READ_AFTER_KEY)
182
187
info->update|=HA_STATE_NEXT_FOUND; /* Previous gives last row */
189
DBUG_RETURN(my_errno);