null+****@clear*****
null+****@clear*****
2011年 6月 9日 (木) 18:13:16 JST
Kouhei Sutou 2011-06-09 09:13:16 +0000 (Thu, 09 Jun 2011)
New Revision: 378717e679828304223b8cc901ab5653436ff4e5
Log:
[default][create] split index validation code.
Modified files:
ha_mroonga.cc
ha_mroonga.h
Modified: ha_mroonga.cc (+45 -31)
===================================================================
--- ha_mroonga.cc 2011-06-09 09:09:19 +0000 (a794ea4)
+++ ha_mroonga.cc 2011-06-09 09:13:16 +0000 (6898aac)
@@ -1029,37 +1029,9 @@ int ha_mroonga::default_create(const char *name, TABLE *table,
if (error != 0)
DBUG_RETURN(error);
- /* checking if index is used for virtual columns */
- uint n_keys = table->s->keys;
- for (i = 0; i < n_keys; i++) {
- KEY key_info = table->s->key_info[i];
- // must be single column key
- int key_parts = key_info.key_parts;
- if (key_parts != 1) {
- GRN_LOG(ctx, GRN_LOG_ERROR, "complex key is not supported yet");
- error = ER_NOT_SUPPORTED_YET;
- my_message(error, "complex key is not supported yet.", MYF(0));
- DBUG_RETURN(error);
- }
- Field *field = key_info.key_part[0].field;
- const char *col_name = field->field_name;
- int col_name_size = strlen(col_name);
- if (strncmp(MRN_ID_COL_NAME, col_name, col_name_size) == 0) {
- if (key_info.algorithm == HA_KEY_ALG_HASH) {
- continue; // hash index is ok
- }
- GRN_LOG(ctx, GRN_LOG_ERROR, "only hash index can be defined for _id");
- error = ER_CANT_CREATE_TABLE;
- my_message(error, "only hash index can be defined for _id", MYF(0));
- DBUG_RETURN(error);
- }
- if (strncmp(MRN_SCORE_COL_NAME, col_name, col_name_size) == 0) {
- GRN_LOG(ctx, GRN_LOG_ERROR, "_score cannot be used for index");
- error = ER_CANT_CREATE_TABLE;
- my_message(error, "_score cannot be used for index", MYF(0));
- DBUG_RETURN(error);
- }
- }
+ error = default_create_validate_index(table);
+ if (error != 0)
+ DBUG_RETURN(error);
/* before creating table, we must check if database is alreadly opened, created */
grn_obj *db_obj;
@@ -1185,6 +1157,7 @@ int ha_mroonga::default_create(const char *name, TABLE *table,
/* create indexes */
char idx_name[MRN_MAX_PATH_SIZE];
+ uint n_keys = table->s->keys;
for (i = 0; i < n_keys; i++) {
if (i == pkeynr) {
continue; // pkey is already handled
@@ -1268,6 +1241,47 @@ int ha_mroonga::default_create(const char *name, TABLE *table,
DBUG_RETURN(0);
}
+int ha_mroonga::default_create_validate_index(TABLE *table)
+{
+ int error = 0;
+ uint i;
+
+ DBUG_ENTER("ha_mroonga::default_create_validate_index");
+ /* checking if index is used for virtual columns */
+ uint n_keys = table->s->keys;
+ for (i = 0; i < n_keys; i++) {
+ KEY key_info = table->s->key_info[i];
+ // must be single column key
+ int key_parts = key_info.key_parts;
+ if (key_parts != 1) {
+ GRN_LOG(ctx, GRN_LOG_ERROR, "complex key is not supported yet");
+ error = ER_NOT_SUPPORTED_YET;
+ my_message(error, "complex key is not supported yet.", MYF(0));
+ DBUG_RETURN(error);
+ }
+ Field *field = key_info.key_part[0].field;
+ const char *col_name = field->field_name;
+ int col_name_size = strlen(col_name);
+ if (strncmp(MRN_ID_COL_NAME, col_name, col_name_size) == 0) {
+ if (key_info.algorithm == HA_KEY_ALG_HASH) {
+ continue; // hash index is ok
+ }
+ GRN_LOG(ctx, GRN_LOG_ERROR, "only hash index can be defined for _id");
+ error = ER_CANT_CREATE_TABLE;
+ my_message(error, "only hash index can be defined for _id", MYF(0));
+ DBUG_RETURN(error);
+ }
+ if (strncmp(MRN_SCORE_COL_NAME, col_name, col_name_size) == 0) {
+ GRN_LOG(ctx, GRN_LOG_ERROR, "_score cannot be used for index");
+ error = ER_CANT_CREATE_TABLE;
+ my_message(error, "_score cannot be used for index", MYF(0));
+ DBUG_RETURN(error);
+ }
+ }
+
+ DBUG_RETURN(error);
+}
+
int ha_mroonga::create(const char *name, TABLE *table, HA_CREATE_INFO *info)
{
int i, error = 0;
Modified: ha_mroonga.h (+1 -0)
===================================================================
--- ha_mroonga.h 2011-06-09 09:09:19 +0000 (05ea8ea)
+++ ha_mroonga.h 2011-06-09 09:13:16 +0000 (5c31688)
@@ -216,6 +216,7 @@ private:
int default_create(const char *name, TABLE *table,
HA_CREATE_INFO *info, MRN_SHARE *tmp_share);
int default_create_validate_pseudo_column(TABLE *table);
+ int default_create_validate_index(TABLE *table);
int wrapper_delete_table(const char *name, MRN_SHARE *tmp_share);
int default_delete_table(const char *name, MRN_SHARE *tmp_share,
const char *tbl_name);