diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 92325aa16b9..c1de7ed33b3 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -154,6 +154,7 @@ ha_spider::ha_spider( result_list.direct_aggregate = FALSE; #endif result_list.casual_read = NULL; + result_list.use_both_key = FALSE; DBUG_VOID_RETURN; } @@ -258,6 +259,7 @@ ha_spider::ha_spider( result_list.direct_aggregate = FALSE; #endif result_list.casual_read = NULL; + result_list.use_both_key = FALSE; ref_length = sizeof(SPIDER_POSITION); DBUG_VOID_RETURN; } @@ -1714,6 +1716,7 @@ int ha_spider::reset() clone_bitmap_init = FALSE; result_list.tmp_table_join = FALSE; result_list.use_union = FALSE; + result_list.use_both_key = FALSE; pt_clone_last_searcher = NULL; conn_kinds = SPIDER_CONN_KIND_MYSQL; has_clone_for_merge = FALSE; @@ -4126,10 +4129,14 @@ int ha_spider::read_range_first( if ((error_num = spider_bg_all_conn_pre_next(this, search_link_idx))) DBUG_RETURN(error_num); use_pre_call = FALSE; - DBUG_RETURN(read_range_next()); + if ((error_num = read_range_next())) + DBUG_RETURN(error_num); + DBUG_RETURN(check_ha_range_eof()); } - DBUG_RETURN(read_range_first_internal(table->record[0], start_key, end_key, - eq_range, sorted)); + if ((error_num = read_range_first_internal(table->record[0], start_key, + end_key, eq_range, sorted))) + DBUG_RETURN(error_num); + DBUG_RETURN(check_ha_range_eof()); } int ha_spider::read_range_next() @@ -4160,7 +4167,7 @@ int ha_spider::read_range_next() if ((error_num = spider_db_seek_next(table->record[0], this, search_link_idx, table))) DBUG_RETURN(check_error_mode_eof(error_num)); - DBUG_RETURN(0); + DBUG_RETURN(check_ha_range_eof()); } #ifdef HA_MRR_USE_DEFAULT_IMPL @@ -4687,7 +4694,7 @@ int ha_spider::read_multi_range_first_internal( #else *found_range_p = multi_range_curr; #endif - DBUG_RETURN(0); + DBUG_RETURN(check_ha_range_eof()); } if ( error_num != HA_ERR_END_OF_FILE && @@ -5743,7 +5750,7 @@ int ha_spider::read_multi_range_next( ) { if (!(error_num = spider_db_seek_next(table->record[0], this, search_link_idx, table))) - DBUG_RETURN(0); + DBUG_RETURN(check_ha_range_eof()); #ifdef HA_MRR_USE_DEFAULT_IMPL range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); DBUG_PRINT("info",("spider range_res1=%d", range_res)); @@ -6092,7 +6099,7 @@ int ha_spider::read_multi_range_next( #else *found_range_p = multi_range_curr; #endif - DBUG_RETURN(0); + DBUG_RETURN(check_ha_range_eof()); } if ( error_num != HA_ERR_END_OF_FILE && @@ -11489,6 +11496,35 @@ void ha_spider::check_direct_order_limit() DBUG_VOID_RETURN; } +int ha_spider::check_ha_range_eof() +{ + DBUG_ENTER("ha_spider::check_ha_range_eof"); + DBUG_PRINT("info",("spider this=%p", this)); + const key_range *end_key = result_list.end_key; + DBUG_PRINT("info",("spider use_both_key=%s", + result_list.use_both_key ? "TRUE" : "FALSE")); + DBUG_PRINT("info",("spider sql_kind[%u]=%u", + search_link_idx, sql_kind[search_link_idx])); + DBUG_PRINT("info",("spider sql_command=%u", sql_command)); + if ( + result_list.use_both_key && + (sql_kind[search_link_idx] & SPIDER_SQL_KIND_HANDLER) && + sql_command != SQLCOM_HA_READ + ) { + int cmp_result = key_cmp(result_list.key_info->key_part, + end_key->key, end_key->length); + DBUG_PRINT("info",("spider cmp_result=%d", cmp_result)); + if ( + cmp_result > 0 || + (end_key->flag == HA_READ_BEFORE_KEY && !cmp_result) + ) { + table->status = STATUS_NOT_FOUND; + DBUG_RETURN(HA_ERR_END_OF_FILE); + } + } + DBUG_RETURN(0); +} + int ha_spider::drop_tmp_tables() { int error_num = 0, tmp_error_num, need_mon; diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index c26a8781f88..a944d3e0533 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -740,6 +740,7 @@ public: ); uint check_partitioned(); void check_direct_order_limit(); + int check_ha_range_eof(); int drop_tmp_tables(); bool handler_opened( int link_idx, diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index a0e3e01e852..4ae7e81d026 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -1595,9 +1595,10 @@ int spider_db_append_key_where_internal( start_key_part_map = 0; use_both = FALSE; } - if (end_key) + if (end_key) { end_key_part_map = end_key->keypart_map & full_key_part_map; - else { + result_list->end_key = end_key; + } else { end_key_part_map = 0; use_both = FALSE; } @@ -1657,6 +1658,8 @@ int spider_db_append_key_where_internal( tgt_key_part_map = end_key_part_map; } DBUG_PRINT("info", ("spider tgt_key_part_map=%lu", tgt_key_part_map)); + if (start_key_part_map == end_key_part_map) + result_list->use_both_key = TRUE; if (sql_kind == SPIDER_SQL_KIND_SQL) { diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 9961b0c3563..84240443327 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -1591,6 +1591,8 @@ typedef struct st_spider_result_list uint *sql_kind_backup; uint sql_kinds_backup; bool use_union; + bool use_both_key; + const key_range *end_key; spider_string *insert_sqls; spider_string *update_sqls; TABLE **upd_tmp_tbls; diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index db6d9f933d2..5c175439a20 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -7119,10 +7119,17 @@ int spider_mysql_handler::append_condition_part( } ha_where_pos = str->length(); - if (sql_part2.length()) - { - str->append(sql_part2); - start_where = FALSE; + if ( + spider->sql_command == SQLCOM_HA_READ || + !spider->result_list.use_both_key + ) { + if (sql_part2.length()) + { + str->append(sql_part2); + start_where = FALSE; + } + } else { + DBUG_RETURN(0); } } break; diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 97dc130600e..c6e3acce8ab 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define SPIDER_DETAIL_VERSION "3.1.13" +#define SPIDER_DETAIL_VERSION "3.1.14" #define SPIDER_HEX_VERSION 0x0301 #if MYSQL_VERSION_ID < 50500