null+****@clear*****
null+****@clear*****
2011年 7月 22日 (金) 10:56:13 JST
Kouhei Sutou 2011-07-22 01:56:13 +0000 (Fri, 22 Jul 2011)
New Revision: 4ce8a7fbf83686b3418105b60f9e66fd9162b27f
Log:
[wrapper][multiple-column-index] split KEY validation. refs #1031
Modified files:
ha_mroonga.cc
ha_mroonga.h
Modified: ha_mroonga.cc (+36 -21)
===================================================================
--- ha_mroonga.cc 2011-07-22 01:41:12 +0000 (9629a07)
+++ ha_mroonga.cc 2011-07-22 01:56:13 +0000 (16df908)
@@ -1164,6 +1164,34 @@ int ha_mroonga::wrapper_create(const char *name, TABLE *table,
DBUG_RETURN(error);
}
+int ha_mroonga::wrapper_validate_key_info(KEY *key_info)
+{
+ MRN_DBUG_ENTER_METHOD();
+
+ int error = 0;
+ uint i;
+ for (i = 0; i < key_info->key_parts; i++) {
+ Field *field = key_info->key_part[i].field;
+
+ int mysql_field_type = field->type();
+ grn_builtin_type gtype = mrn_get_type(ctx, mysql_field_type);
+ if (gtype != GRN_DB_TEXT)
+ {
+ error = ER_CANT_CREATE_TABLE;
+ GRN_LOG(ctx, GRN_LOG_ERROR,
+ "key type must be text: <%d> "
+ "(TODO: We should show type name not type ID.)",
+ mysql_field_type);
+ my_message(ER_CANT_CREATE_TABLE,
+ "key type must be text. (TODO: We should show type name.)",
+ MYF(0));
+ DBUG_RETURN(error);
+ }
+ }
+
+ DBUG_RETURN(error);
+}
+
int ha_mroonga::wrapper_create_index(const char *name, TABLE *table,
HA_CREATE_INFO *info, MRN_SHARE *tmp_share)
{
@@ -1200,24 +1228,11 @@ int ha_mroonga::wrapper_create_index(const char *name, TABLE *table,
continue;
}
- uint j;
- for (j = 0; j < key_info.key_parts; j++) {
- Field *field = key_info.key_part[j].field;
-
- int mysql_field_type = field->type();
- grn_builtin_type gtype = mrn_get_type(ctx, mysql_field_type);
- if (gtype != GRN_DB_TEXT) {
- grn_obj_remove(ctx, grn_table);
- error = ER_CANT_CREATE_TABLE;
- GRN_LOG(ctx, GRN_LOG_ERROR,
- "key type must be text: <%d> "
- "(TODO: We should show type name not type ID.)",
- mysql_field_type);
- my_message(ER_CANT_CREATE_TABLE,
- "key type must be text. (TODO: We should show type name.)",
- MYF(0));
- DBUG_RETURN(error);
- }
+ error = wrapper_validate_key_info(&key_info);
+ if (error)
+ {
+ grn_obj_remove(ctx, grn_table);
+ DBUG_RETURN(error);
}
char index_name[MRN_MAX_PATH_SIZE];
@@ -1241,8 +1256,8 @@ int ha_mroonga::wrapper_create_index(const char *name, TABLE *table,
if (ctx->rc) {
error = ER_CANT_CREATE_TABLE;
my_message(ER_CANT_CREATE_TABLE, ctx->errbuf, MYF(0));
- grn_obj_remove(ctx, grn_table);
grn_obj_unlink(ctx, column_type);
+ grn_obj_remove(ctx, grn_table);
DBUG_RETURN(error);
}
grn_obj_unlink(ctx, column_type);
@@ -1259,10 +1274,10 @@ int ha_mroonga::wrapper_create_index(const char *name, TABLE *table,
index_column_flags,
grn_table);
if (ctx->rc) {
- grn_obj_remove(ctx, index_table);
- grn_obj_remove(ctx, grn_table);
error = ER_CANT_CREATE_TABLE;
my_message(error, ctx->errbuf, MYF(0));
+ grn_obj_remove(ctx, index_table);
+ grn_obj_remove(ctx, grn_table);
DBUG_RETURN(error);
}
}
Modified: ha_mroonga.h (+1 -0)
===================================================================
--- ha_mroonga.h 2011-07-22 01:41:12 +0000 (1a69ddd)
+++ ha_mroonga.h 2011-07-22 01:56:13 +0000 (80164e7)
@@ -230,6 +230,7 @@ private:
HA_CREATE_INFO *info, MRN_SHARE *tmp_share);
int storage_create(const char *name, TABLE *table,
HA_CREATE_INFO *info, MRN_SHARE *tmp_share);
+ int wrapper_validate_key_info(KEY *key_info);
int wrapper_create_index(const char *name, TABLE *table,
HA_CREATE_INFO *info, MRN_SHARE *tmp_share);
int storage_create_validate_pseudo_column(TABLE *table);