null+****@clear*****
null+****@clear*****
2011年 7月 11日 (月) 11:58:21 JST
Kentoku 2011-07-11 02:58:21 +0000 (Mon, 11 Jul 2011) New Revision: a00ded5a94b7bd90dcf964e47abeb81609ab9550 Log: #1032 A full-text search gets hanging up on wrapper mode Modified files: ha_mroonga.cc mrn_table.cc mrn_table.h Modified: ha_mroonga.cc (+53 -3) =================================================================== --- ha_mroonga.cc 2011-07-10 16:33:55 +0000 (806c708) +++ ha_mroonga.cc 2011-07-11 02:58:21 +0000 (5b315de) @@ -1,7 +1,7 @@ /* -*- c-basic-offset: 2 -*- */ /* Copyright(C) 2010 Tetsuro IKEDA - Copyright(C) 2010 Kentoku SHIBA + Copyright(C) 2010-2011 Kentoku SHIBA Copyright(C) 2011 Kouhei Sutou <kou****@clear*****> This library is free software; you can redistribute it and/or @@ -3195,10 +3195,16 @@ ha_rows ha_mroonga::records_in_range(uint key_nr, key_range *range_min, key_rang int ha_mroonga::wrapper_index_init(uint idx, bool sorted) { int error; + KEY key_info = table->s->key_info[idx]; MRN_DBUG_ENTER_METHOD(); MRN_SET_WRAP_SHARE_KEY(share, table->s); MRN_SET_WRAP_TABLE_KEY(this, table); - error = wrap_handler->ha_index_init(share->wrap_key_nr[idx], sorted); + if (key_info.algorithm != HA_KEY_ALG_FULLTEXT) + { + error = wrap_handler->ha_index_init(share->wrap_key_nr[idx], sorted); + } else { + error = wrap_handler->ha_index_init(share->wrap_primary_key, sorted); + } MRN_SET_BASE_SHARE_KEY(share, table->s); MRN_SET_BASE_TABLE_KEY(this, table); DBUG_RETURN(error); @@ -3213,6 +3219,7 @@ int ha_mroonga::storage_index_init(uint idx, bool sorted) int ha_mroonga::index_init(uint idx, bool sorted) { MRN_DBUG_ENTER_METHOD(); + DBUG_PRINT("info",("mroonga idx=%u", idx)); active_index = idx; count_skip = FALSE; if (share->wrapper_mode) @@ -3932,6 +3939,12 @@ int ha_mroonga::read_range_next() int ha_mroonga::wrapper_ft_init() { MRN_DBUG_ENTER_METHOD(); + cur = grn_table_cursor_open(ctx, matched_record_keys, NULL, 0, NULL, 0, 0, + -1, 0); + if (ctx->rc) { + my_message(ER_ERROR_ON_READ, ctx->errbuf, MYF(0)); + DBUG_RETURN(ER_ERROR_ON_READ); + } DBUG_RETURN(0); } @@ -4146,8 +4159,40 @@ FT_INFO *ha_mroonga::ft_init_ext(uint flags, uint key_nr, String *key) int ha_mroonga::wrapper_ft_read(uchar *buf) { + int error; MRN_DBUG_ENTER_METHOD(); - DBUG_RETURN(0); + do { + record_id = grn_table_cursor_next(ctx, cur); + if (record_id == GRN_ID_NIL) { + error = HA_ERR_END_OF_FILE; + grn_table_cursor_close(ctx, cur); + cur = NULL; + break; + } else { + grn_id relation_record_id; +#ifdef _MSC_VER + uchar *key; + key = (uchar *) malloc(table->key_info->key_length); +#else + uchar key[table->key_info->key_length]; +#endif + grn_table_get_key(ctx, matched_record_keys, record_id, + &relation_record_id, sizeof(grn_id)); + grn_table_get_key(ctx, grn_table, relation_record_id, + key, table->key_info->key_length); + MRN_SET_WRAP_SHARE_KEY(share, table->s); + MRN_SET_WRAP_TABLE_KEY(this, table); + set_pk_bitmap(); + error = wrap_handler->index_read_map( + buf, key, pk_keypart_map, HA_READ_KEY_EXACT); + MRN_SET_BASE_SHARE_KEY(share, table->s); + MRN_SET_BASE_TABLE_KEY(this, table); +#ifdef _MSC_VER + free(key); +#endif + } + } while (error == HA_ERR_END_OF_FILE); + DBUG_RETURN(error); } int ha_mroonga::storage_ft_read(uchar *buf) @@ -4564,6 +4609,11 @@ int ha_mroonga::reset() int error; MRN_DBUG_ENTER_METHOD(); DBUG_PRINT("info",("mroonga this=%p", this)); + if (cur) + { + grn_table_cursor_close(ctx, cur); + cur = NULL; + } if (share->wrapper_mode) error = wrapper_reset(); else Modified: mrn_table.cc (+7 -0) =================================================================== --- mrn_table.cc 2011-07-10 16:33:55 +0000 (82533e2) +++ mrn_table.cc 2011-07-11 02:58:21 +0000 (70d8c53) @@ -457,6 +457,7 @@ MRN_SHARE *mrn_get_share(const char *table_name, TABLE *table, int *error) char *tmp_name; uint length, *wrap_key_nr, i, j; KEY *wrap_key_info; + TABLE_SHARE *wrap_table_share; DBUG_ENTER("mrn_get_share"); length = (uint) strlen(table_name); pthread_mutex_lock(&mrn_open_tables_mutex); @@ -469,6 +470,7 @@ MRN_SHARE *mrn_get_share(const char *table_name, TABLE *table, int *error) &tmp_name, length + 1, &wrap_key_nr, sizeof(*wrap_key_nr) * table->s->keys, &wrap_key_info, sizeof(*wrap_key_info) * table->s->keys, + &wrap_table_share, sizeof(*wrap_table_share), NullS)) ) { *error = HA_ERR_OUT_OF_MEM; @@ -515,6 +517,11 @@ MRN_SHARE *mrn_get_share(const char *table_name, TABLE *table, int *error) share->wrap_key_info = NULL; share->wrap_primary_key = MAX_KEY; } + memcpy(wrap_table_share, table->s, sizeof(*wrap_table_share)); + wrap_table_share->keys = share->wrap_keys; + wrap_table_share->key_info = share->wrap_key_info; + wrap_table_share->primary_key = share->wrap_primary_key; + share->wrap_table_share = wrap_table_share; } if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST)) Modified: mrn_table.h (+11 -4) =================================================================== --- mrn_table.h 2011-07-10 16:33:55 +0000 (cc64c51) +++ mrn_table.h 2011-07-11 02:58:21 +0000 (d2d5c3c) @@ -32,6 +32,7 @@ typedef struct st_mroonga_share pthread_mutex_t mutex; THR_LOCK lock; TABLE_SHARE *table_share; + TABLE_SHARE *wrap_table_share; char *engine; int engine_length; @@ -47,21 +48,27 @@ typedef struct st_mroonga_share bool wrapper_mode; } MRN_SHARE; -#define MRN_SET_WRAP_SHARE_KEY(share, table_share) \ +#define MRN_SET_WRAP_SHARE_KEY(share, table_share) +/* table_share->keys = share->wrap_keys; \ table_share->key_info = share->wrap_key_info; \ table_share->primary_key = share->wrap_primary_key; +*/ -#define MRN_SET_BASE_SHARE_KEY(share, table_share) \ +#define MRN_SET_BASE_SHARE_KEY(share, table_share) +/* table_share->keys = share->base_keys; \ table_share->key_info = share->base_key_info; \ table_share->primary_key = share->base_primary_key; +*/ #define MRN_SET_WRAP_TABLE_KEY(file, table) \ - table->key_info = file->wrap_key_info; + table->key_info = file->wrap_key_info; \ + table->s = share->wrap_table_share; #define MRN_SET_BASE_TABLE_KEY(file, table) \ - table->key_info = file->base_key_info; + table->key_info = file->base_key_info; \ + table->s = share->table_share; char *mrn_create_string(const char *str, uint length); char *mrn_get_string_between_quote(char *ptr, bool alloc);