Commit 5cad5897 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

fix the index_read method. close #449

git-svn-id: file:///svn/mysql/tokudb-engine/src@2444 c7de825b-a66e-492c-adef-691d508d4ae1
parent 65e13739
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#define MYSQL_SERVER 1 #define MYSQL_SERVER 1
#include "mysql_priv.h" #include "mysql_priv.h"
#if !defined(HA_END_SPACE_KEY) || HA_END_SPACE_KEY != 0
#error
#endif
unsigned long my_getphyspages() { unsigned long my_getphyspages() {
return sysconf(_SC_PHYS_PAGES); return sysconf(_SC_PHYS_PAGES);
} }
...@@ -1625,73 +1629,41 @@ int ha_tokudb::index_read(uchar * buf, const uchar * key, uint key_len, enum ha_ ...@@ -1625,73 +1629,41 @@ int ha_tokudb::index_read(uchar * buf, const uchar * key, uint key_len, enum ha_
DBUG_ENTER("ha_tokudb::index_read"); DBUG_ENTER("ha_tokudb::index_read");
DBT row; DBT row;
int error; int error;
KEY *key_info = &table->key_info[active_index];
int do_prev = 0;
table->in_use->status_var.ha_read_key_count++; table->in_use->status_var.ha_read_key_count++;
bzero((void *) &row, sizeof(row)); bzero((void *) &row, sizeof(row));
if (find_flag == HA_READ_BEFORE_KEY) { pack_key(&last_key, active_index, key_buff, key, key_len);
find_flag = HA_READ_KEY_OR_NEXT;
do_prev = 1; switch (find_flag) {
} else if (find_flag == HA_READ_PREFIX_LAST_OR_PREV) { case HA_READ_KEY_EXACT:
find_flag = HA_READ_AFTER_KEY; error = cursor->c_get(cursor, &last_key, &row, DB_SET);
do_prev = 1;
}
if (key_len == key_info->key_length && !(table->key_info[active_index].flags & HA_END_SPACE_KEY)) {
if (find_flag == HA_READ_KEY_EXACT) {
error = cursor->c_get(cursor, pack_key(&last_key, active_index, key_buff, key, key_len), &row, DB_SET);
error = read_row(error, buf, active_index, &row, 0, 0); error = read_row(error, buf, active_index, &row, 0, 0);
} else if (find_flag == HA_READ_AFTER_KEY) { break;
error = cursor->c_get(cursor, pack_key(&last_key, active_index, key_buff, key, key_len), &row, DB_SET_RANGE); case HA_READ_AFTER_KEY:
error = cursor->c_get(cursor, &last_key, &row, DB_SET_RANGE);
if (error == 0) { if (error == 0) {
DBT curkey; memset(&curkey, 0, sizeof curkey); curkey.flags = DB_DBT_REALLOC; DBT orig_key;
DBT curval; memset(&curval, 0, sizeof curval); curval.flags = DB_DBT_REALLOC; pack_key(&orig_key, active_index, key_buff2, key, key_len);
error = cursor->c_get(cursor, &curkey, &curval, DB_CURRENT); if (tokudb_cmp_packed_key(share->key_file[active_index], &orig_key, &last_key) == 0) {
if (error == 0 && tokudb_cmp_packed_key(share->key_file[active_index], &curkey, &last_key) == 0) { error = cursor->c_get(cursor, &last_key, &row, DB_NEXT);
error = cursor->c_get(cursor, &curkey, &row, DB_NEXT);
} }
if (curkey.data) free(curkey.data);
if (curval.data) free(curval.data);
} }
error = read_row(error, buf, active_index, &row, 0, 0); error = read_row(error, buf, active_index, &row, 0, 0);
} else if (find_flag == HA_READ_KEY_OR_NEXT) { break;
error = cursor->c_get(cursor, pack_key(&last_key, active_index, key_buff, key, key_len), &row, DB_SET_RANGE); case HA_READ_KEY_OR_NEXT:
error = cursor->c_get(cursor, &last_key, &row, DB_SET_RANGE);
error = read_row(error, buf, active_index, &row, 0, 0); error = read_row(error, buf, active_index, &row, 0, 0);
} else { break;
assert(0); case HA_READ_BEFORE_KEY:
#if 0 error = cursor->c_get(cursor, &last_key, &row, DB_SET_RANGE);
if (find_flag == HA_READ_AFTER_KEY) { if (error == 0)
assert(0); error = cursor->c_get(cursor, &last_key, &row, DB_PREV);
key_info->handler.bdb_return_if_eq = 1; break;
} default:
error = read_row(cursor->c_get(cursor, pack_key(&last_key, active_index, key_buff, key, key_len), &row, assert(0); // QQQ need BEFORE(k), etc.
(find_flag == HA_READ_KEY_EXACT ? DB_SET : DB_SET_RANGE)), buf, active_index, &row, (DBT *) 0, 0); break;
key_info->handler.bdb_return_if_eq = 0;
#endif
}
} else {
/* read of partial key */
pack_key(&last_key, active_index, key_buff, key, key_len);
/* Store for compare */
memcpy(key_buff2, key_buff, (key_len = last_key.size));
/*
If HA_READ_AFTER_KEY is set, return next key, else return first
matching key.
*/
assert(0);
key_info->handler.bdb_return_if_eq = (find_flag == HA_READ_AFTER_KEY ? 1 : -1);
error = read_row(cursor->c_get(cursor, &last_key, &row, DB_SET_RANGE), buf, active_index, &row, (DBT *) 0, 0);
key_info->handler.bdb_return_if_eq = 0;
if (!error && find_flag == HA_READ_KEY_EXACT) {
/* Ensure that we found a key that is equal to the current one */
if (!error && tokudb_key_cmp(table, key_info, key_buff2, key_len))
error = HA_ERR_KEY_NOT_FOUND;
}
}
if (do_prev) {
bzero((void *) &row, sizeof(row));
error = read_row(cursor->c_get(cursor, &last_key, &row, DB_PREV), buf, active_index, &row, &last_key, 1);
} }
DBUG_RETURN(error); DBUG_RETURN(error);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment