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

addresses #1163

change retrieve_auto_increment to be different than MyISAM's function

git-svn-id: file:///svn/mysql/tokudb-engine/src@6208 c7de825b-a66e-492c-adef-691d508d4ae1
parent da37b82a
...@@ -1029,69 +1029,89 @@ static void smart_dbt_callback_ror_heavi(DBT const *key, DBT const *row, void * ...@@ -1029,69 +1029,89 @@ static void smart_dbt_callback_ror_heavi(DBT const *key, DBT const *row, void *
// //
ulonglong retrieve_auto_increment(uint16 type, uint32 offset,const uchar *record) ulonglong retrieve_auto_increment(uint16 type, uint32 offset,const uchar *record)
{ {
ulonglong value= 0; /* Store unsigned values here */ const uchar *key; /* Key */
longlong s_value= 0; /* Store signed values here */ ulonglong unsigned_autoinc; /* Unsigned auto-increment */
const uchar *key= (uchar*) record + offset; longlong signed_autoinc; /* Signed auto-increment */
enum { unsigned_type, signed_type } autoinc_type;
float float_tmp; /* Temporary variable */
double double_tmp; /* Temporary variable */
key = ((uchar *) record) + offset;
/* Set default autoincrement type */
autoinc_type = unsigned_type;
switch (type) { switch (type) {
case HA_KEYTYPE_INT8: case HA_KEYTYPE_INT8:
s_value= (longlong) *(char*)key; signed_autoinc = (longlong) *(char*)key;
autoinc_type = signed_type;
break; break;
case HA_KEYTYPE_BINARY: case HA_KEYTYPE_BINARY:
value=(ulonglong) *(uchar*) key; unsigned_autoinc = (ulonglong) *(uchar*) key;
break; break;
case HA_KEYTYPE_SHORT_INT: case HA_KEYTYPE_SHORT_INT:
s_value= (longlong) sint2korr(key); signed_autoinc = (longlong) sint2korr(key);
autoinc_type = signed_type;
break; break;
case HA_KEYTYPE_USHORT_INT: case HA_KEYTYPE_USHORT_INT:
value=(ulonglong) uint2korr(key); unsigned_autoinc = (ulonglong) uint2korr(key);
break; break;
case HA_KEYTYPE_LONG_INT: case HA_KEYTYPE_LONG_INT:
s_value= (longlong) sint4korr(key); signed_autoinc = (longlong) sint4korr(key);
autoinc_type = signed_type;
break; break;
case HA_KEYTYPE_ULONG_INT: case HA_KEYTYPE_ULONG_INT:
value=(ulonglong) uint4korr(key); unsigned_autoinc = (ulonglong) uint4korr(key);
break; break;
case HA_KEYTYPE_INT24: case HA_KEYTYPE_INT24:
s_value= (longlong) sint3korr(key); signed_autoinc = (longlong) sint3korr(key);
autoinc_type = signed_type;
break; break;
case HA_KEYTYPE_UINT24: case HA_KEYTYPE_UINT24:
value=(ulonglong) uint3korr(key); unsigned_autoinc = (ulonglong) uint3korr(key);
break;
case HA_KEYTYPE_FLOAT: /* This shouldn't be used */
{
float f_1;
float4get(f_1,key);
/* Ignore negative values */
value = (f_1 < (float) 0.0) ? 0 : (ulonglong) f_1;
break;
}
case HA_KEYTYPE_DOUBLE: /* This shouldn't be used */
{
double f_1;
float8get(f_1,key);
/* Ignore negative values */
value = (f_1 < 0.0) ? 0 : (ulonglong) f_1;
break; break;
}
case HA_KEYTYPE_LONGLONG: case HA_KEYTYPE_LONGLONG:
s_value= sint8korr(key); signed_autoinc = sint8korr(key);
autoinc_type = signed_type;
break; break;
case HA_KEYTYPE_ULONGLONG: case HA_KEYTYPE_ULONGLONG:
value= uint8korr(key); unsigned_autoinc = uint8korr(key);
break;
/* The remaining two cases should not be used but are included for
compatibility */
case HA_KEYTYPE_FLOAT:
float4get(float_tmp, key); /* Note: float4get is a macro */
signed_autoinc = (longlong) float_tmp;
autoinc_type = signed_type;
break;
case HA_KEYTYPE_DOUBLE:
float8get(double_tmp, key); /* Note: float8get is a macro */
signed_autoinc = (longlong) double_tmp;
autoinc_type = signed_type;
break; break;
default: default:
DBUG_ASSERT(0); DBUG_ASSERT(0);
value=0; /* Error */ unsigned_autoinc = 0;
break;
} }
/* if (signed_autoinc < 0) {
The following code works becasue if s_value < 0 then value is 0 signed_autoinc = 0;
and if s_value == 0 then value will contain either s_value or the }
correct value.
*/ return autoinc_type == unsigned_type ?
return (s_value > 0) ? (ulonglong) s_value : value; unsigned_autoinc : (ulonglong) signed_autoinc;
} }
......
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