null+****@clear*****
null+****@clear*****
2012年 7月 26日 (木) 14:20:40 JST
Kouhei Sutou 2012-07-26 14:20:40 +0900 (Thu, 26 Jul 2012) New Revision: ebd352913f4a99905484aef967f7640e3a0bb05f https://github.com/mroonga/mroonga/commit/ebd352913f4a99905484aef967f7640e3a0bb05f Log: storage: reduce storage size for ENUM 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. Modified files: ha_mroonga.cpp Modified: ha_mroonga.cpp (+12 -5) =================================================================== --- ha_mroonga.cpp 2012-07-26 14:06:49 +0900 (e1cf691) +++ ha_mroonga.cpp 2012-07-26 14:20:40 +0900 (5c085a2) @@ -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()) { @@ -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); } -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...Download