summaryrefslogtreecommitdiff
path: root/storage/spider
diff options
context:
space:
mode:
Diffstat (limited to 'storage/spider')
-rw-r--r--storage/spider/ha_spider.cc48
-rw-r--r--storage/spider/ha_spider.h10
-rw-r--r--storage/spider/spd_conn.cc56
-rw-r--r--storage/spider/spd_conn.h4
-rw-r--r--storage/spider/spd_db_conn.cc990
-rw-r--r--storage/spider/spd_db_conn.h21
-rw-r--r--storage/spider/spd_db_include.cc90
-rw-r--r--storage/spider/spd_db_include.h36
-rw-r--r--storage/spider/spd_db_mysql.cc29
-rw-r--r--storage/spider/spd_db_mysql.h13
-rw-r--r--storage/spider/spd_direct_sql.cc220
-rw-r--r--storage/spider/spd_err.h5
-rw-r--r--storage/spider/spd_include.h9
-rw-r--r--storage/spider/spd_param.cc26
-rw-r--r--storage/spider/spd_param.h4
-rw-r--r--storage/spider/spd_table.cc298
16 files changed, 1461 insertions, 398 deletions
diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc
index 461d1f01bc2..49ab2fd29ec 100644
--- a/storage/spider/ha_spider.cc
+++ b/storage/spider/ha_spider.cc
@@ -10028,6 +10028,28 @@ int ha_spider::update_row(
}
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
+bool ha_spider::check_direct_update_sql_part(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+) {
+ uint roop_count, dbton_id;
+ spider_db_handler *dbton_hdl;
+ DBUG_ENTER("ha_spider::check_direct_update_sql_part");
+ for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
+ {
+ dbton_id = share->use_sql_dbton_ids[roop_count];
+ dbton_hdl = dbton_handler[dbton_id];
+ if (
+ dbton_hdl->first_link_idx >= 0 &&
+ dbton_hdl->check_direct_update(select_lex, select_limit, offset_limit)
+ ) {
+ DBUG_RETURN(TRUE);
+ }
+ }
+ DBUG_RETURN(FALSE);
+}
+
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
#ifdef SPIDER_MDEV_16246
int ha_spider::direct_update_rows_init(
@@ -10118,6 +10140,7 @@ int ha_spider::direct_update_rows_init(
!select_lex ||
select_lex->table_list.elements != 1 ||
check_update_columns_sql_part() ||
+ check_direct_update_sql_part(select_lex, select_limit, offset_limit) ||
spider_db_append_condition(this, NULL, 0, TRUE)
) {
DBUG_PRINT("info",("spider FALSE by condition"));
@@ -10292,6 +10315,7 @@ int ha_spider::direct_update_rows_init()
!select_lex ||
select_lex->table_list.elements != 1 ||
check_update_columns_sql_part() ||
+ check_direct_update_sql_part(select_lex, select_limit, offset_limit) ||
spider_db_append_condition(this, NULL, 0, TRUE)
) {
DBUG_PRINT("info",("spider FALSE by condition"));
@@ -10649,6 +10673,28 @@ int ha_spider::delete_row(
}
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
+bool ha_spider::check_direct_delete_sql_part(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+) {
+ uint roop_count, dbton_id;
+ spider_db_handler *dbton_hdl;
+ DBUG_ENTER("ha_spider::check_direct_delete_sql_part");
+ for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++)
+ {
+ dbton_id = share->use_sql_dbton_ids[roop_count];
+ dbton_hdl = dbton_handler[dbton_id];
+ if (
+ dbton_hdl->first_link_idx >= 0 &&
+ dbton_hdl->check_direct_delete(select_lex, select_limit, offset_limit)
+ ) {
+ DBUG_RETURN(TRUE);
+ }
+ }
+ DBUG_RETURN(FALSE);
+}
+
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
int ha_spider::direct_delete_rows_init(
uint mode,
@@ -10716,6 +10762,7 @@ int ha_spider::direct_delete_rows_init(
#endif
!select_lex ||
select_lex->table_list.elements != 1 ||
+ check_direct_delete_sql_part(select_lex, select_limit, offset_limit) ||
spider_db_append_condition(this, NULL, 0, TRUE)
) {
DBUG_PRINT("info",("spider FALSE by condition"));
@@ -10821,6 +10868,7 @@ int ha_spider::direct_delete_rows_init()
#endif
!select_lex ||
select_lex->table_list.elements != 1 ||
+ check_direct_delete_sql_part(select_lex, select_limit, offset_limit) ||
spider_db_append_condition(this, NULL, 0, TRUE)
) {
DBUG_PRINT("info",("spider FALSE by condition"));
diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h
index d5645f25a0a..13bbacf0b0e 100644
--- a/storage/spider/ha_spider.h
+++ b/storage/spider/ha_spider.h
@@ -585,6 +585,11 @@ public:
);
#endif
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
+ bool check_direct_update_sql_part(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+ );
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
#ifdef SPIDER_MDEV_16246
inline int direct_update_rows_init(
@@ -709,6 +714,11 @@ public:
const uchar *buf
);
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
+ bool check_direct_delete_sql_part(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+ );
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS
inline int direct_delete_rows_init()
{
diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc
index a9d86823654..8e9d7d60317 100644
--- a/storage/spider/spd_conn.cc
+++ b/storage/spider/spd_conn.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008-2019 Kentoku Shiba
+/* Copyright (C) 2008-2020 Kentoku Shiba
Copyright (C) 2019, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
@@ -563,7 +563,7 @@ SPIDER_CONN *spider_create_conn(
SPIDER_CONN *conn;
SPIDER_IP_PORT_CONN *ip_port_conn;
char *tmp_name, *tmp_host, *tmp_username, *tmp_password, *tmp_socket;
- char *tmp_wrapper, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert;
+ char *tmp_wrapper, *tmp_db, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert;
char *tmp_ssl_cipher, *tmp_ssl_key, *tmp_default_file, *tmp_default_group;
DBUG_ENTER("spider_create_conn");
@@ -578,6 +578,15 @@ SPIDER_CONN *spider_create_conn(
if (conn_kind == SPIDER_CONN_KIND_MYSQL)
{
#endif
+ bool tables_on_different_db_are_joinable;
+ if (share->sql_dbton_ids[link_idx] != SPIDER_DBTON_SIZE)
+ {
+ tables_on_different_db_are_joinable =
+ spider_dbton[share->sql_dbton_ids[link_idx]].db_util->
+ tables_on_different_db_are_joinable();
+ } else {
+ tables_on_different_db_are_joinable = TRUE;
+ }
if (!(conn = (SPIDER_CONN *)
spider_bulk_malloc(spider_current_trx, 18, MYF(MY_WME | MY_ZEROFILL),
&conn, (uint) (sizeof(*conn)),
@@ -590,6 +599,8 @@ SPIDER_CONN *spider_create_conn(
&tmp_socket, (uint) (share->tgt_sockets_lengths[link_idx] + 1),
&tmp_wrapper,
(uint) (share->tgt_wrappers_lengths[link_idx] + 1),
+ &tmp_db, (uint) (tables_on_different_db_are_joinable ?
+ 0 : share->tgt_dbs_lengths[link_idx] + 1),
&tmp_ssl_ca, (uint) (share->tgt_ssl_cas_lengths[link_idx] + 1),
&tmp_ssl_capath,
(uint) (share->tgt_ssl_capaths_lengths[link_idx] + 1),
@@ -638,6 +649,13 @@ SPIDER_CONN *spider_create_conn(
conn->tgt_wrapper = tmp_wrapper;
memcpy(conn->tgt_wrapper, share->tgt_wrappers[link_idx],
share->tgt_wrappers_lengths[link_idx]);
+ if (!tables_on_different_db_are_joinable)
+ {
+ conn->tgt_db_length = share->tgt_dbs_lengths[link_idx];
+ conn->tgt_db = tmp_db;
+ memcpy(conn->tgt_db, share->tgt_dbs[link_idx],
+ share->tgt_dbs_lengths[link_idx]);
+ }
conn->tgt_ssl_ca_length = share->tgt_ssl_cas_lengths[link_idx];
if (conn->tgt_ssl_ca_length)
{
@@ -1878,8 +1896,8 @@ int spider_conn_queue_loop_check(
my_afree(loop_check_buf);
to_str.length = build_table_filename(path, FN_REFLEN,
- share->tgt_dbs[conn_link_idx], share->tgt_table_names[conn_link_idx],
- "", 0);
+ share->tgt_dbs[conn_link_idx] ? share->tgt_dbs[conn_link_idx] : "",
+ share->tgt_table_names[conn_link_idx], "", 0);
to_str.str = path;
DBUG_PRINT("info", ("spider to=%s", to_str.str));
buf_sz = from_str.length + top_share->path.length + to_str.length + 3;
@@ -2831,6 +2849,21 @@ int spider_bg_conn_search(
}
}
result_list->bgs_phase = 2;
+ if (conn->db_conn->limit_mode() == 1)
+ {
+ conn->db_conn->set_limit(result_list->limit_num);
+ if (!discard_result)
+ {
+ if ((error_num = spider_db_store_result_for_reuse_cursor(
+ spider, link_idx, result_list->table)))
+ {
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ DBUG_RETURN(error_num);
+ }
+ }
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ DBUG_RETURN(0);
+ }
}
result_list->bgs_working = TRUE;
conn->bg_search = TRUE;
@@ -2965,6 +2998,21 @@ int spider_bg_conn_search(
DBUG_RETURN(error_num);
}
}
+ if (conn->db_conn->limit_mode() == 1)
+ {
+ conn->db_conn->set_limit(result_list->limit_num);
+ if (!discard_result)
+ {
+ if ((error_num = spider_db_store_result_for_reuse_cursor(
+ spider, link_idx, result_list->table)))
+ {
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ DBUG_RETURN(error_num);
+ }
+ }
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ DBUG_RETURN(0);
+ }
}
conn->bg_target = spider;
conn->link_idx = link_idx;
diff --git a/storage/spider/spd_conn.h b/storage/spider/spd_conn.h
index f6daa9832b3..92da278eecc 100644
--- a/storage/spider/spd_conn.h
+++ b/storage/spider/spd_conn.h
@@ -1,5 +1,5 @@
-/* Copyright (C) 2008-2019 Kentoku Shiba
- Copyright (C) 2019 MariaDB corp
+/* Copyright (C) 2008-2020 Kentoku Shiba
+ Copyright (C) 2019-2020 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc
index 800612f4b5c..a6594df473c 100644
--- a/storage/spider/spd_db_conn.cc
+++ b/storage/spider/spd_db_conn.cc
@@ -960,6 +960,7 @@ int spider_db_set_names_internal(
}
if (
spider_param_use_default_database(trx->thd) &&
+ share->tgt_dbs[all_link_idx] &&
(
!conn->default_database.length() ||
conn->default_database.length() !=
@@ -4040,7 +4041,8 @@ int spider_db_store_result(
#endif
result_list->quick_phase == 2
) {
- if (result_list->low_mem_read)
+ if (result_list->low_mem_read &&
+ result_list->current->result->limit_mode() == 0)
{
do {
spider_db_free_one_result(result_list,
@@ -4488,6 +4490,428 @@ int spider_db_store_result(
DBUG_RETURN(0);
}
+int spider_db_store_result_for_reuse_cursor(
+ ha_spider *spider,
+ int link_idx,
+ TABLE *table
+) {
+ int error_num;
+ SPIDER_CONN *conn;
+ SPIDER_RESULT_LIST *result_list = &spider->result_list;
+ SPIDER_RESULT *current;
+ DBUG_ENTER("spider_db_store_result_for_reuse_cursor");
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ DBUG_ASSERT(spider->conn_kind[link_idx] == SPIDER_CONN_KIND_MYSQL);
+#endif
+ conn = spider->conns[link_idx];
+ DBUG_PRINT("info",("spider conn->connection_id=%llu",
+ conn->connection_id));
+ DBUG_PRINT("info",("spider spider->connection_ids[%d]=%llu",
+ link_idx, spider->connection_ids[link_idx]));
+ if (conn->connection_id != spider->connection_ids[link_idx])
+ {
+ my_message(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM,
+ ER_SPIDER_REMOTE_SERVER_GONE_AWAY_STR, MYF(0));
+/*
+ if (!conn->mta_conn_mutex_unlock_later)
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
+*/
+ DBUG_RETURN(ER_SPIDER_REMOTE_SERVER_GONE_AWAY_NUM);
+ }
+ if (!result_list->current)
+ {
+ if (!result_list->first)
+ {
+ if (!(result_list->first = (SPIDER_RESULT *)
+ spider_malloc(spider_current_trx, 4, sizeof(*result_list->first),
+ MYF(MY_WME | MY_ZEROFILL)))
+ ) {
+/*
+ if (!conn->mta_conn_mutex_unlock_later)
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
+*/
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ }
+ TMP_TABLE_PARAM *tmp_tbl_prm = (TMP_TABLE_PARAM *)
+ &result_list->first->result_tmp_tbl_prm;
+ tmp_tbl_prm->init();
+ tmp_tbl_prm->field_count = 3;
+ result_list->last = result_list->first;
+ result_list->current = result_list->first;
+ } else {
+ result_list->current = result_list->first;
+ }
+ result_list->bgs_current = result_list->current;
+ current = (SPIDER_RESULT*) result_list->current;
+ } else {
+ if (
+#ifndef WITHOUT_SPIDER_BG_SEARCH
+ result_list->bgs_phase > 0 ||
+#endif
+ result_list->quick_phase > 0
+ ) {
+ if (result_list->bgs_current == result_list->last)
+ {
+ if (!(result_list->last = (SPIDER_RESULT *)
+ spider_malloc(spider_current_trx, 5, sizeof(*result_list->last),
+ MYF(MY_WME | MY_ZEROFILL)))
+ ) {
+/*
+ if (!conn->mta_conn_mutex_unlock_later)
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
+*/
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ }
+ TMP_TABLE_PARAM *tmp_tbl_prm = (TMP_TABLE_PARAM *)
+ &result_list->last->result_tmp_tbl_prm;
+ tmp_tbl_prm->init();
+ tmp_tbl_prm->field_count = 3;
+ result_list->bgs_current->next = result_list->last;
+ result_list->last->prev = result_list->bgs_current;
+ result_list->bgs_current = result_list->last;
+ } else {
+ result_list->bgs_current = result_list->bgs_current->next;
+ }
+ if (
+#ifndef WITHOUT_SPIDER_BG_SEARCH
+ result_list->bgs_phase == 1 ||
+#endif
+ result_list->quick_phase == 2
+ ) {
+ result_list->current = result_list->bgs_current;
+ result_list->quick_phase = 0;
+ }
+ current = (SPIDER_RESULT*) result_list->bgs_current;
+ } else {
+ if (result_list->current == result_list->last)
+ {
+ if (!(result_list->last = (SPIDER_RESULT *)
+ spider_malloc(spider_current_trx, 6, sizeof(*result_list->last),
+ MYF(MY_WME | MY_ZEROFILL)))
+ ) {
+/*
+ if (!conn->mta_conn_mutex_unlock_later)
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
+*/
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ }
+ TMP_TABLE_PARAM *tmp_tbl_prm = (TMP_TABLE_PARAM *)
+ &result_list->last->result_tmp_tbl_prm;
+ tmp_tbl_prm->init();
+ tmp_tbl_prm->field_count = 3;
+ result_list->current->next = result_list->last;
+ result_list->last->prev = result_list->current;
+ result_list->current = result_list->last;
+ } else {
+ result_list->current = result_list->current->next;
+ }
+ result_list->bgs_current = result_list->current;
+ current = (SPIDER_RESULT*) result_list->current;
+ }
+ }
+
+ if (result_list->quick_mode == 0)
+ {
+ if (spider_bit_is_set(spider->db_request_phase, link_idx))
+ {
+ spider_clear_bit(spider->db_request_phase, link_idx);
+ }
+ current->result = current->prev->result;
+ current->result->set_limit(result_list->limit_num);
+/*
+ if (!conn->mta_conn_mutex_unlock_later)
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
+*/
+ current->record_num = current->result->num_rows();
+ current->dbton_id = current->result->dbton_id;
+ result_list->record_num += current->record_num;
+ DBUG_PRINT("info",("spider current->record_num=%lld",
+ current->record_num));
+ DBUG_PRINT("info",("spider result_list->record_num=%lld",
+ result_list->record_num));
+ DBUG_PRINT("info",("spider result_list->internal_limit=%lld",
+ result_list->internal_limit));
+ DBUG_PRINT("info",("spider result_list->split_read=%lld",
+ result_list->split_read));
+ if (
+ result_list->internal_limit <= result_list->record_num ||
+ result_list->split_read > current->record_num
+ ) {
+ DBUG_PRINT("info",("spider set finish_flg point 2"));
+ DBUG_PRINT("info",("spider current->finish_flg = TRUE"));
+ DBUG_PRINT("info",("spider result_list->finish_flg = TRUE"));
+ current->finish_flg = TRUE;
+ result_list->finish_flg = TRUE;
+ }
+#ifndef WITHOUT_SPIDER_BG_SEARCH
+ if (result_list->bgs_phase <= 1)
+ {
+#endif
+ result_list->current_row_num = 0;
+#ifndef WITHOUT_SPIDER_BG_SEARCH
+ }
+#endif
+ } else {
+ /* has_result() for case of result with result_tmp_tbl */
+ if (current->prev && current->prev->result &&
+ current->prev->result->has_result())
+ {
+ current->result = current->prev->result;
+ current->result->set_limit(result_list->limit_num);
+ current->prev->result = NULL;
+ result_list->limit_num -= current->prev->record_num;
+/*
+ if (!conn->mta_conn_mutex_unlock_later)
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
+*/
+ } else {
+ if (spider_bit_is_set(spider->db_request_phase, link_idx))
+ {
+ spider_clear_bit(spider->db_request_phase, link_idx);
+ }
+ current->result = current->prev->result;
+ current->result->set_limit(result_list->limit_num);
+ DBUG_PRINT("info", ("spider conn[%p]->quick_target=%p", conn, spider));
+ conn->quick_target = spider;
+ spider->quick_targets[link_idx] = spider;
+/*
+ if (!conn->mta_conn_mutex_unlock_later)
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
+*/
+ }
+ current->dbton_id = current->result->dbton_id;
+ SPIDER_DB_ROW *row;
+ if (!(row = current->result->fetch_row()))
+ {
+ error_num = current->result->get_errno();
+ DBUG_PRINT("info",("spider set finish_flg point 3"));
+ DBUG_PRINT("info",("spider current->finish_flg = TRUE"));
+ DBUG_PRINT("info",("spider result_list->finish_flg = TRUE"));
+ current->finish_flg = TRUE;
+ result_list->finish_flg = TRUE;
+ current->result->free_result();
+ delete current->result;
+ current->result = NULL;
+ DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL", conn));
+ conn->quick_target = NULL;
+ spider->quick_targets[link_idx] = NULL;
+ if (
+#ifndef WITHOUT_SPIDER_BG_SEARCH
+ result_list->bgs_phase <= 1 &&
+#endif
+ result_list->quick_phase == 0
+ ) {
+ result_list->current_row_num = 0;
+ table->status = STATUS_NOT_FOUND;
+ }
+ if (error_num)
+ DBUG_RETURN(error_num);
+ else if (result_list->quick_phase > 0)
+ DBUG_RETURN(0);
+ DBUG_RETURN(HA_ERR_END_OF_FILE);
+ }
+ SPIDER_DB_ROW *tmp_row;
+ uint field_count = current->result->num_fields();
+ SPIDER_POSITION *position;
+ longlong page_size;
+ int roop_count = 0;
+ if (!result_list->quick_page_size)
+ {
+ if (result_list->quick_mode == 3)
+ {
+ page_size = 0;
+ } else {
+ result_list->quick_page_size = result_list->limit_num;
+ page_size = result_list->limit_num;
+ }
+ } else {
+ page_size =
+ result_list->limit_num < result_list->quick_page_size ?
+ result_list->limit_num : result_list->quick_page_size;
+ }
+ current->field_count = field_count;
+ if (!(position = (SPIDER_POSITION *)
+ spider_bulk_malloc(spider_current_trx, 7, MYF(MY_WME | MY_ZEROFILL),
+ &position, (uint) (sizeof(SPIDER_POSITION) * page_size),
+ &tmp_row, (uint) (sizeof(SPIDER_DB_ROW) * field_count),
+ NullS))
+ )
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ current->pos_page_size = (int) page_size;
+ current->first_position = position;
+ current->tmp_tbl_row = tmp_row;
+ if (result_list->quick_mode == 3)
+ {
+ while (page_size > roop_count && row)
+ {
+ if (result_list->quick_page_byte < row->get_byte_size())
+ {
+ current->pos_page_size = roop_count;
+ page_size = roop_count;
+ result_list->quick_page_size = roop_count;
+ result_list->quick_page_byte = 0;
+ break;
+ } else {
+ result_list->quick_page_byte -= row->get_byte_size();
+ }
+ if (!(position->row = row->clone()))
+ {
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ }
+ position++;
+ roop_count++;
+ row = current->result->fetch_row();
+ }
+ } else {
+ do {
+ if (!(position->row = row->clone()))
+ {
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ }
+ position++;
+ roop_count++;
+ if (result_list->quick_page_byte < row->get_byte_size())
+ {
+ current->pos_page_size = roop_count;
+ page_size = roop_count;
+ result_list->quick_page_size = roop_count;
+ result_list->quick_page_byte = 0;
+ break;
+ } else {
+ result_list->quick_page_byte -= row->get_byte_size();
+ }
+ } while (
+ page_size > roop_count &&
+ (row = current->result->fetch_row())
+ );
+ }
+ if (
+ result_list->quick_mode == 3 &&
+ page_size == roop_count &&
+ result_list->limit_num > roop_count &&
+ row
+ ) {
+ THD *thd = current_thd;
+ char buf[MAX_FIELD_WIDTH];
+ spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin);
+ tmp_str.init_calc_mem(120);
+
+ DBUG_PRINT("info",("spider store result to temporary table"));
+ DBUG_ASSERT(!current->result_tmp_tbl);
+#ifdef SPIDER_use_LEX_CSTRING_for_Field_blob_constructor
+ LEX_CSTRING field_name1 = {STRING_WITH_LEN("a")};
+ LEX_CSTRING field_name2 = {STRING_WITH_LEN("b")};
+ LEX_CSTRING field_name3 = {STRING_WITH_LEN("c")};
+ if (!(current->result_tmp_tbl = spider_mk_sys_tmp_table_for_result(
+ thd, table, &current->result_tmp_tbl_prm, &field_name1, &field_name2,
+ &field_name3, &my_charset_bin)))
+#else
+ if (!(current->result_tmp_tbl = spider_mk_sys_tmp_table_for_result(
+ thd, table, &current->result_tmp_tbl_prm, "a", "b", "c",
+ &my_charset_bin)))
+#endif
+ {
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ }
+ current->result_tmp_tbl_thd = thd;
+ TABLE *tmp_tbl = current->result_tmp_tbl;
+ tmp_tbl->file->extra(HA_EXTRA_WRITE_CACHE);
+ tmp_tbl->file->ha_start_bulk_insert((ha_rows) 0);
+ do {
+ if ((error_num = row->store_to_tmp_table(tmp_tbl, &tmp_str)))
+ {
+ tmp_tbl->file->ha_end_bulk_insert();
+ DBUG_RETURN(error_num);
+ }
+ roop_count++;
+ } while (
+ result_list->limit_num > roop_count &&
+ (row = current->result->fetch_row())
+ );
+ tmp_tbl->file->ha_end_bulk_insert();
+ page_size = result_list->limit_num;
+ }
+ current->record_num = roop_count;
+ result_list->record_num += roop_count;
+ if (
+ result_list->internal_limit <= result_list->record_num ||
+ page_size > roop_count ||
+ (
+ result_list->quick_mode == 3 &&
+ result_list->limit_num > roop_count
+ )
+ ) {
+ DBUG_PRINT("info",("spider set finish_flg point 4"));
+ DBUG_PRINT("info",("spider current->finish_flg = TRUE"));
+ DBUG_PRINT("info",("spider result_list->finish_flg = TRUE"));
+ current->finish_flg = TRUE;
+ result_list->finish_flg = TRUE;
+ current->result->free_result();
+ if (!current->result_tmp_tbl)
+ {
+ delete current->result;
+ current->result = NULL;
+ }
+ DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL", conn));
+ conn->quick_target = NULL;
+ spider->quick_targets[link_idx] = NULL;
+ } else if (
+ result_list->quick_mode == 3 ||
+ result_list->limit_num == roop_count
+ ) {
+ current->result->free_result();
+ if (!current->result_tmp_tbl)
+ {
+ delete current->result;
+ current->result = NULL;
+ }
+ DBUG_PRINT("info", ("spider conn[%p]->quick_target=NULL", conn));
+ conn->quick_target = NULL;
+ spider->quick_targets[link_idx] = NULL;
+ }
+#ifndef WITHOUT_SPIDER_BG_SEARCH
+ DBUG_PRINT("info", ("spider bgs_phase=%d", result_list->bgs_phase));
+#endif
+ DBUG_PRINT("info", ("spider quick_phase=%d", result_list->quick_phase));
+ if (
+#ifndef WITHOUT_SPIDER_BG_SEARCH
+ result_list->bgs_phase <= 1 &&
+#endif
+ result_list->quick_phase == 0
+ ) {
+ result_list->current_row_num = 0;
+ }
+ DBUG_PRINT("info", ("spider result_list->current=%p", result_list->current));
+ DBUG_PRINT("info", ("spider current=%p", current));
+ DBUG_PRINT("info", ("spider first_position=%p", current->first_position));
+ DBUG_PRINT("info", ("spider current_row_num=%lld", result_list->current_row_num));
+ DBUG_PRINT("info", ("spider first_position[]=%p", &current->first_position[result_list->current_row_num]));
+ DBUG_PRINT("info", ("spider row=%p", current->first_position[result_list->current_row_num].row));
+ }
+ DBUG_RETURN(0);
+}
+
void spider_db_discard_result(
ha_spider *spider,
int link_idx,
@@ -4818,65 +5242,82 @@ int spider_db_seek_next(
pthread_mutex_lock(&conn->mta_conn_mutex);
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
}
- conn->need_mon = &spider->need_mons[link_idx];
- conn->mta_conn_mutex_lock_already = TRUE;
- conn->mta_conn_mutex_unlock_later = TRUE;
- if ((error_num = spider_db_set_names(spider, conn, link_idx)))
+ if (conn->db_conn->limit_mode() == 1)
{
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
+ conn->db_conn->set_limit(result_list->limit_num);
+ if (fields->is_first_link_ok_chain(link_idx_chain))
+ {
+ if ((error_num = spider_db_store_result_for_reuse_cursor(
+ spider, link_idx, table)))
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ DBUG_RETURN(error_num);
+ }
+ }
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
- pthread_mutex_unlock(&conn->mta_conn_mutex);
- if (
- spider->need_mons[link_idx]
- ) {
- error_num = fields->ping_table_mon_from_table(link_idx_chain);
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ } else {
+ conn->need_mon = &spider->need_mons[link_idx];
+ conn->mta_conn_mutex_lock_already = TRUE;
+ conn->mta_conn_mutex_unlock_later = TRUE;
+ if ((error_num = spider_db_set_names(spider, conn, link_idx)))
+ {
+ conn->mta_conn_mutex_lock_already = FALSE;
+ conn->mta_conn_mutex_unlock_later = FALSE;
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ if (
+ spider->need_mons[link_idx]
+ ) {
+ error_num = fields->ping_table_mon_from_table(link_idx_chain);
+ }
+ DBUG_PRINT("info",("spider error_num 7a=%d", error_num));
+ DBUG_RETURN(error_num);
}
- DBUG_PRINT("info",("spider error_num 7a=%d", error_num));
- DBUG_RETURN(error_num);
- }
- spider_conn_set_timeout_from_share(conn, link_idx,
- spider->wide_handler->trx->thd, share);
- if (dbton_handler->execute_sql(
- sql_type,
- conn,
- result_list->quick_mode,
- &spider->need_mons[link_idx])
- ) {
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
- error_num = spider_db_errorno(conn);
- if (
- spider->need_mons[link_idx]
+ spider_conn_set_timeout_from_share(conn, link_idx,
+ spider->wide_handler->trx->thd, share);
+ if (dbton_handler->execute_sql(
+ sql_type,
+ conn,
+ result_list->quick_mode,
+ &spider->need_mons[link_idx])
) {
- error_num = fields->ping_table_mon_from_table(link_idx_chain);
- }
- DBUG_PRINT("info",("spider error_num 8a=%d", error_num));
- DBUG_RETURN(error_num);
- }
- spider->connection_ids[link_idx] = conn->connection_id;
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
- if (fields->is_first_link_ok_chain(link_idx_chain))
- {
- if ((error_num = spider_db_store_result(spider, link_idx,
- table)))
- {
+ conn->mta_conn_mutex_lock_already = FALSE;
+ conn->mta_conn_mutex_unlock_later = FALSE;
+ error_num = spider_db_errorno(conn);
if (
- error_num != HA_ERR_END_OF_FILE &&
spider->need_mons[link_idx]
) {
- error_num =
- fields->ping_table_mon_from_table(link_idx_chain);
+ error_num = fields->ping_table_mon_from_table(link_idx_chain);
}
- DBUG_PRINT("info",("spider error_num 9a=%d", error_num));
+ DBUG_PRINT("info",("spider error_num 8a=%d", error_num));
DBUG_RETURN(error_num);
}
- spider->result_link_idx = link_ok;
- } else {
- spider_db_discard_result(spider, link_idx, conn);
- SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
- pthread_mutex_unlock(&conn->mta_conn_mutex);
+ spider->connection_ids[link_idx] = conn->connection_id;
+ conn->mta_conn_mutex_lock_already = FALSE;
+ conn->mta_conn_mutex_unlock_later = FALSE;
+ if (fields->is_first_link_ok_chain(link_idx_chain))
+ {
+ if ((error_num = spider_db_store_result(spider, link_idx,
+ table)))
+ {
+ if (
+ error_num != HA_ERR_END_OF_FILE &&
+ spider->need_mons[link_idx]
+ ) {
+ error_num =
+ fields->ping_table_mon_from_table(link_idx_chain);
+ }
+ DBUG_PRINT("info",("spider error_num 9a=%d", error_num));
+ DBUG_RETURN(error_num);
+ }
+ spider->result_link_idx = link_ok;
+ } else {
+ spider_db_discard_result(spider, link_idx, conn);
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
}
}
} else {
@@ -4912,84 +5353,67 @@ int spider_db_seek_next(
pthread_mutex_lock(&conn->mta_conn_mutex);
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
}
- conn->need_mon = &spider->need_mons[roop_count];
- conn->mta_conn_mutex_lock_already = TRUE;
- conn->mta_conn_mutex_unlock_later = TRUE;
- if ((error_num = spider_db_set_names(spider, conn, roop_count)))
+ if (conn->db_conn->limit_mode() == 1)
{
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
+ conn->db_conn->set_limit(result_list->limit_num);
+ if (roop_count == link_ok)
+ {
+ if ((error_num = spider_db_store_result_for_reuse_cursor(
+ spider, link_idx, table)))
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ DBUG_RETURN(error_num);
+ }
+ }
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
- pthread_mutex_unlock(&conn->mta_conn_mutex);
- if (
- share->monitoring_kind[roop_count] &&
- spider->need_mons[roop_count]
- ) {
- error_num = spider_ping_table_mon_from_table(
- spider->wide_handler->trx,
- spider->wide_handler->trx->thd,
- share,
- roop_count,
- (uint32) share->monitoring_sid[roop_count],
- share->table_name,
- share->table_name_length,
- spider->conn_link_idx[roop_count],
- NULL,
- 0,
- share->monitoring_kind[roop_count],
- share->monitoring_limit[roop_count],
- share->monitoring_flag[roop_count],
- TRUE
- );
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ } else {
+ conn->need_mon = &spider->need_mons[roop_count];
+ conn->mta_conn_mutex_lock_already = TRUE;
+ conn->mta_conn_mutex_unlock_later = TRUE;
+ if ((error_num = spider_db_set_names(spider, conn, roop_count)))
+ {
+ conn->mta_conn_mutex_lock_already = FALSE;
+ conn->mta_conn_mutex_unlock_later = FALSE;
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ if (
+ share->monitoring_kind[roop_count] &&
+ spider->need_mons[roop_count]
+ ) {
+ error_num = spider_ping_table_mon_from_table(
+ spider->wide_handler->trx,
+ spider->wide_handler->trx->thd,
+ share,
+ roop_count,
+ (uint32) share->monitoring_sid[roop_count],
+ share->table_name,
+ share->table_name_length,
+ spider->conn_link_idx[roop_count],
+ NULL,
+ 0,
+ share->monitoring_kind[roop_count],
+ share->monitoring_limit[roop_count],
+ share->monitoring_flag[roop_count],
+ TRUE
+ );
+ }
+ DBUG_PRINT("info",("spider error_num 7=%d", error_num));
+ DBUG_RETURN(error_num);
}
- DBUG_PRINT("info",("spider error_num 7=%d", error_num));
- DBUG_RETURN(error_num);
- }
- spider_conn_set_timeout_from_share(conn, roop_count,
- spider->wide_handler->trx->thd, share);
- if (dbton_handler->execute_sql(
- sql_type,
- conn,
- result_list->quick_mode,
- &spider->need_mons[roop_count])
- ) {
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
- error_num = spider_db_errorno(conn);
- if (
- share->monitoring_kind[roop_count] &&
- spider->need_mons[roop_count]
+ spider_conn_set_timeout_from_share(conn, roop_count,
+ spider->wide_handler->trx->thd, share);
+ if (dbton_handler->execute_sql(
+ sql_type,
+ conn,
+ result_list->quick_mode,
+ &spider->need_mons[roop_count])
) {
- error_num = spider_ping_table_mon_from_table(
- spider->wide_handler->trx,
- spider->wide_handler->trx->thd,
- share,
- roop_count,
- (uint32) share->monitoring_sid[roop_count],
- share->table_name,
- share->table_name_length,
- spider->conn_link_idx[roop_count],
- NULL,
- 0,
- share->monitoring_kind[roop_count],
- share->monitoring_limit[roop_count],
- share->monitoring_flag[roop_count],
- TRUE
- );
- }
- DBUG_PRINT("info",("spider error_num 8=%d", error_num));
- DBUG_RETURN(error_num);
- }
- spider->connection_ids[roop_count] = conn->connection_id;
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
- if (roop_count == link_ok)
- {
- if ((error_num = spider_db_store_result(spider, roop_count,
- table)))
- {
+ conn->mta_conn_mutex_lock_already = FALSE;
+ conn->mta_conn_mutex_unlock_later = FALSE;
+ error_num = spider_db_errorno(conn);
if (
- error_num != HA_ERR_END_OF_FILE &&
share->monitoring_kind[roop_count] &&
spider->need_mons[roop_count]
) {
@@ -5010,14 +5434,48 @@ int spider_db_seek_next(
TRUE
);
}
- DBUG_PRINT("info",("spider error_num 9=%d", error_num));
+ DBUG_PRINT("info",("spider error_num 8=%d", error_num));
DBUG_RETURN(error_num);
}
- spider->result_link_idx = link_ok;
- } else {
- spider_db_discard_result(spider, roop_count, conn);
- SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
- pthread_mutex_unlock(&conn->mta_conn_mutex);
+ spider->connection_ids[roop_count] = conn->connection_id;
+ conn->mta_conn_mutex_lock_already = FALSE;
+ conn->mta_conn_mutex_unlock_later = FALSE;
+ if (roop_count == link_ok)
+ {
+ if ((error_num = spider_db_store_result(spider, roop_count,
+ table)))
+ {
+ if (
+ error_num != HA_ERR_END_OF_FILE &&
+ share->monitoring_kind[roop_count] &&
+ spider->need_mons[roop_count]
+ ) {
+ error_num = spider_ping_table_mon_from_table(
+ spider->wide_handler->trx,
+ spider->wide_handler->trx->thd,
+ share,
+ roop_count,
+ (uint32) share->monitoring_sid[roop_count],
+ share->table_name,
+ share->table_name_length,
+ spider->conn_link_idx[roop_count],
+ NULL,
+ 0,
+ share->monitoring_kind[roop_count],
+ share->monitoring_limit[roop_count],
+ share->monitoring_flag[roop_count],
+ TRUE
+ );
+ }
+ DBUG_PRINT("info",("spider error_num 9=%d", error_num));
+ DBUG_RETURN(error_num);
+ }
+ spider->result_link_idx = link_ok;
+ } else {
+ spider_db_discard_result(spider, roop_count, conn);
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
}
}
#ifdef SPIDER_HAS_GROUP_BY_HANDLER
@@ -5166,82 +5624,67 @@ int spider_db_seek_last(
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
}
DBUG_PRINT("info",("spider sql_type=%lu", sql_type));
- conn->need_mon = &spider->need_mons[roop_count];
- conn->mta_conn_mutex_lock_already = TRUE;
- conn->mta_conn_mutex_unlock_later = TRUE;
- if ((error_num = spider_db_set_names(spider, conn, roop_count)))
+ if (conn->db_conn->limit_mode() == 1)
{
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
+ conn->db_conn->set_limit(result_list->limit_num);
+ if (roop_count == link_ok)
+ {
+ if ((error_num = spider_db_store_result_for_reuse_cursor(
+ spider, roop_count, table)))
+ {
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ DBUG_RETURN(error_num);
+ }
+ }
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
- pthread_mutex_unlock(&conn->mta_conn_mutex);
- if (
- share->monitoring_kind[roop_count] &&
- spider->need_mons[roop_count]
- ) {
- error_num = spider_ping_table_mon_from_table(
- spider->wide_handler->trx,
- spider->wide_handler->trx->thd,
- share,
- roop_count,
- (uint32) share->monitoring_sid[roop_count],
- share->table_name,
- share->table_name_length,
- spider->conn_link_idx[roop_count],
- NULL,
- 0,
- share->monitoring_kind[roop_count],
- share->monitoring_limit[roop_count],
- share->monitoring_flag[roop_count],
- TRUE
- );
+ pthread_mutex_unlock(&conn->bg_conn_mutex);
+ } else {
+ conn->need_mon = &spider->need_mons[roop_count];
+ conn->mta_conn_mutex_lock_already = TRUE;
+ conn->mta_conn_mutex_unlock_later = TRUE;
+ if ((error_num = spider_db_set_names(spider, conn, roop_count)))
+ {
+ conn->mta_conn_mutex_lock_already = FALSE;
+ conn->mta_conn_mutex_unlock_later = FALSE;
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ if (
+ share->monitoring_kind[roop_count] &&
+ spider->need_mons[roop_count]
+ ) {
+ error_num = spider_ping_table_mon_from_table(
+ spider->wide_handler->trx,
+ spider->wide_handler->trx->thd,
+ share,
+ roop_count,
+ (uint32) share->monitoring_sid[roop_count],
+ share->table_name,
+ share->table_name_length,
+ spider->conn_link_idx[roop_count],
+ NULL,
+ 0,
+ share->monitoring_kind[roop_count],
+ share->monitoring_limit[roop_count],
+ share->monitoring_flag[roop_count],
+ TRUE
+ );
+ }
+ DBUG_RETURN(error_num);
}
- DBUG_RETURN(error_num);
- }
- spider_conn_set_timeout_from_share(conn, roop_count,
- spider->wide_handler->trx->thd,
- share);
- if (dbton_handler->execute_sql(
- sql_type,
- conn,
- result_list->quick_mode,
- &spider->need_mons[roop_count])
- ) {
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
- error_num = spider_db_errorno(conn);
- if (
- share->monitoring_kind[roop_count] &&
- spider->need_mons[roop_count]
+ spider_conn_set_timeout_from_share(conn, roop_count,
+ spider->wide_handler->trx->thd,
+ share);
+ if (dbton_handler->execute_sql(
+ sql_type,
+ conn,
+ result_list->quick_mode,
+ &spider->need_mons[roop_count])
) {
- error_num = spider_ping_table_mon_from_table(
- spider->wide_handler->trx,
- spider->wide_handler->trx->thd,
- share,
- roop_count,
- (uint32) share->monitoring_sid[roop_count],
- share->table_name,
- share->table_name_length,
- spider->conn_link_idx[roop_count],
- NULL,
- 0,
- share->monitoring_kind[roop_count],
- share->monitoring_limit[roop_count],
- share->monitoring_flag[roop_count],
- TRUE
- );
- }
- DBUG_RETURN(error_num);
- }
- spider->connection_ids[roop_count] = conn->connection_id;
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
- if (roop_count == link_ok)
- {
- if ((error_num = spider_db_store_result(spider, roop_count, table)))
- {
+ conn->mta_conn_mutex_lock_already = FALSE;
+ conn->mta_conn_mutex_unlock_later = FALSE;
+ error_num = spider_db_errorno(conn);
if (
- error_num != HA_ERR_END_OF_FILE &&
share->monitoring_kind[roop_count] &&
spider->need_mons[roop_count]
) {
@@ -5264,11 +5707,43 @@ int spider_db_seek_last(
}
DBUG_RETURN(error_num);
}
- spider->result_link_idx = link_ok;
- } else {
- spider_db_discard_result(spider, roop_count, conn);
- SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
- pthread_mutex_unlock(&conn->mta_conn_mutex);
+ spider->connection_ids[roop_count] = conn->connection_id;
+ conn->mta_conn_mutex_lock_already = FALSE;
+ conn->mta_conn_mutex_unlock_later = FALSE;
+ if (roop_count == link_ok)
+ {
+ if ((error_num = spider_db_store_result(spider, roop_count, table)))
+ {
+ if (
+ error_num != HA_ERR_END_OF_FILE &&
+ share->monitoring_kind[roop_count] &&
+ spider->need_mons[roop_count]
+ ) {
+ error_num = spider_ping_table_mon_from_table(
+ spider->wide_handler->trx,
+ spider->wide_handler->trx->thd,
+ share,
+ roop_count,
+ (uint32) share->monitoring_sid[roop_count],
+ share->table_name,
+ share->table_name_length,
+ spider->conn_link_idx[roop_count],
+ NULL,
+ 0,
+ share->monitoring_kind[roop_count],
+ share->monitoring_limit[roop_count],
+ share->monitoring_flag[roop_count],
+ TRUE
+ );
+ }
+ DBUG_RETURN(error_num);
+ }
+ spider->result_link_idx = link_ok;
+ } else {
+ spider_db_discard_result(spider, roop_count, conn);
+ SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
+ pthread_mutex_unlock(&conn->mta_conn_mutex);
+ }
}
}
result_list->current_row_num = result_list->current->record_num - 1;
@@ -5994,14 +6469,19 @@ void spider_db_set_cardinarity(
{
key_part = &key_info->key_part[roop_count2];
field = key_part->field;
- rec_per_key = (ha_rows) share->stat.records /
- share->cardinality[field->field_index];
- if (rec_per_key > ~(ulong) 0)
- key_info->rec_per_key[roop_count2] = ~(ulong) 0;
- else if (rec_per_key == 0)
+ if (share->cardinality[field->field_index])
+ {
+ rec_per_key = (ha_rows) share->stat.records /
+ share->cardinality[field->field_index];
+ if (rec_per_key > ~(ulong) 0)
+ key_info->rec_per_key[roop_count2] = ~(ulong) 0;
+ else if (rec_per_key == 0)
+ key_info->rec_per_key[roop_count2] = 1;
+ else
+ key_info->rec_per_key[roop_count2] = (ulong) rec_per_key;
+ } else {
key_info->rec_per_key[roop_count2] = 1;
- else
- key_info->rec_per_key[roop_count2] = (ulong) rec_per_key;
+ }
DBUG_PRINT("info",
("spider column id=%d", field->field_index));
DBUG_PRINT("info",
@@ -7149,7 +7629,7 @@ int spider_db_direct_update(
SQL access -> SQL remote access with dirct_update
spider->do_direct_update &&
spider->direct_update_kinds == SPIDER_SQL_KIND_SQL &&
- spider->direct_update_fields
+ spider->wide_handler->direct_update_fields
Handlersocket access -> SQL remote access with dirct_update
spider->do_direct_update &&
@@ -7468,7 +7948,7 @@ int spider_db_direct_update(
SQL access -> SQL remote access with dirct_update
spider->do_direct_update &&
spider->direct_update_kinds == SPIDER_SQL_KIND_SQL &&
- spider->direct_update_fields
+ spider->wide_handler->direct_update_fields
*/
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
@@ -9581,7 +10061,9 @@ int spider_db_open_item_string(
goto end;
}
}
- if (str->charset() != tmp_str2->charset())
+ DBUG_PRINT("info",("spider dbton_id=%u", dbton_id));
+ if (str->charset() != tmp_str2->charset() &&
+ spider_dbton[dbton_id].db_util->append_charset_name_before_string())
{
if ((error_num = spider_db_append_charset_name_before_string(str,
tmp_str2->charset())))
@@ -9968,6 +10450,31 @@ int spider_db_append_update_columns(
}
#endif
+#ifdef HANDLER_HAS_DIRECT_AGGREGATE
+bool spider_db_check_select_colum_in_group(
+ st_select_lex *select_lex,
+ Field *field
+) {
+ ORDER *group;
+ DBUG_ENTER("spider_db_check_select_colum_in_group");
+ for (group = (ORDER *) select_lex->group_list.first; group;
+ group = group->next)
+ {
+ Item *item = *group->item;
+ if (item->type() == Item::FIELD_ITEM)
+ {
+ Item_field *item_field = (Item_field *) item;
+ if (item_field->field == field)
+ {
+ /* This field can be used directly */
+ DBUG_RETURN(TRUE);
+ }
+ }
+ }
+ DBUG_RETURN(FALSE);
+}
+#endif
+
uint spider_db_check_ft_idx(
Item_func *item_func,
ha_spider *spider
@@ -10594,10 +11101,12 @@ int spider_db_udf_direct_sql_select_db(
bool tmp_mta_conn_mutex_lock_already;
SPIDER_DB_CONN *db_conn = conn->db_conn;
DBUG_ENTER("spider_db_udf_direct_sql_select_db");
+ if (
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- if (direct_sql->access_mode == 0)
- {
+ direct_sql->access_mode == 0 &&
#endif
+ spider_dbton[conn->dbton_id].db_util->database_has_default_value()
+ ) {
if (!conn->mta_conn_mutex_lock_already)
{
pthread_mutex_lock(&conn->mta_conn_mutex);
@@ -10644,9 +11153,7 @@ int spider_db_udf_direct_sql_select_db(
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
pthread_mutex_unlock(&conn->mta_conn_mutex);
}
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
}
-#endif
DBUG_RETURN(0);
}
@@ -10990,28 +11497,41 @@ int spider_db_udf_ping_table_append_select(
str->q_append(SPIDER_SQL_SELECT_STR, SPIDER_SQL_SELECT_LEN);
str->q_append(SPIDER_SQL_ONE_STR, SPIDER_SQL_ONE_LEN);
str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN);
- if ((error_num = spider_db_append_name_with_quote_str(str,
- share->tgt_dbs[0], dbton_id)))
- DBUG_RETURN(error_num);
- if (str->reserve(SPIDER_SQL_DOT_LEN))
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN);
+ if (share->tgt_dbs[0])
+ {
+ if ((error_num = spider_db_append_name_with_quote_str(str,
+ share->tgt_dbs[0], dbton_id)))
+ DBUG_RETURN(error_num);
+ if (str->reserve(SPIDER_SQL_DOT_LEN))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ str->q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN);
+ }
if ((error_num = spider_db_append_name_with_quote_str(str,
share->tgt_table_names[0], share->sql_dbton_ids[0])))
DBUG_RETURN(error_num);
- limit_str_length = my_sprintf(limit_str, (limit_str, "%lld", limit));
- if (str->reserve(
- (use_where ? (where_str->length() * 2) : 0) +
- SPIDER_SQL_LIMIT_LEN + limit_str_length
- ))
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- if (use_where)
+ if (spider_dbton[dbton_id].db_util->limit_mode() == 1)
{
- str->append_escape_string(where_str->ptr(), where_str->length());
+ if (use_where)
+ {
+ if (str->reserve(where_str->length() * 2))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ str->append_escape_string(where_str->ptr(), where_str->length());
+ }
+ } else {
+ limit_str_length = my_sprintf(limit_str, (limit_str, "%lld", limit));
+ if (str->reserve(
+ (use_where ? (where_str->length() * 2) : 0) +
+ SPIDER_SQL_LIMIT_LEN + limit_str_length
+ ))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ if (use_where)
+ {
+ str->append_escape_string(where_str->ptr(), where_str->length());
+ }
+ str->q_append(SPIDER_SQL_LIMIT_STR, SPIDER_SQL_LIMIT_LEN);
+ str->q_append(limit_str, limit_str_length);
}
- str->q_append(SPIDER_SQL_LIMIT_STR, SPIDER_SQL_LIMIT_LEN);
- str->q_append(limit_str, limit_str_length);
DBUG_RETURN(0);
}
diff --git a/storage/spider/spd_db_conn.h b/storage/spider/spd_db_conn.h
index d4e527e4bf2..0b69253c43b 100644
--- a/storage/spider/spd_db_conn.h
+++ b/storage/spider/spd_db_conn.h
@@ -1,5 +1,5 @@
-/* Copyright (C) 2008-2019 Kentoku Shiba
- Copyright (C) 2019 MariaDB corp
+/* Copyright (C) 2008-2020 Kentoku Shiba
+ Copyright (C) 2019-2020 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,6 +40,10 @@
#define SPIDER_SQL_OPEN_PAREN_LEN (sizeof(SPIDER_SQL_OPEN_PAREN_STR) - 1)
#define SPIDER_SQL_CLOSE_PAREN_STR ")"
#define SPIDER_SQL_CLOSE_PAREN_LEN (sizeof(SPIDER_SQL_CLOSE_PAREN_STR) - 1)
+#define SPIDER_SQL_OPEN_BRACE_STR "{"
+#define SPIDER_SQL_OPEN_BRACE_LEN (sizeof(SPIDER_SQL_OPEN_BRACE_STR) - 1)
+#define SPIDER_SQL_CLOSE_BRACE_STR "}"
+#define SPIDER_SQL_CLOSE_BRACE_LEN (sizeof(SPIDER_SQL_CLOSE_BRACE_STR) - 1)
#define SPIDER_SQL_COMMA_STR ","
#define SPIDER_SQL_COMMA_LEN (sizeof(SPIDER_SQL_COMMA_STR) - 1)
#define SPIDER_SQL_UNION_ALL_STR ")union all("
@@ -608,6 +612,12 @@ int spider_db_store_result(
TABLE *table
);
+int spider_db_store_result_for_reuse_cursor(
+ ha_spider *spider,
+ int link_idx,
+ TABLE *table
+);
+
void spider_db_discard_result(
ha_spider *spider,
int link_idx,
@@ -1052,6 +1062,13 @@ int spider_db_append_update_columns(
);
#endif
+#ifdef HANDLER_HAS_DIRECT_AGGREGATE
+bool spider_db_check_select_colum_in_group(
+ st_select_lex *select_lex,
+ Field *field
+);
+#endif
+
uint spider_db_check_ft_idx(
Item_func *item_func,
ha_spider *spider
diff --git a/storage/spider/spd_db_include.cc b/storage/spider/spd_db_include.cc
index c07ab4db3be..b9a0532d1b9 100644
--- a/storage/spider/spd_db_include.cc
+++ b/storage/spider/spd_db_include.cc
@@ -1,4 +1,5 @@
-/* Copyright (C) 2018-2019 Kentoku Shiba
+/* Copyright (C) 2018-2020 Kentoku Shiba
+ Copyright (C) 2018-2020 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,6 +34,8 @@
#include "spd_include.h"
#include "spd_conn.h"
+extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
+
spider_db_result::spider_db_result(
SPIDER_DB_CONN *in_db_conn
) : db_conn(in_db_conn), dbton_id(in_db_conn->dbton_id)
@@ -52,6 +55,13 @@ int spider_db_result::fetch_table_checksum(
}
#endif
+uint spider_db_result::limit_mode()
+{
+ DBUG_ENTER("spider_db_result::limit_mode");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(spider_dbton[dbton_id].db_util->limit_mode());
+}
+
spider_db_conn::spider_db_conn(
SPIDER_CONN *in_conn
) : conn(in_conn), dbton_id(in_conn->dbton_id)
@@ -110,6 +120,13 @@ int spider_db_conn::fin_loop_check()
DBUG_RETURN(0);
}
+uint spider_db_conn::limit_mode()
+{
+ DBUG_ENTER("spider_db_conn::limit_mode");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(spider_dbton[dbton_id].db_util->limit_mode());
+}
+
int spider_db_util::append_loop_check(
spider_string *str,
SPIDER_CONN *conn
@@ -120,6 +137,41 @@ int spider_db_util::append_loop_check(
DBUG_RETURN(0);
}
+bool spider_db_util::tables_on_different_db_are_joinable()
+{
+ DBUG_ENTER("spider_db_util::tables_on_different_db_are_joinable");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(TRUE);
+}
+
+bool spider_db_util::socket_has_default_value()
+{
+ DBUG_ENTER("spider_db_util::socket_has_default_value");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(TRUE);
+}
+
+bool spider_db_util::database_has_default_value()
+{
+ DBUG_ENTER("spider_db_util::database_has_default_value");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(TRUE);
+}
+
+bool spider_db_util::append_charset_name_before_string()
+{
+ DBUG_ENTER("spider_db_util::append_charset_name_before_string");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(FALSE);
+}
+
+uint spider_db_util::limit_mode()
+{
+ DBUG_ENTER("spider_db_util::limit_mode");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(0);
+}
+
#ifdef HA_HAS_CHECKSUM_EXTENDED
bool spider_db_share::checksum_support()
{
@@ -136,3 +188,39 @@ int spider_db_handler::checksum_table(
DBUG_RETURN(0);
}
#endif
+
+#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
+bool spider_db_handler::check_direct_update(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+) {
+ DBUG_ENTER("spider_db_handler::check_direct_update");
+ DBUG_PRINT("info",("spider this=%p", this));
+ if (
+ select_limit != 9223372036854775807LL ||
+ offset_limit != 0 ||
+ select_lex->order_list.elements
+ ) {
+ DBUG_RETURN(TRUE);
+ }
+ DBUG_RETURN(FALSE);
+}
+
+bool spider_db_handler::check_direct_delete(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+) {
+ DBUG_ENTER("spider_db_handler::check_direct_delete");
+ DBUG_PRINT("info",("spider this=%p", this));
+ if (
+ select_limit != 9223372036854775807LL ||
+ offset_limit != 0 ||
+ select_lex->order_list.elements
+ ) {
+ DBUG_RETURN(TRUE);
+ }
+ DBUG_RETURN(FALSE);
+}
+#endif
diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h
index 2460de8456e..76466a0b5e8 100644
--- a/storage/spider/spd_db_include.h
+++ b/storage/spider/spd_db_include.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 2008-2018 Kentoku Shiba
+/* Copyright (C) 2008-2020 Kentoku Shiba
+ Copyright (C) 2019-2020 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -93,6 +94,8 @@ typedef st_spider_result SPIDER_RESULT;
#define SPIDER_SQL_SEMICOLON_STR ";"
#define SPIDER_SQL_SEMICOLON_LEN sizeof(SPIDER_SQL_SEMICOLON_STR) - 1
+#define SPIDER_SQL_COLON_STR ":"
+#define SPIDER_SQL_COLON_LEN sizeof(SPIDER_SQL_COLON_STR) - 1
#define SPIDER_SQL_VALUE_QUOTE_STR "'"
#define SPIDER_SQL_VALUE_QUOTE_LEN (sizeof(SPIDER_SQL_VALUE_QUOTE_STR) - 1)
@@ -953,6 +956,11 @@ public:
spider_string *str
) = 0;
#endif
+ virtual bool tables_on_different_db_are_joinable();
+ virtual bool socket_has_default_value();
+ virtual bool database_has_default_value();
+ virtual bool append_charset_name_before_string();
+ virtual uint limit_mode();
};
class spider_db_row
@@ -1003,12 +1011,12 @@ public:
class spider_db_result
{
-protected:
- SPIDER_DB_CONN *db_conn;
public:
- uint dbton_id;
+ SPIDER_DB_CONN *db_conn;
+ uint dbton_id;
spider_db_result(SPIDER_DB_CONN *in_db_conn);
virtual ~spider_db_result() {}
+ virtual void set_limit(longlong value) {}
virtual bool has_result() = 0;
virtual void free_result() = 0;
virtual SPIDER_DB_ROW *current_row() = 0;
@@ -1063,19 +1071,20 @@ public:
CHARSET_INFO *access_charset
) = 0;
#endif
+ virtual uint limit_mode();
};
class spider_db_conn
{
-protected:
- SPIDER_CONN *conn;
public:
- uint dbton_id;
+ SPIDER_CONN *conn;
+ uint dbton_id;
spider_db_conn(
SPIDER_CONN *in_conn
);
virtual ~spider_db_conn() {}
virtual int init() = 0;
+ virtual void set_limit(longlong value) {}
virtual bool is_connected() = 0;
virtual void bg_connect() = 0;
virtual int connect(
@@ -1282,6 +1291,7 @@ public:
virtual bool cmp_request_key_to_snd(
st_spider_db_request_key *request_key
) = 0;
+ virtual uint limit_mode();
};
class spider_db_share
@@ -1822,6 +1832,18 @@ public:
ulong sql_type
) = 0;
#endif
+#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
+ virtual bool check_direct_update(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+ );
+ virtual bool check_direct_delete(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+ );
+#endif
};
class spider_db_copy_table
diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc
index 6f21ac7bd65..c1da9cb7945 100644
--- a/storage/spider/spd_db_mysql.cc
+++ b/storage/spider/spd_db_mysql.cc
@@ -7272,6 +7272,13 @@ int spider_db_mbase_util::append_having(
}
#endif
+bool spider_db_mbase_util::append_charset_name_before_string()
+{
+ DBUG_ENTER("spider_db_mbase_util::append_charset_name_before_string");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(TRUE);
+}
+
spider_mbase_share::spider_mbase_share(
st_spider_share *share,
uint dbton_id,
@@ -15693,6 +15700,28 @@ int spider_mbase_handler::append_order_by(
}
#endif
+#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
+bool spider_mbase_handler::check_direct_update(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+) {
+ DBUG_ENTER("spider_mbase_handler::check_direct_update");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(FALSE);
+}
+
+bool spider_mbase_handler::check_direct_delete(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+) {
+ DBUG_ENTER("spider_mbase_handler::check_direct_delete");
+ DBUG_PRINT("info",("spider this=%p", this));
+ DBUG_RETURN(FALSE);
+}
+#endif
+
spider_mbase_copy_table::spider_mbase_copy_table(
spider_mbase_share *db_share
) : spider_db_copy_table(
diff --git a/storage/spider/spd_db_mysql.h b/storage/spider/spd_db_mysql.h
index 0c818101883..07f37f4002a 100644
--- a/storage/spider/spd_db_mysql.h
+++ b/storage/spider/spd_db_mysql.h
@@ -199,6 +199,7 @@ public:
spider_string *str
);
#endif
+ bool append_charset_name_before_string();
};
class spider_db_mysql_util: public spider_db_mbase_util
@@ -1672,6 +1673,18 @@ public:
spider_fields *fields
);
#endif
+#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
+ bool check_direct_update(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+ );
+ bool check_direct_delete(
+ st_select_lex *select_lex,
+ longlong select_limit,
+ longlong offset_limit
+ );
+#endif
};
class spider_mysql_handler: public spider_mbase_handler
diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc
index 470bbb3bee7..ee40e8fc36b 100644
--- a/storage/spider/spd_direct_sql.cc
+++ b/storage/spider/spd_direct_sql.cc
@@ -1,5 +1,5 @@
-/* Copyright (C) 2009-2019 Kentoku Shiba
- Copyright (C) 2019 MariaDB corp
+/* Copyright (C) 2009-2020 Kentoku Shiba
+ Copyright (C) 2019-2020 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -206,17 +206,79 @@ int spider_udf_direct_sql_create_conn_key(
char *tmp_name, port_str[6];
DBUG_ENTER("spider_udf_direct_sql_create_conn_key");
- /* tgt_db not use */
+ uint roop_count2;
+ bool tables_on_different_db_are_joinable = TRUE;
+ direct_sql->dbton_id = SPIDER_DBTON_SIZE;
+ DBUG_PRINT("info",("spider direct_sql->tgt_wrapper=%s",
+ direct_sql->tgt_wrapper));
+ for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
+ {
+ DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
+ spider_dbton[roop_count2].wrapper ?
+ spider_dbton[roop_count2].wrapper : "NULL"));
+ if (
+ spider_dbton[roop_count2].wrapper &&
+ !strcmp(direct_sql->tgt_wrapper, spider_dbton[roop_count2].wrapper)
+ ) {
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ if (direct_sql->access_mode == 0)
+ {
+#endif
+ if (spider_dbton[roop_count2].db_access_type ==
+ SPIDER_DB_ACCESS_TYPE_SQL)
+ {
+ direct_sql->dbton_id = roop_count2;
+ break;
+ }
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ } else {
+ if (spider_dbton[roop_count2].db_access_type ==
+ SPIDER_DB_ACCESS_TYPE_NOSQL)
+ {
+ direct_sql->dbton_id = roop_count2;
+ break;
+ }
+ }
+#endif
+ }
+ }
+ if (direct_sql->dbton_id == SPIDER_DBTON_SIZE)
+ {
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ if (direct_sql->access_mode == 0)
+ {
+#endif
+ my_printf_error(
+ ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM,
+ ER_SPIDER_SQL_WRAPPER_IS_INVALID_STR,
+ MYF(0), direct_sql->tgt_wrapper);
+ DBUG_RETURN(ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM);
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ } else {
+ my_printf_error(
+ ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_NUM,
+ ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_STR,
+ MYF(0), direct_sql->tgt_wrapper);
+ DBUG_RETURN(ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_NUM);
+ }
+#endif
+ }
+
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
if (direct_sql->access_mode == 0)
{
#endif
+ tables_on_different_db_are_joinable =
+ spider_dbton[direct_sql->dbton_id].db_util->
+ tables_on_different_db_are_joinable();
direct_sql->conn_key_length
= 1
+ direct_sql->tgt_wrapper_length + 1
+ direct_sql->tgt_host_length + 1
+ 5 + 1
+ direct_sql->tgt_socket_length + 1
+ + (tables_on_different_db_are_joinable ?
+ 0 : direct_sql->tgt_default_db_name_length + 1)
+ direct_sql->tgt_username_length + 1
+ direct_sql->tgt_password_length + 1
+ direct_sql->tgt_ssl_ca_length + 1
@@ -263,6 +325,16 @@ int spider_udf_direct_sql_create_conn_key(
if (direct_sql->access_mode == 0)
{
#endif
+ if (!tables_on_different_db_are_joinable)
+ {
+ if (direct_sql->tgt_default_db_name)
+ {
+ DBUG_PRINT("info",("spider tgt_default_db_name=%s",
+ direct_sql->tgt_default_db_name));
+ tmp_name = strmov(tmp_name + 1, direct_sql->tgt_default_db_name);
+ } else
+ tmp_name++;
+ }
if (direct_sql->tgt_username)
{
DBUG_PRINT("info",("spider tgt_username=%s", direct_sql->tgt_username));
@@ -326,62 +398,6 @@ int spider_udf_direct_sql_create_conn_key(
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
}
#endif
- uint roop_count2;
- direct_sql->dbton_id = SPIDER_DBTON_SIZE;
- DBUG_PRINT("info",("spider direct_sql->tgt_wrapper=%s",
- direct_sql->tgt_wrapper));
- for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
- {
- DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
- spider_dbton[roop_count2].wrapper ?
- spider_dbton[roop_count2].wrapper : "NULL"));
- if (
- spider_dbton[roop_count2].wrapper &&
- !strcmp(direct_sql->tgt_wrapper, spider_dbton[roop_count2].wrapper)
- ) {
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- if (direct_sql->access_mode == 0)
- {
-#endif
- if (spider_dbton[roop_count2].db_access_type ==
- SPIDER_DB_ACCESS_TYPE_SQL)
- {
- direct_sql->dbton_id = roop_count2;
- break;
- }
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- } else {
- if (spider_dbton[roop_count2].db_access_type ==
- SPIDER_DB_ACCESS_TYPE_NOSQL)
- {
- direct_sql->dbton_id = roop_count2;
- break;
- }
- }
-#endif
- }
- }
- if (direct_sql->dbton_id == SPIDER_DBTON_SIZE)
- {
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- if (direct_sql->access_mode == 0)
- {
-#endif
- my_printf_error(
- ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM,
- ER_SPIDER_SQL_WRAPPER_IS_INVALID_STR,
- MYF(0), direct_sql->tgt_wrapper);
- DBUG_RETURN(ER_SPIDER_SQL_WRAPPER_IS_INVALID_NUM);
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- } else {
- my_printf_error(
- ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_NUM,
- ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_STR,
- MYF(0), direct_sql->tgt_wrapper);
- DBUG_RETURN(ER_SPIDER_NOSQL_WRAPPER_IS_INVALID_NUM);
- }
-#endif
- }
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
direct_sql->conn_key_hash_value = my_calc_hash(&spider_open_connections,
(uchar*) direct_sql->conn_key, direct_sql->conn_key_length);
@@ -396,9 +412,10 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn(
SPIDER_CONN *conn;
SPIDER_IP_PORT_CONN *ip_port_conn;
char *tmp_name, *tmp_host, *tmp_username, *tmp_password, *tmp_socket;
- char *tmp_wrapper, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert;
+ char *tmp_wrapper, *tmp_db, *tmp_ssl_ca, *tmp_ssl_capath, *tmp_ssl_cert;
char *tmp_ssl_cipher, *tmp_ssl_key, *tmp_default_file, *tmp_default_group;
int *need_mon;
+ bool tables_on_different_db_are_joinable = TRUE;
DBUG_ENTER("spider_udf_direct_sql_create_conn");
if (unlikely(!UTC))
@@ -412,6 +429,9 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn(
if (direct_sql->access_mode == 0)
{
#endif
+ tables_on_different_db_are_joinable =
+ spider_dbton[direct_sql->dbton_id].db_util->
+ tables_on_different_db_are_joinable();
if (!(conn = (SPIDER_CONN *)
spider_bulk_malloc(spider_current_trx, 32, MYF(MY_WME | MY_ZEROFILL),
&conn, (uint) (sizeof(*conn)),
@@ -421,6 +441,8 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn(
&tmp_password, (uint) (direct_sql->tgt_password_length + 1),
&tmp_socket, (uint) (direct_sql->tgt_socket_length + 1),
&tmp_wrapper, (uint) (direct_sql->tgt_wrapper_length + 1),
+ &tmp_db, (uint) (tables_on_different_db_are_joinable ?
+ 0 : direct_sql->tgt_default_db_name_length + 1),
&tmp_ssl_ca, (uint) (direct_sql->tgt_ssl_ca_length + 1),
&tmp_ssl_capath, (uint) (direct_sql->tgt_ssl_capath_length + 1),
&tmp_ssl_cert, (uint) (direct_sql->tgt_ssl_cert_length + 1),
@@ -475,6 +497,13 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn(
conn->tgt_socket = tmp_socket;
memcpy(conn->tgt_socket, direct_sql->tgt_socket,
direct_sql->tgt_socket_length);
+ if (!tables_on_different_db_are_joinable)
+ {
+ conn->tgt_db_length = direct_sql->tgt_default_db_name_length;
+ conn->tgt_db = tmp_db;
+ memcpy(conn->tgt_db, direct_sql->tgt_default_db_name,
+ direct_sql->tgt_default_db_name_length);
+ }
conn->tgt_username_length = direct_sql->tgt_username_length;
conn->tgt_username = tmp_username;
memcpy(conn->tgt_username, direct_sql->tgt_username,
@@ -1338,6 +1367,10 @@ int spider_udf_set_direct_sql_param_default(
SPIDER_TRX *trx,
SPIDER_DIRECT_SQL *direct_sql
) {
+ bool check_socket;
+ bool check_database;
+ bool socket_has_default_value;
+ bool database_has_default_value;
int error_num, roop_count;
DBUG_ENTER("spider_udf_set_direct_sql_param_default");
if (direct_sql->server_name)
@@ -1346,8 +1379,66 @@ int spider_udf_set_direct_sql_param_default(
DBUG_RETURN(error_num);
}
+ if (
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ direct_sql->access_mode == 0 &&
+#endif
+ !direct_sql->tgt_socket &&
+ (!direct_sql->tgt_host || !strcmp(direct_sql->tgt_host, my_localhost))
+ ) {
+ check_socket = TRUE;
+ } else {
+ check_socket = FALSE;
+ }
if (!direct_sql->tgt_default_db_name)
{
+ check_database = TRUE;
+ } else {
+ check_database = FALSE;
+ }
+ if (check_socket || check_database)
+ {
+ socket_has_default_value = check_socket;
+ database_has_default_value = check_database;
+ if (direct_sql->tgt_wrapper)
+ {
+ for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
+ {
+ DBUG_PRINT("info",("spider direct_sql->tgt_wrapper=%s",
+ direct_sql->tgt_wrapper));
+ DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count,
+ spider_dbton[roop_count].wrapper ?
+ spider_dbton[roop_count].wrapper : "NULL"));
+ if (
+ spider_dbton[roop_count].wrapper &&
+ !strcmp(direct_sql->tgt_wrapper,
+ spider_dbton[roop_count].wrapper)
+ ) {
+ if (spider_dbton[roop_count].db_access_type ==
+ SPIDER_DB_ACCESS_TYPE_SQL)
+ {
+ if (check_socket)
+ {
+ socket_has_default_value = spider_dbton[roop_count].
+ db_util->socket_has_default_value();
+ }
+ if (check_database)
+ {
+ database_has_default_value = spider_dbton[roop_count].
+ db_util->database_has_default_value();
+ }
+ break;
+ }
+ }
+ }
+ }
+ } else {
+ socket_has_default_value = FALSE;
+ database_has_default_value = FALSE;
+ }
+
+ if (database_has_default_value)
+ {
DBUG_PRINT("info",("spider create default tgt_default_db_name"));
direct_sql->tgt_default_db_name_length = SPIDER_THD_db_length(trx->thd);
if (
@@ -1442,13 +1533,8 @@ int spider_udf_set_direct_sql_param_default(
if (direct_sql->tgt_ssl_vsc == -1)
direct_sql->tgt_ssl_vsc = 0;
- if (
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- direct_sql->access_mode == 0 &&
-#endif
- !direct_sql->tgt_socket &&
- !strcmp(direct_sql->tgt_host, my_localhost)
- ) {
+ if (socket_has_default_value)
+ {
DBUG_PRINT("info",("spider create default tgt_socket"));
direct_sql->tgt_socket_length = strlen((char *) MYSQL_UNIX_ADDR);
if (
diff --git a/storage/spider/spd_err.h b/storage/spider/spd_err.h
index b4315708157..60b2a084714 100644
--- a/storage/spider/spd_err.h
+++ b/storage/spider/spd_err.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 2008-2017 Kentoku Shiba
+/* Copyright (C) 2008-2020 Kentoku Shiba
+ Copyright (C) 2019-2020 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -120,6 +121,8 @@
#define ER_SPIDER_ORACLE_STR "Error from Oracle %d %d %s"
#define ER_SPIDER_ORACLE_NUM 12712
#define ER_SPIDER_ORACLE_ERR "Oracle error"
+#define ER_SPIDER_DATASOURCE_STR "Error from %s %d %s %s"
+#define ER_SPIDER_DATASOURCE_NUM 12712
#define ER_SPIDER_CON_COUNT_ERROR 12713
#define ER_SPIDER_CON_COUNT_ERROR_STR "Too many connections between spider and remote"
#define ER_SPIDER_TABLE_OPEN_TIMEOUT_NUM 12714
diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h
index c1819da1567..3424b3e590b 100644
--- a/storage/spider/spd_include.h
+++ b/storage/spider/spd_include.h
@@ -1,5 +1,5 @@
-/* Copyright (C) 2008-2019 Kentoku Shiba
- Copyright (C) 2019 MariaDB corp
+/* Copyright (C) 2008-2020 Kentoku Shiba
+ Copyright (C) 2019-2020 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -261,7 +261,7 @@ const char SPIDER_empty_string = "";
#define SPIDER_TMP_SHARE_LONG_COUNT 19
#define SPIDER_TMP_SHARE_LONGLONG_COUNT 3
-#define SPIDER_MEM_CALC_LIST_NUM 273
+#define SPIDER_MEM_CALC_LIST_NUM 314
#define SPIDER_CONN_META_BUF_LEN 64
#define SPIDER_BACKUP_DASTATUS \
@@ -482,6 +482,7 @@ typedef struct st_spider_conn
char *tgt_password;
char *tgt_socket;
char *tgt_wrapper;
+ char *tgt_db; /* for not joinable tables on different db */
char *tgt_ssl_ca;
char *tgt_ssl_capath;
char *tgt_ssl_cert;
@@ -501,6 +502,7 @@ typedef struct st_spider_conn
uint tgt_password_length;
uint tgt_socket_length;
uint tgt_wrapper_length;
+ uint tgt_db_length;
uint tgt_ssl_ca_length;
uint tgt_ssl_capath_length;
uint tgt_ssl_cert_length;
@@ -1046,6 +1048,7 @@ typedef struct st_spider_share
int bulk_size;
int bulk_update_mode;
int bulk_update_size;
+ int buffer_size;
int internal_optimize;
int internal_optimize_local;
double scan_rate;
diff --git a/storage/spider/spd_param.cc b/storage/spider/spd_param.cc
index 446ccc22141..90f68450f67 100644
--- a/storage/spider/spd_param.cc
+++ b/storage/spider/spd_param.cc
@@ -1053,6 +1053,31 @@ int spider_param_bulk_update_size(
/*
-1 :use table parameter
+ 0-:buffer size
+ */
+static MYSQL_THDVAR_INT(
+ buffer_size, /* name */
+ PLUGIN_VAR_RQCMDARG, /* opt */
+ "Buffer size", /* comment */
+ NULL, /* check */
+ NULL, /* update */
+ -1, /* def */
+ -1, /* min */
+ 2147483647, /* max */
+ 0 /* blk */
+);
+
+int spider_param_buffer_size(
+ THD *thd,
+ int buffer_size
+) {
+ DBUG_ENTER("spider_param_buffer_size");
+ DBUG_RETURN(THDVAR(thd, buffer_size) == -1 ?
+ buffer_size : THDVAR(thd, buffer_size));
+}
+
+/*
+ -1 :use table parameter
0 :off
1 :on
*/
@@ -3463,6 +3488,7 @@ static struct st_mysql_sys_var* spider_system_variables[] = {
MYSQL_SYSVAR(bulk_size),
MYSQL_SYSVAR(bulk_update_mode),
MYSQL_SYSVAR(bulk_update_size),
+ MYSQL_SYSVAR(buffer_size),
MYSQL_SYSVAR(internal_optimize),
MYSQL_SYSVAR(internal_optimize_local),
MYSQL_SYSVAR(use_flash_logs),
diff --git a/storage/spider/spd_param.h b/storage/spider/spd_param.h
index 4e76d7a997d..f3b103eec99 100644
--- a/storage/spider/spd_param.h
+++ b/storage/spider/spd_param.h
@@ -126,6 +126,10 @@ int spider_param_bulk_update_size(
THD *thd,
int bulk_update_size
);
+int spider_param_buffer_size(
+ THD *thd,
+ int buffer_size
+);
int spider_param_internal_optimize(
THD *thd,
int internal_optimize
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index 6b6e5624cdf..f3f2dabf887 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -1,5 +1,5 @@
-/* Copyright (C) 2008-2019 Kentoku Shiba
- Copyright (C) 2019 MariaDB corp
+/* Copyright (C) 2008-2020 Kentoku Shiba
+ Copyright (C) 2019-2020 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -2050,6 +2050,7 @@ int spider_parse_connect_info(
share->bulk_size = -1;
share->bulk_update_mode = -1;
share->bulk_update_size = -1;
+ share->buffer_size = -1;
share->internal_optimize = -1;
share->internal_optimize_local = -1;
share->scan_rate = -1;
@@ -2219,6 +2220,7 @@ int spider_parse_connect_info(
#ifdef HA_CAN_BULK_ACCESS
SPIDER_PARAM_INT_WITH_MAX("baf", bulk_access_free, 0, 1);
#endif
+ SPIDER_PARAM_INT("bfz", buffer_size, 0);
#ifndef WITHOUT_SPIDER_BG_SEARCH
SPIDER_PARAM_LONGLONG("bfr", bgs_first_read, 0);
SPIDER_PARAM_INT("bmd", bgs_mode, 0);
@@ -2428,6 +2430,7 @@ int spider_parse_connect_info(
SPIDER_PARAM_LONG_LIST_WITH_MAX("use_hs_read", use_hs_reads, 0, 1);
#endif
SPIDER_PARAM_INT_WITH_MAX("casual_read", casual_read, 0, 63);
+ SPIDER_PARAM_INT("buffer_size", buffer_size, 0);
error_num = connect_string_parse.print_param_error();
goto error;
case 12:
@@ -3504,7 +3507,11 @@ int spider_set_connect_info_default(
#endif
TABLE_SHARE *table_share
) {
- int error_num, roop_count;
+ bool check_socket;
+ bool check_database;
+ bool socket_has_default_value;
+ bool database_has_default_value;
+ int error_num, roop_count, roop_count2;
DBUG_ENTER("spider_set_connect_info_default");
for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
{
@@ -3514,6 +3521,64 @@ int spider_set_connect_info_default(
DBUG_RETURN(error_num);
}
+ if (
+ !share->tgt_sockets[roop_count] &&
+ (
+ !share->tgt_hosts[roop_count] ||
+ !strcmp(share->tgt_hosts[roop_count], my_localhost)
+ )
+ ) {
+ check_socket = TRUE;
+ } else {
+ check_socket = FALSE;
+ }
+ if (!share->tgt_dbs[roop_count] && table_share)
+ {
+ check_database = TRUE;
+ } else {
+ check_database = FALSE;
+ }
+ if (check_socket || check_database)
+ {
+ socket_has_default_value = check_socket;
+ database_has_default_value = check_database;
+ if (share->tgt_wrappers[roop_count])
+ {
+ for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
+ {
+ DBUG_PRINT("info",("spider share->tgt_wrappers[%d]=%s", roop_count,
+ share->tgt_wrappers[roop_count]));
+ DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
+ spider_dbton[roop_count2].wrapper ?
+ spider_dbton[roop_count2].wrapper : "NULL"));
+ if (
+ spider_dbton[roop_count2].wrapper &&
+ !strcmp(share->tgt_wrappers[roop_count],
+ spider_dbton[roop_count2].wrapper)
+ ) {
+ if (spider_dbton[roop_count2].db_access_type ==
+ SPIDER_DB_ACCESS_TYPE_SQL)
+ {
+ if (check_socket)
+ {
+ socket_has_default_value = spider_dbton[roop_count2].
+ db_util->socket_has_default_value();
+ }
+ if (check_database)
+ {
+ database_has_default_value = spider_dbton[roop_count2].
+ db_util->database_has_default_value();
+ }
+ break;
+ }
+ }
+ }
+ }
+ } else {
+ socket_has_default_value = FALSE;
+ database_has_default_value = FALSE;
+ }
+
if (!share->tgt_wrappers[roop_count])
{
DBUG_PRINT("info",("spider create default tgt_wrappers"));
@@ -3540,7 +3605,7 @@ int spider_set_connect_info_default(
}
}
- if (!share->tgt_dbs[roop_count] && table_share)
+ if (database_has_default_value)
{
DBUG_PRINT("info",("spider create default tgt_dbs"));
share->tgt_dbs_lengths[roop_count] = table_share->db.length;
@@ -3662,10 +3727,8 @@ int spider_set_connect_info_default(
if (share->tgt_ssl_vscs[roop_count] == -1)
share->tgt_ssl_vscs[roop_count] = 0;
- if (
- !share->tgt_sockets[roop_count] &&
- !strcmp(share->tgt_hosts[roop_count], my_localhost)
- ) {
+ if (socket_has_default_value)
+ {
DBUG_PRINT("info",("spider create default tgt_sockets"));
share->tgt_sockets_lengths[roop_count] =
strlen((char *) MYSQL_UNIX_ADDR);
@@ -3828,6 +3891,8 @@ int spider_set_connect_info_default(
share->bulk_update_mode = 0;
if (share->bulk_update_size == -1)
share->bulk_update_size = 16000;
+ if (share->buffer_size == -1)
+ share->buffer_size = 16000;
if (share->internal_optimize == -1)
share->internal_optimize = 0;
if (share->internal_optimize_local == -1)
@@ -3934,12 +3999,54 @@ int spider_set_connect_info_default_db_table(
const char *table_name,
uint table_name_length
) {
- int roop_count;
+ uint roop_count, roop_count2;
+ bool check_database;
+ bool database_has_default_value;
DBUG_ENTER("spider_set_connect_info_default_db_table");
- for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
+ for (roop_count = 0; roop_count < share->link_count; roop_count++)
{
if (!share->tgt_dbs[roop_count] && db_name)
{
+ check_database = TRUE;
+ } else {
+ check_database = FALSE;
+ }
+ if (check_database)
+ {
+ database_has_default_value = check_database;
+ if (share->tgt_wrappers[roop_count])
+ {
+ for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
+ {
+ DBUG_PRINT("info",("spider share->tgt_wrappers[%d]=%s", roop_count,
+ share->tgt_wrappers[roop_count]));
+ DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
+ spider_dbton[roop_count2].wrapper ?
+ spider_dbton[roop_count2].wrapper : "NULL"));
+ if (
+ spider_dbton[roop_count2].wrapper &&
+ !strcmp(share->tgt_wrappers[roop_count],
+ spider_dbton[roop_count2].wrapper)
+ ) {
+ if (spider_dbton[roop_count2].db_access_type ==
+ SPIDER_DB_ACCESS_TYPE_SQL)
+ {
+ if (check_database)
+ {
+ database_has_default_value = spider_dbton[roop_count2].
+ db_util->database_has_default_value();
+ }
+ break;
+ }
+ }
+ }
+ }
+ } else {
+ database_has_default_value = FALSE;
+ }
+
+ if (database_has_default_value)
+ {
DBUG_PRINT("info",("spider create default tgt_dbs"));
share->tgt_dbs_lengths[roop_count] = db_name_length;
if (
@@ -4023,16 +4130,19 @@ int spider_create_conn_keys(
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
char *tmp_hs_r_name, *tmp_hs_w_name;
#endif
+ uint length_base = sizeof(uint) * share->all_link_count;
uint *conn_keys_lengths;
+ uint *sql_dbton_ids;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ uint *hs_dbton_ids;
uint *hs_r_conn_keys_lengths;
uint *hs_w_conn_keys_lengths;
#endif
DBUG_ENTER("spider_create_conn_keys");
char *ptr;
- uint length = sizeof(uint) * share->all_link_count;
+ uint length = length_base * 2;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- length += (sizeof(uint) * share->all_link_count) * 2;
+ length += length_base * 3;
#endif
ptr = (char *) my_alloca(length);
if (!ptr)
@@ -4040,10 +4150,14 @@ int spider_create_conn_keys(
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
conn_keys_lengths = (uint *) ptr;
- ptr += (sizeof(uint) * share->all_link_count);
+ ptr += length_base;
+ sql_dbton_ids = (uint *) ptr;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ ptr += length_base;
+ hs_dbton_ids = (uint *) ptr;
+ ptr += length_base;
hs_r_conn_keys_lengths = (uint *) ptr;
- ptr += (sizeof(uint) * share->all_link_count);
+ ptr += length_base;
hs_w_conn_keys_lengths = (uint *) ptr;
#endif
@@ -4054,13 +4168,76 @@ int spider_create_conn_keys(
#endif
for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
{
- /* tgt_db not use */
+ bool get_sql_id = FALSE;
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ bool get_nosql_id = FALSE;
+#endif
+ for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
+ {
+ DBUG_PRINT("info",("spider share->tgt_wrappers[%d]=%s", roop_count,
+ share->tgt_wrappers[roop_count]));
+ DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
+ spider_dbton[roop_count2].wrapper ?
+ spider_dbton[roop_count2].wrapper : "NULL"));
+ if (
+ spider_dbton[roop_count2].wrapper &&
+ !strcmp(share->tgt_wrappers[roop_count],
+ spider_dbton[roop_count2].wrapper)
+ ) {
+ spider_set_bit(share->dbton_bitmap, roop_count2);
+ if (
+ !get_sql_id &&
+ spider_dbton[roop_count2].db_access_type == SPIDER_DB_ACCESS_TYPE_SQL
+ ) {
+ sql_dbton_ids[roop_count] = roop_count2;
+ get_sql_id = TRUE;
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ if (get_nosql_id)
+#endif
+ break;
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ else
+ continue;
+#endif
+ }
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ if (
+ !get_nosql_id &&
+ spider_dbton[roop_count2].db_access_type ==
+ SPIDER_DB_ACCESS_TYPE_NOSQL
+ ) {
+ hs_dbton_ids[roop_count] = roop_count2;
+ get_nosql_id = TRUE;
+ if (get_sql_id)
+ break;
+ }
+#endif
+ }
+ }
+ if (!get_sql_id)
+ sql_dbton_ids[roop_count] = SPIDER_DBTON_SIZE;
+#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
+ if (!get_nosql_id)
+ hs_dbton_ids[roop_count] = SPIDER_DBTON_SIZE;
+#endif
+
+ bool tables_on_different_db_are_joinable;
+ if (get_sql_id)
+ {
+ tables_on_different_db_are_joinable =
+ spider_dbton[sql_dbton_ids[roop_count]].db_util->
+ tables_on_different_db_are_joinable();
+ } else {
+ tables_on_different_db_are_joinable = TRUE;
+ }
conn_keys_lengths[roop_count]
= 1
+ share->tgt_wrappers_lengths[roop_count] + 1
+ share->tgt_hosts_lengths[roop_count] + 1
+ 5 + 1
+ share->tgt_sockets_lengths[roop_count] + 1
+ + (tables_on_different_db_are_joinable ?
+ 0 : share->tgt_dbs_lengths[roop_count] + 1)
+ share->tgt_usernames_lengths[roop_count] + 1
+ share->tgt_passwords_lengths[roop_count] + 1
+ share->tgt_ssl_cas_lengths[roop_count] + 1
@@ -4095,7 +4272,7 @@ int spider_create_conn_keys(
spider_bulk_alloc_mem(spider_current_trx, 45,
__func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
&share->conn_keys, sizeof(char *) * share->all_link_count,
- &share->conn_keys_lengths, sizeof(uint) * share->all_link_count,
+ &share->conn_keys_lengths, length_base,
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
&share->conn_keys_hash_value,
sizeof(my_hash_value_type) * share->all_link_count,
@@ -4103,23 +4280,23 @@ int spider_create_conn_keys(
&tmp_name, sizeof(char) * share->conn_keys_charlen,
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
&share->hs_read_conn_keys, sizeof(char *) * share->all_link_count,
- &share->hs_read_conn_keys_lengths, sizeof(uint) * share->all_link_count,
+ &share->hs_read_conn_keys_lengths, length_base,
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
&share->hs_read_conn_keys_hash_value,
sizeof(my_hash_value_type) * share->all_link_count,
#endif
&tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen,
&share->hs_write_conn_keys, sizeof(char *) * share->all_link_count,
- &share->hs_write_conn_keys_lengths, sizeof(uint) * share->all_link_count,
+ &share->hs_write_conn_keys_lengths, length_base,
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
&share->hs_write_conn_keys_hash_value,
sizeof(my_hash_value_type) * share->all_link_count,
#endif
&tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen,
#endif
- &share->sql_dbton_ids, sizeof(uint) * share->all_link_count,
+ &share->sql_dbton_ids, length_base,
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- &share->hs_dbton_ids, sizeof(uint) * share->all_link_count,
+ &share->hs_dbton_ids, length_base,
#endif
NullS))
) {
@@ -4128,20 +4305,32 @@ int spider_create_conn_keys(
}
share->conn_keys_length = share->all_link_count;
memcpy(share->conn_keys_lengths, conn_keys_lengths,
- sizeof(uint) * share->all_link_count);
+ length_base);
+ memcpy(share->sql_dbton_ids, sql_dbton_ids, length_base);
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
share->hs_read_conn_keys_length = share->all_link_count;
share->hs_write_conn_keys_length = share->all_link_count;
memcpy(share->hs_read_conn_keys_lengths, hs_r_conn_keys_lengths,
- sizeof(uint) * share->all_link_count);
+ length_base);
memcpy(share->hs_write_conn_keys_lengths, hs_w_conn_keys_lengths,
- sizeof(uint) * share->all_link_count);
+ length_base);
+ memcpy(share->hs_dbton_ids, hs_dbton_ids, length_base);
#endif
my_afree(conn_keys_lengths);
for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
{
+ bool tables_on_different_db_are_joinable;
+ if (share->sql_dbton_ids[roop_count] != SPIDER_DBTON_SIZE)
+ {
+ tables_on_different_db_are_joinable =
+ spider_dbton[share->sql_dbton_ids[roop_count]].db_util->
+ tables_on_different_db_are_joinable();
+ } else {
+ tables_on_different_db_are_joinable = TRUE;
+ }
+
share->conn_keys[roop_count] = tmp_name;
*tmp_name = '0';
DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count,
@@ -4160,6 +4349,16 @@ int spider_create_conn_keys(
tmp_name = strmov(tmp_name + 1, share->tgt_sockets[roop_count]);
} else
tmp_name++;
+ if (!tables_on_different_db_are_joinable)
+ {
+ if (share->tgt_dbs[roop_count])
+ {
+ DBUG_PRINT("info",("spider tgt_dbs[%d]=%s", roop_count,
+ share->tgt_dbs[roop_count]));
+ tmp_name = strmov(tmp_name + 1, share->tgt_dbs[roop_count]);
+ } else
+ tmp_name++;
+ }
if (share->tgt_usernames[roop_count])
{
DBUG_PRINT("info",("spider tgt_usernames[%d]=%s", roop_count,
@@ -4288,59 +4487,6 @@ int spider_create_conn_keys(
share->hs_write_conn_keys_lengths[roop_count]);
#endif
#endif
-
- bool get_sql_id = FALSE;
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- bool get_nosql_id = FALSE;
-#endif
- for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
- {
- DBUG_PRINT("info",("spider share->tgt_wrappers[%d]=%s", roop_count,
- share->tgt_wrappers[roop_count]));
- DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
- spider_dbton[roop_count2].wrapper ?
- spider_dbton[roop_count2].wrapper : "NULL"));
- if (
- spider_dbton[roop_count2].wrapper &&
- !strcmp(share->tgt_wrappers[roop_count],
- spider_dbton[roop_count2].wrapper)
- ) {
- spider_set_bit(share->dbton_bitmap, roop_count2);
- if (
- !get_sql_id &&
- spider_dbton[roop_count2].db_access_type == SPIDER_DB_ACCESS_TYPE_SQL
- ) {
- share->sql_dbton_ids[roop_count] = roop_count2;
- get_sql_id = TRUE;
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- if (get_nosql_id)
-#endif
- break;
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- else
- continue;
-#endif
- }
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- if (
- !get_nosql_id &&
- spider_dbton[roop_count2].db_access_type ==
- SPIDER_DB_ACCESS_TYPE_NOSQL
- ) {
- share->hs_dbton_ids[roop_count] = roop_count2;
- get_nosql_id = TRUE;
- if (get_sql_id)
- break;
- }
-#endif
- }
- }
- if (!get_sql_id)
- share->sql_dbton_ids[roop_count] = SPIDER_DBTON_SIZE;
-#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
- if (!get_nosql_id)
- share->hs_dbton_ids[roop_count] = SPIDER_DBTON_SIZE;
-#endif
}
for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
{