diff --git a/sql/sql_class.cc b/sql/sql_class.cc index f36fc0dfc4a..1de6485e269 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -732,6 +732,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock) spider_slow_query_num = 0; spider_current_partition_num = 0; spider_features_type = 0; + spider_const_index_read = FALSE; kill_self = FALSE; file_id = 0; diff --git a/sql/sql_class.h b/sql/sql_class.h index 2defd8fd51a..96e11d6df6d 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2438,6 +2438,7 @@ class THD :public Statement, ulong current_global_server_version; bool is_support_ddl_by_ctl; // equal to tdbctl_is_ddl_by_ctl(thd,lex) bool do_ddl_by_ctl; // must do tcadmin_execute_command + bool spider_const_index_read; // const or system join type in spider // Process indicator struct { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 319756a4ed6..f26d7835c74 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7014,6 +7014,7 @@ void THD::reset_for_next_command(bool do_clear_error) { thd->spider_current_partition_num = 0; thd->spider_features_type = 0; thd->current_global_server_version = get_modify_server_version(); + thd->spider_const_index_read = FALSE; DBUG_PRINT("debug", ("is_current_stmt_binlog_format_row(): %d", is_current_stmt_binlog_format_row())); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 7655a06ae2b..64588d02066 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -17571,6 +17571,8 @@ static int join_read_const(JOIN_TAB *tab) { if (cp_buffer_from_ref(tab->join->thd, table, &tab->ref)) error = HA_ERR_KEY_NOT_FOUND; else { + if (table->file->is_spider_storage_engine()) + tab->join->thd->spider_const_index_read = TRUE; error = table->file->ha_index_read_idx_map( table->record[0], tab->ref.key, (uchar *)tab->ref.key_buff, make_prev_keypart_map(tab->ref.key_parts), HA_READ_KEY_EXACT); diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index bd2a3ec2fd2..c319d639171 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -3034,11 +3034,16 @@ int spider_db_store_result(ha_spider *spider, int link_idx, TABLE *table) { SPIDER_DB_ROW *tmp_row; uint field_count = current->result->num_fields(); SPIDER_POSITION *position; - longlong page_size = - !result_list->quick_page_size || - result_list->limit_num < result_list->quick_page_size - ? result_list->limit_num - : result_list->quick_page_size; + longlong page_size = 0LL; + if (thd->spider_const_index_read) { + /* only one row for const index read */ + page_size = 1; + } else { + page_size = !result_list->quick_page_size || + result_list->limit_num < result_list->quick_page_size + ? result_list->limit_num + : result_list->quick_page_size; + } int roop_count = 0; current->field_count = field_count; if (!(position = (SPIDER_POSITION *)spider_bulk_malloc(