Commit 95364736 authored by joreland@mysql.com's avatar joreland@mysql.com

ndb - HugoCalculator, faster string generation

parent d96c622c
...@@ -18,6 +18,22 @@ ...@@ -18,6 +18,22 @@
#include <NDBT.hpp> #include <NDBT.hpp>
#include <Base64.hpp> #include <Base64.hpp>
static
Uint32
myRand(Uint64 * seed)
{
const Uint64 mul= 0x5deece66dull;
const Uint64 add= 0xb;
Uint64 loc_result = *seed * mul + add;
* seed= loc_result;
return loc_result >> 1;
}
static char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
/* ************************************************************* /* *************************************************************
* HugoCalculator * HugoCalculator
* *
...@@ -79,21 +95,23 @@ HugoCalculator::calcValue(int record, ...@@ -79,21 +95,23 @@ HugoCalculator::calcValue(int record,
int updates, int updates,
char* buf, char* buf,
int len) const { int len) const {
unsigned seed; Uint64 seed;
const NdbDictionary::Column* attr = m_tab.getColumn(attrib); const NdbDictionary::Column* attr = m_tab.getColumn(attrib);
Uint32 val; Uint32 val;
do do
{ {
if (attrib == m_idCol) if (attrib == m_idCol)
{ {
*((Uint32*)buf)= record; val= record;
memcpy(buf, &val, 4);
return buf; return buf;
} }
// If this is the update column // If this is the update column
if (attrib == m_updatesCol) if (attrib == m_updatesCol)
{ {
*((Uint32*)buf)= updates; val= updates;
memcpy(buf, &val, 4);
return buf; return buf;
} }
...@@ -106,26 +124,13 @@ HugoCalculator::calcValue(int record, ...@@ -106,26 +124,13 @@ HugoCalculator::calcValue(int record,
seed = record + attrib + updates; seed = record + attrib + updates;
} }
} while (0); } while (0);
val = rand_r(&seed);
val = myRand(&seed);
if(attr->getNullable() && (((val >> 16) & 255) > 220)) if(attr->getNullable() && (((val >> 16) & 255) > 220))
return NULL; return NULL;
memcpy(buf, &val, (len > 4 ? 4 : len));
int pos= 4;
while(pos + 4 < len)
{
val= rand_r(&seed);
memcpy(buf+pos, &val, 4);
pos++;
}
if(pos < len)
{
val= rand_r(&seed);
memcpy(buf+pos, &val, (len - pos));
}
int pos= 0;
switch(attr->getType()){ switch(attr->getType()){
case NdbDictionary::Column::Tinyint: case NdbDictionary::Column::Tinyint:
case NdbDictionary::Column::Tinyunsigned: case NdbDictionary::Column::Tinyunsigned:
...@@ -144,15 +149,24 @@ HugoCalculator::calcValue(int record, ...@@ -144,15 +149,24 @@ HugoCalculator::calcValue(int record,
case NdbDictionary::Column::Datetime: case NdbDictionary::Column::Datetime:
case NdbDictionary::Column::Time: case NdbDictionary::Column::Time:
case NdbDictionary::Column::Date: case NdbDictionary::Column::Date:
break;
case NdbDictionary::Column::Bit: case NdbDictionary::Column::Bit:
{ while (len > 4)
Uint32 bits= attr->getLength(); {
Uint32 tmp = bits >> 5; memcpy(buf+pos, &val, 4);
Uint32 size = bits & 31; pos += 4;
((Uint32*)buf)[tmp] &= ((1 << size) - 1); len -= 4;
val= myRand(&seed);
}
memcpy(buf+pos, &val, len);
if(attr->getType() == NdbDictionary::Column::Bit)
{
Uint32 bits= attr->getLength();
Uint32 tmp = bits >> 5;
Uint32 size = bits & 31;
((Uint32*)buf)[tmp] &= ((1 << size) - 1);
}
break; break;
}
case NdbDictionary::Column::Varbinary: case NdbDictionary::Column::Varbinary:
case NdbDictionary::Column::Varchar: case NdbDictionary::Column::Varchar:
case NdbDictionary::Column::Text: case NdbDictionary::Column::Text:
...@@ -160,9 +174,21 @@ HugoCalculator::calcValue(int record, ...@@ -160,9 +174,21 @@ HugoCalculator::calcValue(int record,
case NdbDictionary::Column::Longvarchar: case NdbDictionary::Column::Longvarchar:
case NdbDictionary::Column::Longvarbinary: case NdbDictionary::Column::Longvarbinary:
{ {
BaseString tmp; char* ptr= (char*)&val;
base64_encode(buf, len, tmp); while(len >= 4)
memcpy(buf, tmp.c_str(), len); {
len -= 4;
buf[pos++] = base64_table[ptr[0] & 0x3f];
buf[pos++] = base64_table[ptr[1] & 0x3f];
buf[pos++] = base64_table[ptr[2] & 0x3f];
buf[pos++] = base64_table[ptr[3] & 0x3f];
val= myRand(&seed);
}
for(; len; len--, pos++)
buf[pos] = base64_table[ptr[len] & 0x3f];
pos--;
break; break;
} }
case NdbDictionary::Column::Blob: case NdbDictionary::Column::Blob:
......
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