Navigation Menu

Skip to content

Commit

Permalink
storage: reduce storage size for ENUM
Browse files Browse the repository at this point in the history
This is incompatible change!

ENUM requires 1 byte storage size for the number of elements < 256, 2
bytes storage size for the number of elements >= 256. Before this
change, ENUM always uses 2 byte storage size. By this change, ENUM
that has the number of elements < 256 uses 1 byte storage size.

Users who use ENUM that has the number of elements < 256 need to
recreate database. Users who doesn't use ENUM or use ENUM that has the
number of elements >= 256 don't need to recreate database.
  • Loading branch information
kou committed Jul 26, 2012
1 parent 82a879b commit ebd3529
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ha_mroonga.cpp
Expand Up @@ -1090,7 +1090,11 @@ static grn_builtin_type mrn_grn_type_from_field(grn_ctx *ctx, Field *field,
type = GRN_DB_SHORT_TEXT; // 4Kbytes
break;
case MYSQL_TYPE_ENUM: // ENUM; <= 2bytes
type = GRN_DB_UINT16; // 2bytes
if (field->pack_length() == 1) {
type = GRN_DB_UINT8; // 1bytes
} else {
type = GRN_DB_UINT16; // 2bytes
}
break;
case MYSQL_TYPE_SET: // SET; <= 8bytes
switch (field->pack_length()) {
Expand Down Expand Up @@ -9068,14 +9072,17 @@ int ha_mroonga::storage_encode_key_enum(Field *field, const uchar *key,
{
MRN_DBUG_ENTER_METHOD();
int error = 0;
uint16 value;
if (field->pack_length() == 1) {
value = static_cast<uint16>(key[0]);
uchar value;
value = key[0];
*size = 1;
memcpy(buf, &value, *size);
} else {
uint16 value;
shortget(value, key);
*size = 2;
memcpy(buf, &value, *size);
}
memcpy(buf, &value, 2);
*size = 2;
DBUG_RETURN(error);
}

Expand Down

0 comments on commit ebd3529

Please sign in to comment.