null+****@clear*****
null+****@clear*****
2012年 2月 21日 (火) 09:37:12 JST
Kentoku 2012-02-21 09:37:12 +0900 (Tue, 21 Feb 2012) New Revision: 82b7fe028d74c60f79f10e2564ecc610010e97fb Log: change max_supported_key_part_length check. refs #1282 Modified files: ha_mroonga.cc ha_mroonga.h Modified: ha_mroonga.cc (+33 -6) =================================================================== --- ha_mroonga.cc 2012-02-20 03:30:07 +0900 (4d85780) +++ ha_mroonga.cc 2012-02-21 09:37:12 +0900 (3b74f40) @@ -2021,7 +2021,9 @@ int ha_mroonga::wrapper_create(const char *name, TABLE *table, DBUG_RETURN(ER_REQUIRES_PRIMARY_KEY); } - error = wrapper_create_index(name, table, info, tmp_share); + char grn_table_name[MRN_MAX_PATH_SIZE]; + mrn_table_name_gen(name, grn_table_name); + error = wrapper_create_index(name, table, info, tmp_share, grn_table_name); if (error) DBUG_RETURN(error); @@ -2049,12 +2051,19 @@ int ha_mroonga::wrapper_create(const char *name, TABLE *table, DBUG_RETURN(HA_ERR_OUT_OF_MEM); } hnd->init(); - error = hnd->ha_create(name, table, info); + error = wrapper_create_index_check(hnd, table); + if (!error) { + error = hnd->ha_create(name, table, info); + } MRN_SET_BASE_SHARE_KEY(tmp_share, table->s); MRN_SET_BASE_TABLE_KEY(this, table); share = NULL; delete hnd; + if (error) { + wrapper_delete_index(name, tmp_share, grn_table_name); + } + if (wrap_key_info) { my_free(wrap_key_info, MYF(0)); @@ -2222,7 +2231,9 @@ int ha_mroonga::wrapper_create_index_geo(grn_obj *grn_table, } int ha_mroonga::wrapper_create_index(const char *name, TABLE *table, - HA_CREATE_INFO *info, MRN_SHARE *tmp_share) + HA_CREATE_INFO *info, + MRN_SHARE *tmp_share, + char *grn_table_name) { MRN_DBUG_ENTER_METHOD(); @@ -2236,8 +2247,6 @@ int ha_mroonga::wrapper_create_index(const char *name, TABLE *table, DBUG_RETURN(error); grn_obj *grn_table; - char grn_table_name[MRN_MAX_PATH_SIZE]; - mrn_table_name_gen(name, grn_table_name); char *grn_table_path = NULL; // we don't specify path grn_obj *pkey_type = grn_ctx_at(ctx, GRN_DB_SHORT_TEXT); grn_obj *pkey_value_type = NULL; // we don't use this @@ -2284,6 +2293,24 @@ int ha_mroonga::wrapper_create_index(const char *name, TABLE *table, DBUG_RETURN(error); } +int ha_mroonga::wrapper_create_index_check(handler *hnd, TABLE *table) +{ + MRN_DBUG_ENTER_METHOD(); + uint i, j; + for (i = 0; i < table->s->keys; i++) { + KEY *key_info = &table->s->key_info[i]; + KEY_PART_INFO *key_part = key_info->key_part; + for (j = 0; j < key_info->key_parts; j++) { + if (key_part[j].length > hnd->max_key_part_length()) + { + my_error(ER_TOO_LONG_KEY, MYF(0), hnd->max_key_part_length()); + DBUG_RETURN(ER_TOO_LONG_KEY); + } + } + } + DBUG_RETURN(0); +} + int ha_mroonga::storage_create(const char *name, TABLE *table, HA_CREATE_INFO *info, MRN_SHARE *tmp_share) { @@ -9972,7 +9999,7 @@ int ha_mroonga::wrapper_recreate_indexes(THD *thd) } if ( (res = wrapper_create_index(table_share->normalized_path.str, table, - NULL, share)) || + NULL, share, table_name)) || (res = wrapper_open_indexes(table_share->normalized_path.str, false)) ) DBUG_RETURN(res); Modified: ha_mroonga.h (+7 -4) =================================================================== --- ha_mroonga.h 2012-02-20 03:30:07 +0900 (b41f422) +++ ha_mroonga.h 2012-02-21 09:37:12 +0900 (dec972f) @@ -255,10 +255,11 @@ public: int update_row(const uchar *old_data, uchar *new_data); int delete_row(const uchar *buf); - uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; } - uint max_supported_keys() const { return 100; } + uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; } + uint max_supported_keys() const { return 100; } uint max_supported_key_parts(); - uint max_supported_key_length() const { return MAX_KEY_LENGTH; } + uint max_supported_key_length() const { return MAX_KEY_LENGTH; } + uint max_supported_key_part_length() const { return MAX_KEY_LENGTH; } ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); int index_init(uint idx, bool sorted); @@ -520,7 +521,9 @@ private: grn_obj **index_tables, MRN_SHARE *tmp_share); int wrapper_create_index(const char *name, TABLE *table, - HA_CREATE_INFO *info, MRN_SHARE *tmp_share); + HA_CREATE_INFO *info, MRN_SHARE *tmp_share, + char *grn_table_name); + int wrapper_create_index_check(handler *hnd, TABLE *table); int storage_create_validate_pseudo_column(TABLE *table); int storage_create_validate_index(TABLE *table); int storage_create_index(TABLE *table, const char *grn_table_name,