summaryrefslogtreecommitdiff
path: root/myisam/mi_rkey.c
diff options
context:
space:
mode:
Diffstat (limited to 'myisam/mi_rkey.c')
-rw-r--r--myisam/mi_rkey.c63
1 files changed, 39 insertions, 24 deletions
diff --git a/myisam/mi_rkey.c b/myisam/mi_rkey.c
index 1bb478efd3d..12db00337ee 100644
--- a/myisam/mi_rkey.c
+++ b/myisam/mi_rkey.c
@@ -17,7 +17,7 @@
/* Read record based on a key */
#include "myisamdef.h"
-
+#include "rt_index.h"
/* Read a record using key */
/* Ordinary search_flag is 0 ; Give error if no record with key */
@@ -28,7 +28,7 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len,
uchar *key_buff;
MYISAM_SHARE *share=info->s;
MI_KEYDEF *keyinfo;
- MI_KEYSEG *last_used_keyseg;
+ HA_KEYSEG *last_used_keyseg;
uint pack_key_length, use_key_length, nextflag;
DBUG_ENTER("mi_rkey");
DBUG_PRINT("enter",("base: %lx inx: %d search_flag: %d",
@@ -38,20 +38,12 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len,
DBUG_RETURN(my_errno);
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
+ info->last_key_func= search_flag;
keyinfo= share->keyinfo + inx;
- if (!info->use_packed_key)
- {
- if (key_len == 0)
- key_len=USE_WHOLE_KEY;
- key_buff=info->lastkey+info->s->base.max_key_length;
- pack_key_length=_mi_pack_key(info, (uint) inx, key_buff, (uchar*) key,
- key_len, &last_used_keyseg);
- DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE, keyinfo->seg,
- key_buff, pack_key_length););
- }
- else
+ if (info->once_flags & USE_PACKED_KEYS)
{
+ info->once_flags&= ~USE_PACKED_KEYS; /* Reset flag */
/*
key is already packed!; This happens when we are using a MERGE TABLE
*/
@@ -60,6 +52,16 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len,
bmove(key_buff,key,key_len);
last_used_keyseg= 0;
}
+ else
+ {
+ if (key_len == 0)
+ key_len=USE_WHOLE_KEY;
+ key_buff=info->lastkey+info->s->base.max_key_length;
+ pack_key_length=_mi_pack_key(info,(uint) inx, key_buff, (uchar*) key,
+ key_len, &last_used_keyseg);
+ DBUG_EXECUTE("key",_mi_print_key(DBUG_FILE, keyinfo->seg,
+ key_buff, pack_key_length););
+ }
if (fast_mi_readinfo(info))
goto err;
@@ -71,22 +73,35 @@ int mi_rkey(MI_INFO *info, byte *buf, int inx, const byte *key, uint key_len,
if (!(nextflag & (SEARCH_FIND | SEARCH_NO_FIND | SEARCH_LAST)))
use_key_length=USE_WHOLE_KEY;
- if (!_mi_search(info,keyinfo, key_buff, use_key_length,
+ switch (info->s->keyinfo[inx].key_alg) {
+#ifdef HAVE_RTREE_KEYS
+ case HA_KEY_ALG_RTREE:
+ if (rtree_find_first(info,inx,key_buff,use_key_length,nextflag) < 0)
+ {
+ my_errno=HA_ERR_CRASHED;
+ goto err;
+ }
+ break;
+#endif
+ case HA_KEY_ALG_BTREE:
+ default:
+ if (!_mi_search(info, keyinfo, key_buff, use_key_length,
myisam_read_vec[search_flag], info->s->state.key_root[inx]))
- {
- while (info->lastpos >= info->state->data_file_length)
{
- /*
- Skip rows that are inserted by other threads since we got a lock
- Note that this can only happen if we are not searching after an
- exact key, because the keys are sorted according to position
- */
-
- if (_mi_search_next(info, keyinfo, info->lastkey,
+ while (info->lastpos >= info->state->data_file_length)
+ {
+ /*
+ Skip rows that are inserted by other threads since we got a lock
+ Note that this can only happen if we are not searching after an
+ exact key, because the keys are sorted according to position
+ */
+
+ if (_mi_search_next(info, keyinfo, info->lastkey,
info->lastkey_length,
myisam_readnext_vec[search_flag],
info->s->state.key_root[inx]))
- break;
+ break;
+ }
}
}
if (share->concurrent_insert)