Commit 1dc90ab6 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

addresses #1655

move functions around

git-svn-id: file:///svn/mysql/tokudb-engine/src@11076 c7de825b-a66e-492c-adef-691d508d4ae1
parent 4e7886db
...@@ -71,17 +71,36 @@ inline TOKU_TYPE mysql_to_toku_type (Field* field) { ...@@ -71,17 +71,36 @@ inline TOKU_TYPE mysql_to_toku_type (Field* field) {
case MYSQL_TYPE_GEOMETRY: case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_VAR_STRING:
assert(false);
goto exit;
default: default:
ret_val = toku_type_unknown; assert(false);
goto exit;
} }
exit: exit:
return ret_val; return ret_val;
} }
//
// used to read the length of a variable sized field in a tokudb key (buf).
//
inline u_int32_t get_length_from_var_tokudata (uchar* buf, u_int32_t length_bytes) {
u_int32_t length = (u_int32_t)(buf[0]);
if (length_bytes == 2) {
u_int32_t rest_of_length = (u_int32_t)buf[1];
length += rest_of_length<<8;
}
return length;
}
//
// used to deduce the number of bytes used to store the length of a varstring/varbinary
// in a key field stored in tokudb
//
inline u_int32_t get_length_bytes_from_max(u_int32_t max_num_bytes) {
return (max_num_bytes > 255) ? 2 : 1;
}
// //
// assuming MySQL in little endian, and we are storing in little endian // assuming MySQL in little endian, and we are storing in little endian
// //
...@@ -376,26 +395,6 @@ inline int cmp_toku_string( ...@@ -376,26 +395,6 @@ inline int cmp_toku_string(
return ret_val; return ret_val;
} }
//
// used to read the length of a variable sized field in a tokudb key (buf).
//
inline u_int32_t get_length_from_var_tokudata (uchar* buf, u_int32_t length_bytes) {
u_int32_t length = (u_int32_t)(buf[0]);
if (length_bytes == 2) {
u_int32_t rest_of_length = (u_int32_t)buf[1];
length += rest_of_length<<8;
}
return length;
}
//
// used to deduce the number of bytes used to store the length of a varstring/varbinary
// in a key field stored in tokudb
//
inline u_int32_t get_length_bytes_from_max(u_int32_t max_num_bytes) {
return (max_num_bytes > 255) ? 2 : 1;
}
inline uchar* pack_toku_varbinary( inline uchar* pack_toku_varbinary(
uchar* to_tokudb, uchar* to_tokudb,
uchar* from_mysql, uchar* from_mysql,
...@@ -475,46 +474,29 @@ inline uchar* unpack_toku_varbinary( ...@@ -475,46 +474,29 @@ inline uchar* unpack_toku_varbinary(
return from_tokudb + length_bytes_in_tokudb+ length; return from_tokudb + length_bytes_in_tokudb+ length;
} }
inline uchar* unpack_toku_blob( inline int cmp_toku_varbinary(
uchar* to_mysql, uchar* a_buf,
uchar* from_tokudb, uchar* b_buf,
u_int32_t length_bytes_in_tokudb, // number of bytes used to encode length in from_tokudb u_int32_t length_bytes, //number of bytes used to encode length in a_buf and b_buf
u_int32_t length_bytes_in_mysql // number of bytes used to encode length in to_mysql u_int32_t* a_bytes_read,
u_int32_t* b_bytes_read
) )
{ {
u_int32_t length = get_length_from_var_tokudata(from_tokudb, length_bytes_in_tokudb); int ret_val = 0;
uchar* blob_pos = NULL; u_int32_t a_len = get_length_from_var_tokudata(a_buf, length_bytes);
// u_int32_t b_len = get_length_from_var_tokudata(b_buf, length_bytes);
// copy the length into the mysql buffer ret_val = cmp_toku_binary(
// a_buf + length_bytes,
switch (length_bytes_in_mysql) { a_len,
case (0): b_buf + length_bytes,
break; b_len
case (1): );
*to_mysql = (uchar) length; *a_bytes_read = a_len + length_bytes;
break; *b_bytes_read = b_len + length_bytes;
case (2): return ret_val;
int2store(to_mysql, length);
break;
case (3):
int3store(to_mysql, length);
break;
case (4):
int4store(to_mysql, length);
break;
default:
assert(false);
}
//
// copy the binary data
//
blob_pos = from_tokudb + length_bytes_in_tokudb;
memcpy(to_mysql + length_bytes_in_mysql, &blob_pos, sizeof(uchar *));
return from_tokudb + length_bytes_in_tokudb+ length;
} }
inline uchar* pack_toku_blob(
inline uchar* pack_toku_varstring(
uchar* to_tokudb, uchar* to_tokudb,
uchar* from_mysql, uchar* from_mysql,
u_int32_t length_bytes_in_tokudb, //number of bytes to use to encode the length in to_tokudb u_int32_t length_bytes_in_tokudb, //number of bytes to use to encode the length in to_tokudb
...@@ -525,6 +507,7 @@ inline uchar* pack_toku_varstring( ...@@ -525,6 +507,7 @@ inline uchar* pack_toku_varstring(
{ {
u_int32_t length = 0; u_int32_t length = 0;
u_int32_t local_char_length = 0; u_int32_t local_char_length = 0;
uchar* blob_buf = NULL;
switch (length_bytes_in_mysql) { switch (length_bytes_in_mysql) {
case (0): case (0):
...@@ -545,14 +528,16 @@ inline uchar* pack_toku_varstring( ...@@ -545,14 +528,16 @@ inline uchar* pack_toku_varstring(
} }
set_if_smaller(length,max_num_bytes); set_if_smaller(length,max_num_bytes);
memcpy(&blob_buf,from_mysql+length_bytes_in_mysql,sizeof(uchar *));
local_char_length= ((charset->mbmaxlen > 1) ? local_char_length= ((charset->mbmaxlen > 1) ?
max_num_bytes/charset->mbmaxlen : max_num_bytes); max_num_bytes/charset->mbmaxlen : max_num_bytes);
if (length > local_char_length) if (length > local_char_length)
{ {
local_char_length= my_charpos( local_char_length= my_charpos(
charset, charset,
from_mysql+length_bytes_in_mysql, blob_buf,
from_mysql+length_bytes_in_mysql+length, blob_buf+length,
local_char_length local_char_length
); );
set_if_smaller(length, local_char_length); set_if_smaller(length, local_char_length);
...@@ -569,12 +554,51 @@ inline uchar* pack_toku_varstring( ...@@ -569,12 +554,51 @@ inline uchar* pack_toku_varstring(
// //
// copy the string // copy the string
// //
memcpy(to_tokudb + length_bytes_in_tokudb, from_mysql + length_bytes_in_mysql, length); memcpy(to_tokudb + length_bytes_in_tokudb, blob_buf, length);
return to_tokudb + length + length_bytes_in_tokudb; return to_tokudb + length + length_bytes_in_tokudb;
} }
inline uchar* pack_toku_blob( inline uchar* unpack_toku_blob(
uchar* to_mysql,
uchar* from_tokudb,
u_int32_t length_bytes_in_tokudb, // number of bytes used to encode length in from_tokudb
u_int32_t length_bytes_in_mysql // number of bytes used to encode length in to_mysql
)
{
u_int32_t length = get_length_from_var_tokudata(from_tokudb, length_bytes_in_tokudb);
uchar* blob_pos = NULL;
//
// copy the length into the mysql buffer
//
switch (length_bytes_in_mysql) {
case (0):
break;
case (1):
*to_mysql = (uchar) length;
break;
case (2):
int2store(to_mysql, length);
break;
case (3):
int3store(to_mysql, length);
break;
case (4):
int4store(to_mysql, length);
break;
default:
assert(false);
}
//
// copy the binary data
//
blob_pos = from_tokudb + length_bytes_in_tokudb;
memcpy(to_mysql + length_bytes_in_mysql, &blob_pos, sizeof(uchar *));
return from_tokudb + length_bytes_in_tokudb+ length;
}
inline uchar* pack_toku_varstring(
uchar* to_tokudb, uchar* to_tokudb,
uchar* from_mysql, uchar* from_mysql,
u_int32_t length_bytes_in_tokudb, //number of bytes to use to encode the length in to_tokudb u_int32_t length_bytes_in_tokudb, //number of bytes to use to encode the length in to_tokudb
...@@ -585,7 +609,6 @@ inline uchar* pack_toku_blob( ...@@ -585,7 +609,6 @@ inline uchar* pack_toku_blob(
{ {
u_int32_t length = 0; u_int32_t length = 0;
u_int32_t local_char_length = 0; u_int32_t local_char_length = 0;
uchar* blob_buf = NULL;
switch (length_bytes_in_mysql) { switch (length_bytes_in_mysql) {
case (0): case (0):
...@@ -606,16 +629,14 @@ inline uchar* pack_toku_blob( ...@@ -606,16 +629,14 @@ inline uchar* pack_toku_blob(
} }
set_if_smaller(length,max_num_bytes); set_if_smaller(length,max_num_bytes);
memcpy(&blob_buf,from_mysql+length_bytes_in_mysql,sizeof(uchar *));
local_char_length= ((charset->mbmaxlen > 1) ? local_char_length= ((charset->mbmaxlen > 1) ?
max_num_bytes/charset->mbmaxlen : max_num_bytes); max_num_bytes/charset->mbmaxlen : max_num_bytes);
if (length > local_char_length) if (length > local_char_length)
{ {
local_char_length= my_charpos( local_char_length= my_charpos(
charset, charset,
blob_buf, from_mysql+length_bytes_in_mysql,
blob_buf+length, from_mysql+length_bytes_in_mysql+length,
local_char_length local_char_length
); );
set_if_smaller(length, local_char_length); set_if_smaller(length, local_char_length);
...@@ -632,31 +653,10 @@ inline uchar* pack_toku_blob( ...@@ -632,31 +653,10 @@ inline uchar* pack_toku_blob(
// //
// copy the string // copy the string
// //
memcpy(to_tokudb + length_bytes_in_tokudb, blob_buf, length); memcpy(to_tokudb + length_bytes_in_tokudb, from_mysql + length_bytes_in_mysql, length);
return to_tokudb + length + length_bytes_in_tokudb; return to_tokudb + length + length_bytes_in_tokudb;
} }
inline int cmp_toku_varbinary(
uchar* a_buf,
uchar* b_buf,
u_int32_t length_bytes, //number of bytes used to encode length in a_buf and b_buf
u_int32_t* a_bytes_read,
u_int32_t* b_bytes_read
)
{
int ret_val = 0;
u_int32_t a_len = get_length_from_var_tokudata(a_buf, length_bytes);
u_int32_t b_len = get_length_from_var_tokudata(b_buf, length_bytes);
ret_val = cmp_toku_binary(
a_buf + length_bytes,
a_len,
b_buf + length_bytes,
b_len
);
*a_bytes_read = a_len + length_bytes;
*b_bytes_read = b_len + length_bytes;
return ret_val;
}
inline int cmp_toku_varstring( inline int cmp_toku_varstring(
uchar* a_buf, uchar* a_buf,
......
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