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
/* Read record based on a key */
18
#include "myisam_priv.h"
20
using namespace drizzled;
18
#include "myisamdef.h"
22
20
/* Read a record using key */
23
21
/* Ordinary search_flag is 0 ; Give error if no record with key */
25
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,
26
24
key_part_map keypart_map, enum ha_rkey_function search_flag)
28
unsigned char *key_buff;
29
27
MYISAM_SHARE *share=info->s;
30
28
MI_KEYDEF *keyinfo;
31
29
HA_KEYSEG *last_used_keyseg;
32
uint32_t pack_key_length, use_key_length, nextflag;
33
uint32_t myisam_search_flag;
30
uint pack_key_length, use_key_length, nextflag;
31
uint myisam_search_flag;
36
34
if ((inx = _mi_check_index(info,inx)) < 0)
39
37
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
40
38
info->last_key_func= search_flag;
50
48
key_buff=info->lastkey+info->s->base.max_key_length;
51
49
pack_key_length= keypart_map;
52
memmove(key_buff, key, pack_key_length);
50
memcpy(key_buff, key, pack_key_length);
53
51
last_used_keyseg= info->s->keyinfo[inx].seg + info->last_used_keyseg;
57
55
assert(keypart_map);
58
56
/* Save the packed key for later use in the second buffer of lastkey. */
59
57
key_buff=info->lastkey+info->s->base.max_key_length;
60
pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (unsigned char*) key,
58
pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (uchar*) key,
61
59
keypart_map, &last_used_keyseg);
62
60
/* Save packed_key_length for use by the MERGE engine. */
63
61
info->pack_key_length= pack_key_length;
68
66
if (fast_mi_readinfo(info))
69
if (share->concurrent_insert)
70
rw_rdlock(&share->key_root_lock[inx]);
71
72
nextflag=myisam_read_vec[search_flag];
72
73
use_key_length=pack_key_length;
73
74
if (!(nextflag & (SEARCH_FIND | SEARCH_NO_FIND | SEARCH_LAST)))
100
101
while ((info->lastpos >= info->state->data_file_length &&
101
102
(search_flag != HA_READ_KEY_EXACT ||
102
103
last_used_keyseg != keyinfo->seg + keyinfo->keysegs)) ||
103
(info->index_cond_func &&
104
(info->index_cond_func &&
104
105
!(res= mi_check_index_cond(info, inx, buf))))
106
uint32_t not_used[2];
108
109
Skip rows that are inserted by other threads since we got a lock
109
110
Note that this can only happen if we are not searching after an
124
125
ha_key_cmp(keyinfo->seg, key_buff, info->lastkey, use_key_length,
125
126
SEARCH_FIND, not_used))
127
errno= HA_ERR_KEY_NOT_FOUND;
128
my_errno= HA_ERR_KEY_NOT_FOUND;
128
129
info->lastpos= HA_OFFSET_ERROR;
134
135
info->lastpos= HA_OFFSET_ERROR;
135
return((errno= HA_ERR_KEY_NOT_FOUND));
136
if (share->concurrent_insert)
137
rw_unlock(&share->key_root_lock[inx]);
138
return((my_errno= HA_ERR_KEY_NOT_FOUND));
138
141
Error if no row found within the data file. (Bug #29838)
139
Do not overwrite errno if already at HA_OFFSET_ERROR.
142
Do not overwrite my_errno if already at HA_OFFSET_ERROR.
141
144
if (info->lastpos != HA_OFFSET_ERROR &&
142
145
info->lastpos >= info->state->data_file_length)
144
147
info->lastpos= HA_OFFSET_ERROR;
145
errno= HA_ERR_KEY_NOT_FOUND;
148
my_errno= HA_ERR_KEY_NOT_FOUND;
152
if (share->concurrent_insert)
153
rw_unlock(&share->key_root_lock[inx]);
150
155
/* Calculate length of the found key; Used by mi_rnext_same */
151
156
if ((keyinfo->flag & HA_VAR_LENGTH_KEY) && last_used_keyseg &&
158
163
/* Check if we don't want to have record back, only error message */
160
return(info->lastpos == HA_OFFSET_ERROR ? errno : 0);
165
return(info->lastpos == HA_OFFSET_ERROR ? my_errno : 0);
162
167
if (!(*info->read_record)(info,info->lastpos,buf))
170
175
/* Store last used key as a base for read next */
171
176
memcpy(info->lastkey,key_buff,pack_key_length);
172
177
info->last_rkey_length= pack_key_length;
173
memset(info->lastkey+pack_key_length, 0, info->s->base.rec_reflength);
178
memset((char*) info->lastkey+pack_key_length, 0, info->s->base.rec_reflength);
174
179
info->lastkey_length=pack_key_length+info->s->base.rec_reflength;
176
181
if (search_flag == HA_READ_AFTER_KEY)
177
182
info->update|=HA_STATE_NEXT_FOUND; /* Previous gives last row */