Commit b2f6d428 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:1930], remove heaviside functions

git-svn-id: file:///svn/mysql/tokudb-engine/src@14088 c7de825b-a66e-492c-adef-691d508d4ae1
parent d960329e
...@@ -391,29 +391,6 @@ smart_dbt_callback_rowread(DBT const *key, DBT const *row, void *context) { ...@@ -391,29 +391,6 @@ smart_dbt_callback_rowread(DBT const *key, DBT const *row, void *context) {
return error; return error;
} }
//
// Smart DBT callback function in c_getf_heaviside, in case where we have a covering index,
//
static int
smart_dbt_callback_keyread_heavi(DBT const *key, DBT const *row, void *context, int r_h) {
SMART_DBT_INFO info = (SMART_DBT_INFO)context;
info->ha->heavi_ret_val = r_h;
smart_dbt_callback_keyread(key,row,context);
return 0;
}
//
// Smart DBT callback function in c_getf_heaviside, in case where we do NOT have a covering index
//
static int
smart_dbt_callback_rowread_heavi(DBT const *key, DBT const *row, void *context, int r_h) {
SMART_DBT_INFO info = (SMART_DBT_INFO)context;
info->ha->heavi_ret_val = r_h;
smart_dbt_callback_rowread(key,row,context);
return 0;
}
// //
// macro for Smart DBT callback function, // macro for Smart DBT callback function,
// so we do not need to put this long line of code in multiple places // so we do not need to put this long line of code in multiple places
...@@ -3351,105 +3328,6 @@ int ha_tokudb::read_full_row(uchar * buf) { ...@@ -3351,105 +3328,6 @@ int ha_tokudb::read_full_row(uchar * buf) {
} }
//
// context information for the heaviside functions.
// Context information includes data necessary
// to perform comparisons
//
typedef struct heavi_info {
DB *db;
const DBT *key;
} *HEAVI_INFO;
//
// effect:
// heaviside function used for HA_READ_AFTER_KEY.
// to use this heaviside function in ha_read_after_key, use direction>0
// the stored key (in heavi_info) contains a prefix of the columns in the candidate
// keys. only the columns in the stored key will be used for comparison.
//
// parameters:
// [in] key - candidate key in db that is being compared
// [in] value - candidate value, unused
// [in] extra_h - a heavi_info that contains information necessary for
// the comparison
// returns:
// >0 : candidate key > stored key
// <0 : otherwise
// examples:
// columns: (a,b,c,d)
// stored key = (3,4) (only a,b)
// candidate keys have (a,b,c,d)
// (3,2,1,1) < (3,4)
// (3,4,1,1) == (3,4)
// (3,5,1,1) > (3,4)
//
static int after_key_heavi(const DBT *key, const DBT *value, void *extra_h) {
HEAVI_INFO info = (HEAVI_INFO)extra_h;
int cmp = tokudb_prefix_cmp_dbt_key(info->db, key, info->key);
return cmp>0 ? 1 : -1;
}
//
// effect:
// heaviside function used for HA_READ_PREFIX_LAST_OR_PREV.
// to use this heaviside function in HA_READ_PREFIX_LAST_OR_PREV, use direction<0
// the stored key (in heavi_info) contains a prefix of the columns in the candidate
// keys. only the columns in the stored key will be used for comparison.
//
// parameters:
// [in] key - candidate key in db that is being compared
// [in] value - candidate value, unused
// [in] extra_h - a heavi_info that contains information necessary for
// the comparison
// returns:
// >0 : candidate key > stored key
// 0 : candidate key == stored key
// <0 : candidate key < stored key
// examples:
// columns: (a,b,c,d)
// stored key = (3,4) (only a,b)
// candidate keys have (a,b,c,d)
// (3,2,1,1) < (3,4)
// (3,4,1,1) == (3,4)
// (3,5,1,1) > (3,4)
//
static int prefix_last_or_prev_heavi(const DBT *key, const DBT *value, void *extra_h) {
HEAVI_INFO info = (HEAVI_INFO)extra_h;
int cmp = tokudb_prefix_cmp_dbt_key(info->db, key, info->key);
return cmp;
}
//
// effect:
// heaviside function used for HA_READ_BEFORE_KEY.
// to use this heaviside function in HA_READ_BEFORE_KEY, use direction<0
// the stored key (in heavi_info) contains a prefix of the columns in the candidate
// keys. only the columns in the stored key will be used for comparison.
//
// parameters:
// [in] key - candidate key in db that is being compared
// [in] value - candidate value, unused
// [in] extra_h - a heavi_info that contains information necessary for
// the comparison
// returns:
// <0 : candidate key < stored key
// >0 : otherwise
// examples:
// columns: (a,b,c,d)
// stored key = (3,4) (only a,b)
// candidate keys have (a,b,c,d)
// (3,2,1,1) < (3,4)
// (3,4,1,1) == (3,4)
// (3,5,1,1) > (3,4)
//
static int before_key_heavi(const DBT *key, const DBT *value, void *extra_h) {
HEAVI_INFO info = (HEAVI_INFO)extra_h;
int cmp = tokudb_prefix_cmp_dbt_key(info->db, key, info->key);
return (cmp<0) ? -1 : 1;
}
// //
// Reads the next row matching to the key, on success, advances cursor // Reads the next row matching to the key, on success, advances cursor
// Parameters: // Parameters:
...@@ -3525,60 +3403,55 @@ int ha_tokudb::index_read(uchar * buf, const uchar * key, uint key_len, enum ha_ ...@@ -3525,60 +3403,55 @@ int ha_tokudb::index_read(uchar * buf, const uchar * key, uint key_len, enum ha_
TOKUDB_DBUG_ENTER("ha_tokudb::index_read %p find %d", this, find_flag); TOKUDB_DBUG_ENTER("ha_tokudb::index_read %p find %d", this, find_flag);
// TOKUDB_DBUG_DUMP("key=", key, key_len); // TOKUDB_DBUG_DUMP("key=", key, key_len);
DBT row; DBT row;
DBT lookup_key;
int error; int error;
u_int32_t flags = 0; u_int32_t flags = 0;
struct smart_dbt_info info; struct smart_dbt_info info;
struct heavi_info heavi_info;
HANDLE_INVALID_CURSOR(); HANDLE_INVALID_CURSOR();
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));
pack_key(&last_key, active_index, key_buff, key, key_len, COL_NEG_INF);
info.ha = this; info.ha = this;
info.buf = buf; info.buf = buf;
info.keynr = active_index; info.keynr = active_index;
heavi_info.db = share->key_file[active_index];
heavi_info.key = &last_key;
flags = SET_READ_FLAG(0); flags = SET_READ_FLAG(0);
switch (find_flag) { switch (find_flag) {
case HA_READ_KEY_EXACT: /* Find first record else error */ case HA_READ_KEY_EXACT: /* Find first record else error */
error = cursor->c_getf_set_range(cursor, flags, &last_key, SMART_DBT_CALLBACK, &info); pack_key(&lookup_key, active_index, key_buff3, key, key_len, COL_NEG_INF);
error = cursor->c_getf_set_range(cursor, flags, &lookup_key, SMART_DBT_CALLBACK, &info);
if (error == 0) { if (error == 0) {
DBT orig_key; DBT orig_key;
pack_key(&orig_key, active_index, key_buff2, key, key_len, COL_NEG_INF); pack_key(&orig_key, active_index, key_buff2, key, key_len, COL_NEG_INF);
if (tokudb_prefix_cmp_dbt_key(share->key_file[active_index], &orig_key, &last_key)) { if (tokudb_prefix_cmp_dbt_key(share->key_file[active_index], &orig_key, &lookup_key)) {
error = DB_NOTFOUND; error = DB_NOTFOUND;
} }
} }
break; break;
case HA_READ_AFTER_KEY: /* Find next rec. after key-record */ case HA_READ_AFTER_KEY: /* Find next rec. after key-record */
error = cursor->c_getf_heaviside( pack_key(&lookup_key, active_index, key_buff3, key, key_len, COL_POS_INF);
cursor, flags, error = cursor->c_getf_set_range(cursor, flags, &lookup_key, SMART_DBT_CALLBACK, &info);
key_read ? smart_dbt_callback_keyread_heavi : smart_dbt_callback_rowread_heavi, &info,
after_key_heavi, &heavi_info,
1
);
break; break;
case HA_READ_BEFORE_KEY: /* Find next rec. before key-record */ case HA_READ_BEFORE_KEY: /* Find next rec. before key-record */
error = cursor->c_getf_heaviside( pack_key(&lookup_key, active_index, key_buff3, key, key_len, COL_NEG_INF);
cursor, flags, error = cursor->c_getf_set_range_reverse(cursor, flags, &lookup_key, SMART_DBT_CALLBACK, &info);
key_read ? smart_dbt_callback_keyread_heavi : smart_dbt_callback_rowread_heavi, &info,
before_key_heavi, &heavi_info,
-1
);
break; break;
case HA_READ_KEY_OR_NEXT: /* Record or next record */ case HA_READ_KEY_OR_NEXT: /* Record or next record */
error = cursor->c_getf_set_range(cursor, flags, &last_key, SMART_DBT_CALLBACK, &info); pack_key(&lookup_key, active_index, key_buff3, key, key_len, COL_NEG_INF);
error = cursor->c_getf_set_range(cursor, flags, &lookup_key, SMART_DBT_CALLBACK, &info);
break; break;
//
// This case does not seem to ever be used, it is ok for it to be slow
//
case HA_READ_KEY_OR_PREV: /* Record or previous */ case HA_READ_KEY_OR_PREV: /* Record or previous */
error = cursor->c_getf_set_range(cursor, flags, &last_key, SMART_DBT_CALLBACK, &info); pack_key(&lookup_key, active_index, key_buff3, key, key_len, COL_NEG_INF);
error = cursor->c_getf_set_range(cursor, flags, &lookup_key, SMART_DBT_CALLBACK, &info);
if (error == 0) { if (error == 0) {
DBT orig_key; DBT orig_key;
pack_key(&orig_key, active_index, key_buff2, key, key_len, COL_NEG_INF); pack_key(&orig_key, active_index, key_buff2, key, key_len, COL_NEG_INF);
if (tokudb_prefix_cmp_dbt_key(share->key_file[active_index], &orig_key, &last_key) != 0) { if (tokudb_prefix_cmp_dbt_key(share->key_file[active_index], &orig_key, &lookup_key) != 0) {
error = cursor->c_getf_prev(cursor, flags, SMART_DBT_CALLBACK, &info); error = cursor->c_getf_prev(cursor, flags, SMART_DBT_CALLBACK, &info);
} }
} }
...@@ -3587,22 +3460,18 @@ int ha_tokudb::index_read(uchar * buf, const uchar * key, uint key_len, enum ha_ ...@@ -3587,22 +3460,18 @@ int ha_tokudb::index_read(uchar * buf, const uchar * key, uint key_len, enum ha_
} }
break; break;
case HA_READ_PREFIX_LAST_OR_PREV: /* Last or prev key with the same prefix */ case HA_READ_PREFIX_LAST_OR_PREV: /* Last or prev key with the same prefix */
error = cursor->c_getf_heaviside( pack_key(&lookup_key, active_index, key_buff3, key, key_len, COL_POS_INF);
cursor, flags, error = cursor->c_getf_set_range_reverse(cursor, flags, &lookup_key, SMART_DBT_CALLBACK, &info);
key_read ? smart_dbt_callback_keyread_heavi : smart_dbt_callback_rowread_heavi, &info,
prefix_last_or_prev_heavi, &heavi_info,
-1
);
break; break;
case HA_READ_PREFIX_LAST: case HA_READ_PREFIX_LAST:
error = cursor->c_getf_heaviside( pack_key(&lookup_key, active_index, key_buff3, key, key_len, COL_POS_INF);
cursor, flags, error = cursor->c_getf_set_range_reverse(cursor, flags, &lookup_key, SMART_DBT_CALLBACK, &info);
key_read ? smart_dbt_callback_keyread_heavi : smart_dbt_callback_rowread_heavi, &info, if (error == 0) {
prefix_last_or_prev_heavi, &heavi_info, DBT orig_key;
-1 pack_key(&orig_key, active_index, key_buff2, key, key_len, COL_NEG_INF);
); if (tokudb_prefix_cmp_dbt_key(share->key_file[active_index], &orig_key, &lookup_key)) {
if (!error && heavi_ret_val != 0) { error = DB_NOTFOUND;
error = DB_NOTFOUND; }
} }
break; break;
default: default:
......
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