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

addresses #1567

create function that outputs a descriptor for a key

git-svn-id: file:///svn/mysql/tokudb-engine/src@10933 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0919ffff
......@@ -3556,10 +3556,11 @@ THR_LOCK_DATA **ha_tokudb::store_lock(THD * thd, THR_LOCK_DATA ** to, enum thr_l
}
static int create_sub_table(const char *table_name, int flags) {
static int create_sub_table(const char *table_name, int flags , DBT* row_descriptor) {
TOKUDB_DBUG_ENTER("create_sub_table");
int error;
DB *file = NULL;
DBUG_PRINT("enter", ("flags: %d", flags));
error = db_create(&file, db_env, 0);
......@@ -3570,13 +3571,20 @@ static int create_sub_table(const char *table_name, int flags) {
}
file->set_flags(file, flags);
error = file->set_descriptor(file, row_descriptor);
if (error) {
DBUG_PRINT("error", ("Got error: %d when setting row descriptor for table '%s'", error, table_name));
goto exit;
}
error = file->open(file, NULL, table_name, NULL, DB_BTREE, DB_THREAD | DB_CREATE, my_umask);
if (error) {
DBUG_PRINT("error", ("Got error: %d when opening table '%s'", error, table_name));
goto exit;
}
(void) file->close(file, 0);
file->close(file, 0);
error = 0;
exit:
if (error) {
......@@ -3789,7 +3797,7 @@ int ha_tokudb::create(const char *name, TABLE * form, HA_CREATE_INFO * create_in
fn_format(name_buff, newname, "", 0, MY_UNPACK_FILENAME);
/* Create the main table that will hold the real rows */
error = create_sub_table(name_buff, 0);
error = create_sub_table(name_buff, 0, NULL);
if (tokudb_debug & TOKUDB_DEBUG_OPEN) {
TOKUDB_TRACE("create:%s:error=%d\n", newname, error);
}
......@@ -3807,7 +3815,7 @@ int ha_tokudb::create(const char *name, TABLE * form, HA_CREATE_INFO * create_in
sprintf(part, "key-%s", form->s->key_info[i].name);
make_name(newname, name, part);
fn_format(name_buff, newname, "", 0, MY_UNPACK_FILENAME);
error = create_sub_table(name_buff, flags);
error = create_sub_table(name_buff, flags, NULL);
if (tokudb_debug & TOKUDB_DEBUG_OPEN) {
TOKUDB_TRACE("create:%s:flags=%ld:error=%d\n", newname, form->key_info[i].flags, error);
}
......@@ -4353,7 +4361,7 @@ int ha_tokudb::add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys) {
sprintf(part, "key-%s", key_info[i].name);
make_name(newname, share->table_name, part);
fn_format(name_buff, newname, "", 0, MY_UNPACK_FILENAME);
error = create_sub_table(name_buff, flags);
error = create_sub_table(name_buff, flags, NULL);
if (tokudb_debug & TOKUDB_DEBUG_OPEN) {
TOKUDB_TRACE("create:%s:flags=%ld:error=%d\n", newname, key_info[i].flags, error);
}
......
......@@ -1127,3 +1127,89 @@ int tokudb_prefix_cmp_packed_key(DB *file, const DBT *keya, const DBT *keyb) {
return tokudb_compare_two_keys(key, keya->data, keya->size, keyb->data, keyb->size, true);
}
//
// outputs a descriptor for key into buf. num_bytes returns number of bytes used in buf
// to store the descriptor
//
int create_key_descriptor(KEY* key, uchar* buf, u_int32_t* num_bytes) {
int ret_val = 0;
uchar* pos = buf;
u_int32_t num_bytes_in_field = 0;
u_int32_t charset_num = 0;
for (uint i = 0; i < key->key_parts; i++){
Field* field = key->key_part[i].field;
//
// The first byte for each field is the type
//
TOKU_TYPE type = mysql_to_toku_type(field);
assert (type < 256);
*pos = (uchar)(type & 255);
pos++;
//
// based on the type, extra data follows afterwards
// doubles and floats have no extra information
// after it
//
switch (type) {
//
// two bytes follow for ints, first one states how many
// bytes the int is (1 , 2, 3, 4 or 8)
// next one states if it is signed or not
//
case (toku_type_int):
num_bytes_in_field = field->pack_length();
assert (num_bytes_in_field < 256);
*pos = (uchar)(num_bytes_in_field & 255);
pos++;
*pos = (field->flags & UNSIGNED_FLAG) ? 1 : 0;
pos++;
break;
//
// nothing follows floats and doubles
//
case (toku_type_double):
case (toku_type_float):
break;
//
// two bytes follow stating the length of the field
//
case (toku_type_fixbinary):
num_bytes_in_field = field->pack_length();
set_if_smaller(num_bytes_in_field, key->key_part[i].length);
pos[0] = (uchar)(num_bytes_in_field & 255);
pos[1] = (uchar) (num_bytes_in_field >> 8);
pos += 2;
break;
//
// one byte follows: the number of bytes used to encode the length
//
case (toku_type_varbinary):
*pos = (uchar)(get_length_bytes_from_max(key->key_part[i].length) & 255);
pos++;
break;
//
// five bytes follow: one for the number of bytes to encode the length,
// four for the charset number
//
case (toku_type_fixstring):
case (toku_type_varstring):
case (toku_type_blob):
*pos = (uchar)(get_length_bytes_from_max(key->key_part[i].length) & 255);
pos++;
charset_num = field->charset()->number;
pos[0] = (uchar)(charset_num & 255);
pos[1] = (uchar)((charset_num >> 8) & 255);
pos[2] = (uchar)((charset_num >> 16) & 255);
pos[3] = (uchar)((charset_num >> 24) & 255);
pos += 4;
break;
default:
assert(false);
}
}
*num_bytes = pos - buf;
return ret_val;
}
......@@ -121,5 +121,7 @@ int tokudb_cmp_primary_key(DB *file, const DBT *keya, const DBT *keyb);
//TODO: QQQ Only do one direction for prefix.
int tokudb_prefix_cmp_packed_key(DB *file, const DBT *keya, const DBT *keyb);
int create_key_descriptor(KEY* key, uchar* buf, u_int32_t* num_bytes);
#endif
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