summaryrefslogtreecommitdiffstats
path: root/storage/spider/spd_db_mysql.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/spider/spd_db_mysql.cc')
-rw-r--r--storage/spider/spd_db_mysql.cc891
1 files changed, 292 insertions, 599 deletions
diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc
index e0dffe57..c2f0c6b8 100644
--- a/storage/spider/spd_db_mysql.cc
+++ b/storage/spider/spd_db_mysql.cc
@@ -451,7 +451,7 @@ int spider_db_mbase_row::append_escaped_to_str(
DBUG_ENTER("spider_db_mbase_row::append_escaped_to_str");
DBUG_PRINT("info",("spider this=%p", this));
spider_string tmp_str(*row, *lengths + 1, str->charset());
- tmp_str.init_calc_mem(133);
+ tmp_str.init_calc_mem(SPD_MID_DB_MBASE_ROW_APPEND_ESCAPED_TO_STR_1);
tmp_str.length(*lengths);
if (str->reserve(*lengths * 2 + 2))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
@@ -544,7 +544,7 @@ SPIDER_DB_ROW *spider_db_mbase_row::clone()
row_size = record_size + field_count;
}
if (!spider_bulk_malloc(
- spider_current_trx, 29, MYF(MY_WME),
+ spider_current_trx, SPD_MID_DB_MBASE_ROW_CLONE_1, MYF(MY_WME),
&clone_row->row, (uint) (sizeof(char*) * (field_count + 1)),
&tmp_char, (uint) (row_size),
&clone_row->lengths, (uint) (sizeof(ulong) * field_count),
@@ -774,9 +774,9 @@ SPIDER_DB_ROW *spider_db_mbase_result::fetch_row_from_tmp_table(
uint field_count;
DBUG_ENTER("spider_db_mbase_result::fetch_row_from_tmp_table");
DBUG_PRINT("info",("spider this=%p", this));
- tmp_str1.init_calc_mem(117);
- tmp_str2.init_calc_mem(118);
- tmp_str3.init_calc_mem(170);
+ tmp_str1.init_calc_mem(SPD_MID_DB_MBASE_RESULT_FETCH_ROW_FROM_TMP_TABLE_1);
+ tmp_str2.init_calc_mem(SPD_MID_DB_MBASE_RESULT_FETCH_ROW_FROM_TMP_TABLE_2);
+ tmp_str3.init_calc_mem(SPD_MID_DB_MBASE_RESULT_FETCH_ROW_FROM_TMP_TABLE_3);
tmp_table->field[0]->val_str(tmp_str1.get_str());
tmp_table->field[1]->val_str(tmp_str2.get_str());
tmp_table->field[2]->val_str(tmp_str3.get_str());
@@ -1529,10 +1529,13 @@ int spider_db_mbase_result::fetch_index_for_discover_table_structure(
}
DBUG_RETURN(0);
}
- if (num_fields() != 13)
+ if (num_fields() < 13)
{
- DBUG_PRINT("info",("spider num_fields != 13"));
- my_printf_error(ER_SPIDER_UNKNOWN_NUM, ER_SPIDER_UNKNOWN_STR, MYF(0));
+ DBUG_PRINT("info",("spider num_fields < 13"));
+ my_printf_error(ER_SPIDER_CANT_NUM, ER_SPIDER_CANT_STR1, MYF(0),
+ "fetch index for table structure discovery because of "
+ "wrong number of columns in SHOW INDEX FROM output: ",
+ num_fields());
DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM);
}
bool first = TRUE;
@@ -1826,7 +1829,7 @@ int spider_db_mbase::init()
) {
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
- spider_alloc_calc_mem_init(lock_table_hash, 140);
+ spider_alloc_calc_mem_init(lock_table_hash, SPD_MID_DB_MBASE_INIT_1);
spider_alloc_calc_mem(spider_current_trx,
lock_table_hash,
lock_table_hash.array.max_element *
@@ -1929,7 +1932,7 @@ int spider_db_mbase::connect(
if (!spider_param_same_server_link(thd))
{
- if (!strcmp(tgt_host, my_localhost))
+ if (!strcmp(tgt_host, my_localhost) || !tgt_host || !tgt_host[0])
{
if (!strcmp(tgt_socket, *spd_mysqld_unix_port))
{
@@ -1939,7 +1942,7 @@ int spider_db_mbase::connect(
DBUG_RETURN(ER_SPIDER_SAME_SERVER_LINK_NUM);
}
} else if (!strcmp(tgt_host, "127.0.0.1") ||
- !strcmp(tgt_host, glob_hostname))
+ !strcmp(tgt_host, glob_hostname) || !tgt_host || !tgt_host[0])
{
if (tgt_port == (long) *spd_mysqld_port)
{
@@ -2066,7 +2069,7 @@ int spider_db_mbase::exec_query(
const char *tgt_str = conn->tgt_host;
uint32 tgt_len = conn->tgt_host_length;
spider_string tmp_query_str;
- tmp_query_str.init_calc_mem(230);
+ tmp_query_str.init_calc_mem(SPD_MID_DB_MBASE_EXEC_QUERY_1);
if (tmp_query_str.reserve(
length + conn->tgt_wrapper_length +
tgt_len + (SPIDER_SQL_SPACE_LEN * 2)))
@@ -2096,7 +2099,7 @@ int spider_db_mbase::exec_query(
struct tm lt;
struct tm *l_time = localtime_r(&cur_time, &lt);
spider_string tmp_query_str;
- tmp_query_str.init_calc_mem(243);
+ tmp_query_str.init_calc_mem(SPD_MID_DB_MBASE_EXEC_QUERY_2);
uint query_length = thd->query_length();
if ((log_result_error_with_sql & 2) && query_length)
{
@@ -2640,7 +2643,7 @@ int spider_db_mbase::xa_end(
spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin);
DBUG_ENTER("spider_db_mbase::xa_end");
DBUG_PRINT("info",("spider this=%p", this));
- sql_str.init_calc_mem(108);
+ sql_str.init_calc_mem(SPD_MID_DB_MBASE_XA_END_1);
sql_str.length(0);
sql_str.q_append(SPIDER_SQL_XA_END_STR, SPIDER_SQL_XA_END_LEN);
@@ -2683,7 +2686,7 @@ int spider_db_mbase::xa_prepare(
spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin);
DBUG_ENTER("spider_db_mbase::xa_prepare");
DBUG_PRINT("info",("spider this=%p", this));
- sql_str.init_calc_mem(109);
+ sql_str.init_calc_mem(SPD_MID_DB_MBASE_XA_PREPARE_1);
sql_str.length(0);
sql_str.q_append(SPIDER_SQL_XA_PREPARE_STR, SPIDER_SQL_XA_PREPARE_LEN);
@@ -2726,7 +2729,7 @@ int spider_db_mbase::xa_commit(
spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin);
DBUG_ENTER("spider_db_mbase::xa_commit");
DBUG_PRINT("info",("spider this=%p", this));
- sql_str.init_calc_mem(110);
+ sql_str.init_calc_mem(SPD_MID_DB_MBASE_XA_COMMIT_1);
sql_str.length(0);
sql_str.q_append(SPIDER_SQL_XA_COMMIT_STR, SPIDER_SQL_XA_COMMIT_LEN);
@@ -2769,7 +2772,7 @@ int spider_db_mbase::xa_rollback(
spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin);
DBUG_ENTER("spider_db_mbase::xa_rollback");
DBUG_PRINT("info",("spider this=%p", this));
- sql_str.init_calc_mem(111);
+ sql_str.init_calc_mem(SPD_MID_DB_MBASE_XA_ROLLBACK_1);
sql_str.length(0);
sql_str.q_append(SPIDER_SQL_XA_ROLLBACK_STR, SPIDER_SQL_XA_ROLLBACK_LEN);
@@ -3106,7 +3109,7 @@ int spider_db_mbase::set_wait_timeout(
spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin);
DBUG_ENTER("spider_db_mbase::set_wait_timeout");
DBUG_PRINT("info",("spider this=%p", this));
- sql_str.init_calc_mem(264);
+ sql_str.init_calc_mem(SPD_MID_DB_MBASE_SET_WAIT_TIMEOUT_1);
sql_str.length(0);
timeout_str_length =
my_sprintf(timeout_str, (timeout_str, "%d", wait_timeout));
@@ -3160,7 +3163,7 @@ int spider_db_mbase::set_sql_mode(
spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin);
DBUG_ENTER("spider_db_mbase::set_sql_mode");
DBUG_PRINT("info",("spider this=%p", this));
- sql_str.init_calc_mem(265);
+ sql_str.init_calc_mem(SPD_MID_DB_MBASE_SET_SQL_MODE_1);
sql_str.length(0);
if (sql_str.reserve(SPIDER_SQL_SQL_MODE_LEN))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
@@ -3225,7 +3228,7 @@ int spider_db_mbase::set_time_zone(
spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin);
DBUG_ENTER("spider_db_mbase::set_time_zone");
DBUG_PRINT("info",("spider this=%p", this));
- sql_str.init_calc_mem(214);
+ sql_str.init_calc_mem(SPD_MID_DB_MBASE_SET_TIME_ZONE_1);
sql_str.length(0);
if (sql_str.reserve(SPIDER_SQL_TIME_ZONE_LEN +
tz_str->length() + SPIDER_SQL_VALUE_QUOTE_LEN))
@@ -3278,7 +3281,7 @@ int spider_db_mbase::set_loop_check(
spider_string sql_str(sql_buf, sizeof(sql_buf), &my_charset_bin);
DBUG_ENTER("spider_db_mbase::set_loop_check");
DBUG_PRINT("info",("spider this=%p", this));
- sql_str.init_calc_mem(270);
+ sql_str.init_calc_mem(SPD_MID_DB_MBASE_SET_LOOP_CHECK_1);
while ((lcptr = (SPIDER_CONN_LOOP_CHECK *) my_hash_element(
&conn->loop_check_queue, 0)))
{
@@ -3960,7 +3963,7 @@ int spider_db_mariadb_util::append_column_value(ha_spider *spider,
THD *thd = field->table->in_use;
Time_zone *saved_time_zone = thd->variables.time_zone;
DBUG_ENTER("spider_db_mariadb_util::append_column_value");
- tmp_str.init_calc_mem(113);
+ tmp_str.init_calc_mem(SPD_MID_DB_MARIADB_UTIL_APPEND_COLUMN_VALUE_1);
thd->variables.time_zone = UTC;
@@ -4036,7 +4039,7 @@ int spider_db_mariadb_util::append_column_value(ha_spider *spider,
DBUG_PRINT("info", ("spider append_escaped"));
char buf2[MAX_FIELD_WIDTH];
spider_string tmp_str2(buf2, MAX_FIELD_WIDTH, field->charset());
- tmp_str2.init_calc_mem(114);
+ tmp_str2.init_calc_mem(SPD_MID_DB_MARIADB_UTIL_APPEND_COLUMN_VALUE_2);
tmp_str2.length(0);
if (
tmp_str2.append(ptr->ptr(), ptr->length(), field->charset()) ||
@@ -4104,7 +4107,7 @@ int spider_db_mysql_util::append_column_value(
THD *thd = field->table->in_use;
Time_zone *saved_time_zone = thd->variables.time_zone;
DBUG_ENTER("spider_db_mysql_util::append_column_value");
- tmp_str.init_calc_mem(266);
+ tmp_str.init_calc_mem(SPD_MID_DB_MYSQL_UTIL_APPEND_COLUMN_VALUE_1);
thd->variables.time_zone = UTC;
@@ -4255,7 +4258,7 @@ int spider_db_mysql_util::append_column_value(
DBUG_PRINT("info", ("spider append_escaped"));
char buf2[MAX_FIELD_WIDTH];
spider_string tmp_str2(buf2, MAX_FIELD_WIDTH, field->charset());
- tmp_str2.init_calc_mem(267);
+ tmp_str2.init_calc_mem(SPD_MID_DB_MYSQL_UTIL_APPEND_COLUMN_VALUE_2);
tmp_str2.length(0);
if (
tmp_str2.append(ptr->ptr(), ptr->length(), field->charset()) ||
@@ -5828,12 +5831,17 @@ int spider_db_mbase_util::print_item_func(
item_count -= 2;
break;
}
- } else if (func_name_length == 6 &&
- !strncasecmp("istrue", func_name, func_name_length)
- ) {
- last_str = SPIDER_SQL_IS_TRUE_STR;
- last_str_length = SPIDER_SQL_IS_TRUE_LEN;
- break;
+ } else if (func_name_length == 6)
+ {
+ if (!strncasecmp("istrue", func_name, func_name_length))
+ {
+ last_str= SPIDER_SQL_IS_TRUE_STR;
+ last_str_length= SPIDER_SQL_IS_TRUE_LEN;
+ break;
+ }
+ else if (!strncasecmp("regexp", func_name, func_name_length))
+ /* Keep the infix expression */
+ break;
} else if (func_name_length == 7)
{
if (!strncasecmp("isfalse", func_name, func_name_length))
@@ -6093,7 +6101,7 @@ int spider_db_mbase_util::print_item_func(
char *tmp_ptr, *tmp_ptr2;
DBUG_ASSERT(tmp_str.length() == 0);
tmp_str.set_charset(str->charset());
- tmp_str.init_calc_mem(123);
+ tmp_str.init_calc_mem(SPD_MID_DB_MBASE_UTIL_PRINT_ITEM_FUNC_1);
tmp_str.reserve(MAX_FIELD_WIDTH);
str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN);
if (!merge_func)
@@ -6218,7 +6226,7 @@ int spider_db_mbase_util::print_item_func(
char *tmp_ptr, *tmp_ptr2;
DBUG_ASSERT(tmp_str.length() == 0);
tmp_str.set_charset(str->charset());
- tmp_str.init_calc_mem(124);
+ tmp_str.init_calc_mem(SPD_MID_DB_MBASE_UTIL_PRINT_ITEM_FUNC_2);
tmp_str.reserve(MAX_FIELD_WIDTH);
str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN);
if (!merge_func)
@@ -6355,7 +6363,7 @@ int spider_db_mbase_util::print_item_func(
char *tmp_ptr, *tmp_ptr2;
DBUG_ASSERT(tmp_str.length() == 0);
tmp_str.set_charset(str->charset());
- tmp_str.init_calc_mem(125);
+ tmp_str.init_calc_mem(SPD_MID_DB_MBASE_UTIL_PRINT_ITEM_FUNC_3);
tmp_str.reserve(MAX_FIELD_WIDTH);
str->length(str->length() - SPIDER_SQL_OPEN_PAREN_LEN);
if (!merge_func)
@@ -6803,440 +6811,250 @@ int spider_db_mbase_util::append_escaped_util(
DBUG_RETURN(0);
}
-int spider_db_mbase_util::append_table(
- ha_spider *spider,
- spider_fields *fields,
- spider_string *str,
- TABLE_LIST *table_list,
- TABLE_LIST **used_table_list,
- uint *current_pos,
- TABLE_LIST **cond_table_list_ptr,
- bool top_down,
- bool first
-) {
- int error_num;
- bool use_cond_table_list = FALSE;
- spider_mbase_share *db_share;
- spider_mbase_handler *dbton_hdl;
- SPIDER_TABLE_HOLDER *table_holder;
- TABLE_LIST *cond_table_list = *cond_table_list_ptr;
- ha_spider *spd;
- DBUG_ENTER("spider_db_mbase_util::append_table");
- DBUG_PRINT("info",("spider table_list=%p", table_list));
- DBUG_PRINT("info",("spider table_list->outer_join=%u",
- table_list->outer_join));
- DBUG_PRINT("info",("spider table_list->on_expr=%p",
- table_list->on_expr));
- DBUG_PRINT("info",("spider table_list->join_using_fields=%p",
- table_list->join_using_fields));
- DBUG_PRINT("info",("spider table_list->table=%p",
- table_list->table));
- if (!top_down && table_list->embedding)
- {
- if ((error_num = append_embedding_tables(spider, fields, str,
- table_list->embedding, used_table_list, current_pos,
- cond_table_list_ptr)))
+/*
+ Walk a TABLE_LIST, or format it to a string and append it.
+
+ If str is NULL, walk the nested join (if any) to determine whether
+ to create a group by handler. Otherwise, format the TABLE_LIST to a
+ string and append it to str.
+
+ Adapted from TABLE_LIST::print().
+*/
+int spider_db_mbase_util::append_table_list(spider_fields *fields,
+ spider_string *str,
+ TABLE_LIST *table,
+ table_map *upper_usable_tables,
+ table_map eliminated_tables)
+{
+ DBUG_ENTER("spider_db_mbase_util::append_table_list");
+ /* Eliminated tables were removed from append_join(). */
+ DBUG_ASSERT(!is_eliminated_table(eliminated_tables, table));
+ if (!str) /* First pass (GBH creation) */
+ {
+ DBUG_ASSERT(upper_usable_tables);
+ if (table->nested_join)
+ DBUG_RETURN(append_join(fields, str,
+ &table->nested_join->join_list,
+ upper_usable_tables, eliminated_tables));
+ /* jtbm is a kind of semi join, and TABLE_LIST::print() adds an
+ extra " <materialize> " annotation. */
+ if (table->jtbm_subselect)
+ DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
+ /* TODO: These conditions are printed in a different way in
+ TABLE_LIST::print(), but they do not seem to occur very often.
+ Let's not worry about them now. */
+ if (table->view_name.str || table->derived || table->table_function)
+ DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
+ *upper_usable_tables |= table->table->map;
+ DBUG_RETURN(0);
+ }
+ /* Second pass (query execution) */
+ DBUG_ASSERT(!upper_usable_tables);
+ if (table->nested_join)
+ {
+ if (str->append("("))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ if (int error_num= append_join(
+ fields, str, &table->nested_join->join_list,
+ upper_usable_tables, eliminated_tables))
DBUG_RETURN(error_num);
- } else if (!table_list->table)
+ if (str->append(")"))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ DBUG_RETURN(0);
+ }
+ /* These have been ruled out during the creation of the group by
+ handler, see above. */
+ DBUG_ASSERT(!table->jtbm_subselect);
+ DBUG_ASSERT(!table->view_name.str);
+ DBUG_ASSERT(!table->derived);
+ DBUG_ASSERT(!table->table_function);
+ /* We have a "normal" table. Print it and append to str. */
+ SPIDER_TABLE_HOLDER *table_holder = fields->get_table_holder(table->table);
+ ha_spider *spd = table_holder->spider;
+ spider_mbase_share *db_share =
+ (spider_mbase_share *) spd->share->dbton_share[dbton_id];
+ spider_mbase_handler *dbton_hdl =
+ (spider_mbase_handler *) spd->dbton_handler[dbton_id];
+ if (table->table->const_table)
{
- if ((error_num = append_tables_top_down(spider, fields, str, table_list,
- used_table_list, current_pos, cond_table_list_ptr)))
+ if (str->append(STRING_WITH_LEN("(select 1)")))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ }
+ else
+ if (int error_num= db_share->append_table_name(
+ str, spd->conn_link_idx[dbton_hdl->first_link_idx]))
DBUG_RETURN(error_num);
- } else {
- if (
- table_list->outer_join ||
- table_list->on_expr ||
- table_list->join_using_fields
- ) {
- DBUG_PRINT("info",("spider use table_list"));
- if (table_list->outer_join & JOIN_TYPE_LEFT)
- {
- if (str)
- {
- if (str->reserve(SPIDER_SQL_LEFT_JOIN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_LEFT_JOIN_STR, SPIDER_SQL_LEFT_JOIN_LEN);
- }
- } else {
- if (str)
- {
- if (str->reserve(SPIDER_SQL_JOIN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_JOIN_STR, SPIDER_SQL_JOIN_LEN);
- }
- }
- } else if (
- cond_table_list &&
- (
- cond_table_list->outer_join ||
- cond_table_list->on_expr ||
- cond_table_list->join_using_fields
- )
- ) {
- DBUG_PRINT("info",("spider use cond_table_list"));
- if (cond_table_list->outer_join & (JOIN_TYPE_LEFT | JOIN_TYPE_RIGHT))
- {
- if (str)
- {
- if (str->reserve(SPIDER_SQL_LEFT_JOIN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_LEFT_JOIN_STR, SPIDER_SQL_LEFT_JOIN_LEN);
- }
- } else {
- if (str)
- {
- if (str->reserve(SPIDER_SQL_JOIN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_JOIN_STR, SPIDER_SQL_JOIN_LEN);
- }
- }
- use_cond_table_list = TRUE;
- } else if (*current_pos > 0 && !first)
- {
- DBUG_PRINT("info",("spider no condition"));
- if (str)
- {
- if (str->reserve(SPIDER_SQL_JOIN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_JOIN_STR, SPIDER_SQL_JOIN_LEN);
- }
- }
-
- if (str)
- {
- table_holder = fields->get_table_holder(table_list->table);
- spd = table_holder->spider;
- db_share = (spider_mbase_share *)
- spd->share->dbton_share[dbton_id];
- dbton_hdl = (spider_mbase_handler *)
- spd->dbton_handler[dbton_id];
+ if (str->append(" ") ||
+ str->append(table_holder->alias->ptr(),
+ /* Don't append the trailing dot */
+ table_holder->alias->length() - 1))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ DBUG_RETURN(0);
+}
- dbton_hdl->table_name_pos = str->length();
+/*
+ Walk an array of TABLE_LIST's, or format it to a string and append it.
- if (str->reserve(
- db_share->db_nm_max_length +
- SPIDER_SQL_DOT_LEN + /* SPIDER_SQL_NAME_QUOTE_LEN */ 4 +
- db_share->table_nm_max_length + SPIDER_SQL_SPACE_LEN +
- table_holder->alias->length() - SPIDER_SQL_DOT_LEN
- )) {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
+ If str is NULL, walk each TABLE_LIST to determine whether to create
+ a group by handler. Otherwise, format the TABLE_LISTs to a string
+ and append it to str.
- if ((error_num = db_share->append_table_name_with_adjusting(str,
- spd->conn_link_idx[dbton_hdl->first_link_idx])))
- {
- DBUG_RETURN(error_num);
- }
- str->q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
- str->q_append(table_holder->alias->ptr(),
- table_holder->alias->length() - SPIDER_SQL_DOT_LEN);
- }
- used_table_list[(*current_pos)++] = table_list;
+ Adapted from print_table_array().
+*/
+int spider_db_mbase_util::append_table_array(spider_fields *fields,
+ spider_string *str,
+ TABLE_LIST **table,
+ TABLE_LIST **end,
+ table_map *upper_usable_tables,
+ table_map eliminated_tables)
+{
+ DBUG_ENTER("spider_db_mbase_util::append_table_array");
+ if (str)
+ {
+ DBUG_ASSERT(!upper_usable_tables);
+ if (int error_num= append_table_list(fields, str, *table, NULL,
+ eliminated_tables))
+ DBUG_RETURN(error_num);
- if (str)
+ for (TABLE_LIST **tbl= table + 1; tbl < end; tbl++)
{
- List<String> *join_using_fields = table_list->join_using_fields;
- if (!join_using_fields && cond_table_list)
- {
- join_using_fields = cond_table_list->join_using_fields;
- }
+ TABLE_LIST *curr= *tbl;
- if (join_using_fields)
+ /* JOIN_TYPE_OUTER is just a marker unrelated to real join */
+ if (curr->outer_join & (JOIN_TYPE_LEFT|JOIN_TYPE_RIGHT))
{
- if (str->reserve(SPIDER_SQL_USING_LEN + SPIDER_SQL_OPEN_PAREN_LEN))
- {
+ /* MySQL converts right to left joins */
+ if (str->append(STRING_WITH_LEN(" left join ")))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_USING_STR, SPIDER_SQL_USING_LEN);
- str->q_append(SPIDER_SQL_OPEN_PAREN_STR,
- SPIDER_SQL_OPEN_PAREN_LEN);
- List_iterator_fast<String> it2(*join_using_fields);
- String *ptr;
- while ((ptr = it2++))
- {
- if (str->reserve(ptr->length() + SPIDER_SQL_COMMA_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(ptr->ptr(), ptr->length());
- str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
- }
- str->length(str->length() - SPIDER_SQL_COMMA_LEN);
- if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
- SPIDER_SQL_CLOSE_PAREN_LEN);
}
- }
-
- Item *on_expr = table_list->on_expr;
- if (!on_expr && cond_table_list)
- {
- on_expr = cond_table_list->on_expr;
- }
-
- if (on_expr)
- {
- if (str)
+ else if (curr->straight)
{
- if (str->reserve(SPIDER_SQL_ON_LEN))
- {
+ if (str->append(STRING_WITH_LEN(" straight_join ")))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_ON_STR, SPIDER_SQL_ON_LEN);
}
- if ((error_num = spider_db_print_item_type(on_expr, NULL,
- spider, str, NULL, 0, dbton_id, TRUE, fields)))
- {
- DBUG_RETURN(error_num);
- }
- }
+ /* semi join should already have been ruled out during the
+ creation of the group by handler. */
+ else if (curr->sj_inner_tables)
+ DBUG_ASSERT(0);
+ else
+ if (str->append(STRING_WITH_LEN(" join ")))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- if (use_cond_table_list)
- {
- (*cond_table_list_ptr) = NULL;
- DBUG_PRINT("info",("spider cond_table_list=%p", (*cond_table_list_ptr)));
- }
- }
- DBUG_RETURN(0);
-}
+ if (int error_num= append_table_list(fields, str, curr, NULL,
+ eliminated_tables))
+ DBUG_RETURN(error_num);
-int spider_db_mbase_util::append_tables_top_down(
- ha_spider *spider,
- spider_fields *fields,
- spider_string *str,
- TABLE_LIST *table_list,
- TABLE_LIST **used_table_list,
- uint *current_pos,
- TABLE_LIST **cond_table_list_ptr
-) {
- int error_num;
- uint outer_join_backup;
- TABLE_LIST *cur_table_list, *prev_table_list = NULL, *cond_table_list = NULL;
- bool first = TRUE;
- DBUG_ENTER("spider_db_mbase_util::append_tables_top_down");
- DBUG_PRINT("info",("spider this=%p", this));
- if (
- table_list->outer_join ||
- table_list->on_expr ||
- table_list->join_using_fields
- ) {
- DBUG_ASSERT(!(*cond_table_list_ptr));
- (*cond_table_list_ptr) = table_list;
- DBUG_PRINT("info",("spider cond_table_list=%p", table_list));
- }
- List_iterator_fast<TABLE_LIST> it1(table_list->nested_join->join_list);
- cur_table_list = it1++;
- if (cur_table_list->outer_join & JOIN_TYPE_RIGHT)
- {
- first = FALSE;
- prev_table_list = cur_table_list;
- cur_table_list = it1++;
- } else if (*cond_table_list_ptr)
- {
- first = TRUE;
- cond_table_list = (*cond_table_list_ptr);
- (*cond_table_list_ptr) = NULL;
- if (cond_table_list->outer_join & JOIN_TYPE_LEFT)
- {
- if (str)
+ if (curr->on_expr)
{
- if (str->reserve(SPIDER_SQL_LEFT_JOIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN))
- {
+ if (str->append(STRING_WITH_LEN(" on ")))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_LEFT_JOIN_STR, SPIDER_SQL_LEFT_JOIN_LEN);
- str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN);
- }
- } else {
- if (str)
- {
- if (str->reserve(SPIDER_SQL_JOIN_LEN + SPIDER_SQL_OPEN_PAREN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_JOIN_STR, SPIDER_SQL_JOIN_LEN);
- str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN);
+ if (int error_num=
+ spider_db_print_item_type(curr->on_expr, NULL,
+ fields->get_first_table_holder()->spider,
+ str, NULL, 0, dbton_id, TRUE, fields))
+ DBUG_RETURN(error_num);
}
}
}
-
- do {
- if (cur_table_list->outer_join & JOIN_TYPE_RIGHT)
+ else /* str == NULL */
+ {
+ table_map usable_tables= 0;
+ if (int error_num= append_table_list(fields, str, *table,
+ &usable_tables, eliminated_tables))
+ DBUG_RETURN(error_num);
+ for (TABLE_LIST **tbl= table + 1; tbl < end; tbl++)
{
- prev_table_list = cur_table_list;
- } else {
- if ((error_num = append_table(spider, fields, str, cur_table_list,
- used_table_list, current_pos, cond_table_list_ptr, TRUE, first)))
+ TABLE_LIST *curr= *tbl;
+ /* semi join is an "internal" join and is unsupported. */
+ if (curr->sj_inner_tables)
+ DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
+ if (int error_num= append_table_list(fields, str, curr,
+ &usable_tables, eliminated_tables))
DBUG_RETURN(error_num);
- first = FALSE;
- if (prev_table_list)
+ if (curr->on_expr)
{
- outer_join_backup = prev_table_list->outer_join;
- prev_table_list->outer_join = JOIN_TYPE_LEFT;
- if ((error_num = append_table(spider, fields, str, prev_table_list,
- used_table_list, current_pos, cond_table_list_ptr, TRUE, FALSE)))
- {
- prev_table_list->outer_join = outer_join_backup;
+ /* The join refers to fields outside of the current context,
+ and cannot be handled by a group by handler. */
+ if ((curr->on_expr->used_tables() & usable_tables) !=
+ curr->on_expr->used_tables())
+ DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
+ if (int error_num=
+ spider_db_print_item_type(curr->on_expr, NULL,
+ fields->get_first_table_holder()->spider,
+ str, NULL, 0, dbton_id, TRUE, fields))
DBUG_RETURN(error_num);
- }
- prev_table_list->outer_join = outer_join_backup;
- prev_table_list = NULL;
- }
- }
- } while ((cur_table_list = it1++));
-
- if (cond_table_list)
- {
- if (str)
- {
- if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
- SPIDER_SQL_CLOSE_PAREN_LEN);
-
- List<String> *join_using_fields = cond_table_list->join_using_fields;
- if (join_using_fields)
- {
- if (str->reserve(SPIDER_SQL_USING_LEN + SPIDER_SQL_OPEN_PAREN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_USING_STR, SPIDER_SQL_USING_LEN);
- str->q_append(SPIDER_SQL_OPEN_PAREN_STR,
- SPIDER_SQL_OPEN_PAREN_LEN);
- List_iterator_fast<String> it2(*join_using_fields);
- String *ptr;
- while ((ptr = it2++))
- {
- if (str->reserve(ptr->length() + SPIDER_SQL_COMMA_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(ptr->ptr(), ptr->length());
- str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
- }
- str->length(str->length() - SPIDER_SQL_COMMA_LEN);
- if (str->reserve(SPIDER_SQL_CLOSE_PAREN_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
- SPIDER_SQL_CLOSE_PAREN_LEN);
- }
- }
-
- Item *on_expr = cond_table_list->on_expr;
- if (on_expr)
- {
- if (str)
- {
- if (str->reserve(SPIDER_SQL_ON_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_ON_STR, SPIDER_SQL_ON_LEN);
- }
- if ((error_num = spider_db_print_item_type(on_expr, NULL,
- spider, str, NULL, 0, dbton_id, TRUE, fields)))
- {
- DBUG_RETURN(error_num);
}
}
+ /* Update usable tables in the outer context. */
+ if (upper_usable_tables)
+ *upper_usable_tables |= usable_tables;
}
DBUG_RETURN(0);
}
-int spider_db_mbase_util::append_tables_top_down_check(
- TABLE_LIST *table_list,
- TABLE_LIST **used_table_list,
- uint *current_pos
-) {
- int error_num;
- TABLE_LIST *cur_table_list;
- DBUG_ENTER("spider_db_mbase_util::append_tables_top_down_check");
- DBUG_PRINT("info",("spider this=%p", this));
- List_iterator_fast<TABLE_LIST> it1(table_list->nested_join->join_list);
- while ((cur_table_list = it1++))
+/*
+ Walk a join, or format it to a string and append the string.
+
+ Skip all eliminated tables.
+
+ If str is NULL, walk the tables to determine whether to create a
+ group by handler. Otherwise, format the join to a string and append
+ it to str.
+
+ Adapted from print_join().
+*/
+int spider_db_mbase_util::append_join(spider_fields *fields,
+ spider_string *str,
+ List<TABLE_LIST> *tables,
+ table_map *upper_usable_tables,
+ table_map eliminated_tables)
+{
+ /* List is reversed => we should reverse it before using */
+ List_iterator_fast<TABLE_LIST> ti(*tables);
+ TABLE_LIST **table;
+ THD *thd= fields->get_first_table_holder()->spider->wide_handler->trx->thd;
+ DBUG_ENTER("spider_db_mbase_util::append_join");
+
+ size_t tables_to_print= 0;
+
+ for (TABLE_LIST *t= ti++; t ; t= ti++)
{
- if (!cur_table_list->table)
- {
- if ((error_num = append_tables_top_down_check(
- cur_table_list, used_table_list, current_pos)))
- DBUG_RETURN(error_num);
- } else {
- used_table_list[(*current_pos)++] = cur_table_list;
- }
+ /* optimized_away implies const_table */
+ DBUG_ASSERT(!t->optimized_away || t->table->const_table);
+ if (!is_eliminated_table(eliminated_tables, t))
+ tables_to_print++;
}
- DBUG_RETURN(0);
-}
+ if (tables_to_print == 0)
+ {
+ if (str && str->append(STRING_WITH_LEN("dual")))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ DBUG_RETURN(0);
+ }
+ ti.rewind();
-int spider_db_mbase_util::append_embedding_tables(
- ha_spider *spider,
- spider_fields *fields,
- spider_string *str,
- TABLE_LIST *table_list,
- TABLE_LIST **used_table_list,
- uint *current_pos,
- TABLE_LIST **cond_table_list_ptr
-) {
- int error_num;
- TABLE_LIST *embedding = table_list->embedding;
- DBUG_ENTER("spider_db_mbase_util::append_embedding_tables");
- DBUG_PRINT("info",("spider this=%p", this));
- if (embedding)
- {
- DBUG_PRINT("info",("spider embedding=%p", embedding));
- DBUG_PRINT("info",("spider embedding->outer_join=%u",
- embedding->outer_join));
- DBUG_PRINT("info",("spider embedding->on_expr=%p",
- embedding->on_expr));
- DBUG_PRINT("info",("spider embedding->join_using_fields=%p",
- embedding->join_using_fields));
- DBUG_PRINT("info",("spider embedding->table=%p",
- embedding->table));
- if ((error_num = append_embedding_tables(spider, fields, str, embedding,
- used_table_list, current_pos, cond_table_list_ptr)))
- DBUG_RETURN(error_num);
- } else {
- DBUG_PRINT("info",("spider table_list=%p", table_list));
- DBUG_PRINT("info",("spider table_list->outer_join=%u",
- table_list->outer_join));
- DBUG_PRINT("info",("spider table_list->on_expr=%p",
- table_list->on_expr));
- DBUG_PRINT("info",("spider table_list->join_using_fields=%p",
- table_list->join_using_fields));
- DBUG_PRINT("info",("spider table_list->table=%p",
- table_list->table));
- if (table_list->outer_join & JOIN_TYPE_RIGHT)
- {
- if ((error_num = append_tables_top_down_check(table_list,
- used_table_list, current_pos)))
- DBUG_RETURN(error_num);
- DBUG_ASSERT(!(*cond_table_list_ptr));
- (*cond_table_list_ptr) = table_list;
- DBUG_PRINT("info",("spider cond_table_list=%p", table_list));
- } else {
- if ((error_num = append_tables_top_down(spider, fields, str, table_list,
- used_table_list, current_pos, cond_table_list_ptr)))
- DBUG_RETURN(error_num);
- }
+ if (!(table= static_cast<TABLE_LIST **>(thd->alloc(sizeof(TABLE_LIST*) *
+ tables_to_print))))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+
+ TABLE_LIST *tmp, **t= table + (tables_to_print - 1);
+ while ((tmp= ti++))
+ if (!is_eliminated_table(eliminated_tables, tmp))
+ *t--= tmp;
+
+ DBUG_ASSERT(tables->elements >= 1);
+ if ((*table)->sj_inner_tables)
+ {
+ /* Semi join is not supported. */
+ if (!str)
+ DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
+ /* Semi join should have been skipped in the first pass. */
+ else
+ DBUG_ASSERT(0);
}
- DBUG_RETURN(0);
+ int error_num= append_table_array(
+ fields, str, table, table + tables_to_print, upper_usable_tables,
+ eliminated_tables);
+ DBUG_RETURN(error_num);
}
int spider_db_mbase_util::append_from_and_tables(
@@ -7245,116 +7063,17 @@ int spider_db_mbase_util::append_from_and_tables(
spider_string *str,
TABLE_LIST *table_list,
uint table_count
-) {
- int error_num;
- uint current_pos = 0, roop_count, backup_pos, outer_join_backup;
- TABLE *table;
- TABLE_LIST **used_table_list, *prev_table_list = NULL,
- *cond_table_list = NULL;
+)
+{
DBUG_ENTER("spider_db_mbase_util::append_from_and_tables");
- DBUG_PRINT("info",("spider this=%p", this));
- used_table_list = (TABLE_LIST **)
- my_alloca(sizeof(TABLE_LIST *) * table_count);
- if (!used_table_list)
+ if (str && str->append(" from "))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
-
- if (str)
- {
- if (str->reserve(SPIDER_SQL_FROM_LEN))
- {
- my_afree(used_table_list);
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- str->q_append(SPIDER_SQL_FROM_STR, SPIDER_SQL_FROM_LEN);
- }
-
- do {
- table = table_list->table;
- if (table->const_table)
- continue;
-
- for (roop_count = 0; roop_count < current_pos; ++roop_count)
- {
- if (used_table_list[roop_count] == table_list)
- break;
- }
- if (roop_count < current_pos)
- continue;
-
- if (prev_table_list)
- current_pos = backup_pos;
- else
- backup_pos = current_pos;
- if ((error_num = append_table(spider, fields, str, table_list, used_table_list,
- &current_pos, &cond_table_list, FALSE, FALSE)))
- {
- my_afree(used_table_list);
- DBUG_RETURN(error_num);
- }
- if (prev_table_list)
- {
- outer_join_backup = prev_table_list->outer_join;
- prev_table_list->outer_join = JOIN_TYPE_LEFT;
- if ((error_num = append_table(spider, fields, str, prev_table_list,
- used_table_list, &current_pos, &cond_table_list, FALSE, FALSE)))
- {
- prev_table_list->outer_join = outer_join_backup;
- my_afree(used_table_list);
- DBUG_RETURN(error_num);
- }
- prev_table_list->outer_join = outer_join_backup;
- prev_table_list = NULL;
- }
- if (cond_table_list && (cond_table_list->outer_join & JOIN_TYPE_RIGHT))
- {
- prev_table_list = cond_table_list;
- cond_table_list = NULL;
- DBUG_PRINT("info",("spider cond_table_list=%p", cond_table_list));
- }
- } while ((table_list = table_list->next_local));
- my_afree(used_table_list);
- DBUG_RETURN(0);
-}
-
-int spider_db_mbase_util::reappend_tables(
- spider_fields *fields,
- SPIDER_LINK_IDX_CHAIN *link_idx_chain,
- spider_string *str
-) {
- int error_num;
- uint32 length;
- ha_spider *spider;
- spider_mbase_share *db_share;
- spider_mbase_handler *dbton_hdl;
- SPIDER_TABLE_HOLDER *table_holder;
- SPIDER_LINK_IDX_HOLDER *link_idx_holder;
- DBUG_ENTER("spider_db_mbase_util::reappend_tables");
- DBUG_PRINT("info",("spider this=%p", this));
- length = str->length();
- fields->set_pos_to_first_table_on_link_idx_chain(link_idx_chain);
- fields->set_pos_to_first_table_holder();
- while ((table_holder = fields->get_next_table_holder()))
- {
- link_idx_holder =
- fields->get_next_table_on_link_idx_chain(link_idx_chain);
- spider = table_holder->spider;
- db_share = (spider_mbase_share *)
- spider->share->dbton_share[dbton_id];
- if (!db_share->same_db_table_name)
- {
- dbton_hdl = (spider_mbase_handler *) spider->dbton_handler[dbton_id];
- str->length(dbton_hdl->table_name_pos);
- if ((error_num = db_share->append_table_name_with_adjusting(str,
- spider->conn_link_idx[link_idx_holder->link_idx])))
- {
- DBUG_RETURN(error_num);
- }
- }
- }
- str->length(length);
- DBUG_RETURN(0);
+ const table_map eliminated_tables= table_list->select_lex->join ?
+ table_list->select_lex->join->eliminated_tables : 0;
+ int error_num = append_join(fields, str, table_list->select_lex->join_list,
+ NULL, eliminated_tables);
+ DBUG_RETURN(error_num);
}
-
int spider_db_mbase_util::append_where(
spider_string *str
) {
@@ -7455,7 +7174,7 @@ spider_mbase_share::spider_mbase_share(
{
DBUG_ENTER("spider_mbase_share::spider_mbase_share");
DBUG_PRINT("info",("spider this=%p", this));
- spider_alloc_calc_mem_init(mem_calc, 71);
+ spider_alloc_calc_mem_init(mem_calc, SPD_MID_MBASE_SHARE_SPIDER_MBASE_SHARE_1);
spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this));
DBUG_VOID_RETURN;
}
@@ -7529,7 +7248,7 @@ int spider_mbase_share::init()
DBUG_ENTER("spider_mbase_share::init");
DBUG_PRINT("info",("spider this=%p", this));
if (!(key_select_pos = (int *)
- spider_bulk_alloc_mem(spider_current_trx, 112,
+ spider_bulk_alloc_mem(spider_current_trx, SPD_MID_MBASE_SHARE_INIT_1,
__func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
&key_select_pos,
sizeof(int) * keys,
@@ -7547,7 +7266,7 @@ int spider_mbase_share::init()
}
for (roop_count = 0; roop_count < keys; roop_count++)
{
- key_hint[roop_count].init_calc_mem(189);
+ key_hint[roop_count].init_calc_mem(SPD_MID_MBASE_SHARE_INIT_2);
key_hint[roop_count].set_charset(spider_share->access_charset);
}
DBUG_PRINT("info",("spider key_hint=%p", key_hint));
@@ -7571,13 +7290,13 @@ int spider_mbase_share::init()
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
- table_select->init_calc_mem(96);
+ table_select->init_calc_mem(SPD_MID_MBASE_SHARE_INIT_3);
if (table_share && (error_num = append_table_select()))
DBUG_RETURN(error_num);
for (roop_count = 0; roop_count < keys; roop_count++)
{
- key_select[roop_count].init_calc_mem(97);
+ key_select[roop_count].init_calc_mem(SPD_MID_MBASE_SHARE_INIT_4);
if ((error_num = append_key_select(roop_count)))
DBUG_RETURN(error_num);
}
@@ -7728,9 +7447,9 @@ int spider_mbase_share::create_table_names_str()
for (roop_count = 0; roop_count < (int) spider_share->all_link_count;
roop_count++)
{
- table_names_str[roop_count].init_calc_mem(86);
- db_names_str[roop_count].init_calc_mem(87);
- db_table_str[roop_count].init_calc_mem(88);
+ table_names_str[roop_count].init_calc_mem(SPD_MID_MBASE_SHARE_CREATE_TABLE_NAMES_STR_1);
+ db_names_str[roop_count].init_calc_mem(SPD_MID_MBASE_SHARE_CREATE_TABLE_NAMES_STR_2);
+ db_table_str[roop_count].init_calc_mem(SPD_MID_MBASE_SHARE_CREATE_TABLE_NAMES_STR_3);
if (spider_share->sql_dbton_ids[roop_count] != dbton_id)
continue;
if (first_all_link_idx == -1)
@@ -7869,7 +7588,7 @@ int spider_mbase_share::create_column_name_str()
for (field = table_share->field, str = column_name_str;
*field; field++, str++)
{
- str->init_calc_mem(89);
+ str->init_calc_mem(SPD_MID_MBASE_SHARE_CREATE_COLUMN_NAME_STR_1);
str->set_charset(spider_share->access_charset);
if ((error_num = spider_db_append_name_with_quote_str(str,
(*field)->field_name, dbton_id)))
@@ -7937,8 +7656,8 @@ int spider_mbase_share::append_show_table_status()
for (roop_count = 0; roop_count < (int) spider_share->all_link_count;
roop_count++)
{
- show_table_status[0 + (2 * roop_count)].init_calc_mem(90);
- show_table_status[1 + (2 * roop_count)].init_calc_mem(91);
+ show_table_status[0 + (2 * roop_count)].init_calc_mem(SPD_MID_MBASE_SHARE_APPEND_SHOW_TABLE_STATUS_1);
+ show_table_status[1 + (2 * roop_count)].init_calc_mem(SPD_MID_MBASE_SHARE_APPEND_SHOW_TABLE_STATUS_2);
if (spider_share->sql_dbton_ids[roop_count] != dbton_id)
continue;
@@ -8018,7 +7737,7 @@ int spider_mbase_share::append_show_records()
for (roop_count = 0; roop_count < (int) spider_share->all_link_count;
roop_count++)
{
- show_records[roop_count].init_calc_mem(92);
+ show_records[roop_count].init_calc_mem(SPD_MID_MBASE_SHARE_APPEND_SHOW_RECORDS_1);
if (spider_share->sql_dbton_ids[roop_count] != dbton_id)
continue;
@@ -8068,8 +7787,8 @@ int spider_mbase_share::append_show_index()
for (roop_count = 0; roop_count < (int) spider_share->all_link_count;
roop_count++)
{
- show_index[0 + (2 * roop_count)].init_calc_mem(93);
- show_index[1 + (2 * roop_count)].init_calc_mem(94);
+ show_index[0 + (2 * roop_count)].init_calc_mem(SPD_MID_MBASE_SHARE_APPEND_SHOW_INDEX_1);
+ show_index[1 + (2 * roop_count)].init_calc_mem(SPD_MID_MBASE_SHARE_APPEND_SHOW_INDEX_2);
if (spider_share->sql_dbton_ids[roop_count] != dbton_id)
continue;
@@ -8202,7 +7921,7 @@ int spider_mbase_share::discover_table_structure(
uint strlen = str->length();
DBUG_ENTER("spider_mbase_share::discover_table_structure");
DBUG_PRINT("info",("spider this=%p", this));
- sql_str.init_calc_mem(228);
+ sql_str.init_calc_mem(SPD_MID_MBASE_SHARE_DISCOVER_TABLE_STRUCTURE_1);
for (roop_count = 0; roop_count < (int) spider_share->all_link_count;
roop_count++)
{
@@ -8536,7 +8255,7 @@ spider_mbase_handler::spider_mbase_handler(
{
DBUG_ENTER("spider_mbase_handler::spider_mbase_handler");
DBUG_PRINT("info",("spider this=%p", this));
- spider_alloc_calc_mem_init(mem_calc, 183);
+ spider_alloc_calc_mem_init(mem_calc, SPD_MID_MBASE_HANDLER_SPIDER_MBASE_HANDLER_1);
spider_alloc_calc_mem(spider_current_trx, mem_calc, sizeof(*this));
DBUG_VOID_RETURN;
}
@@ -8609,14 +8328,14 @@ int spider_mbase_handler::init()
TABLE *table = spider->get_table();
DBUG_ENTER("spider_mbase_handler::init");
DBUG_PRINT("info",("spider this=%p", this));
- sql.init_calc_mem(59);
- sql_part.init_calc_mem(60);
- sql_part2.init_calc_mem(61);
- ha_sql.init_calc_mem(62);
- insert_sql.init_calc_mem(64);
- update_sql.init_calc_mem(65);
- tmp_sql.init_calc_mem(66);
- dup_update_sql.init_calc_mem(166);
+ sql.init_calc_mem(SPD_MID_MBASE_HANDLER_INIT_1);
+ sql_part.init_calc_mem(SPD_MID_MBASE_HANDLER_INIT_2);
+ sql_part2.init_calc_mem(SPD_MID_MBASE_HANDLER_INIT_3);
+ ha_sql.init_calc_mem(SPD_MID_MBASE_HANDLER_INIT_4);
+ insert_sql.init_calc_mem(SPD_MID_MBASE_HANDLER_INIT_5);
+ update_sql.init_calc_mem(SPD_MID_MBASE_HANDLER_INIT_6);
+ tmp_sql.init_calc_mem(SPD_MID_MBASE_HANDLER_INIT_7);
+ dup_update_sql.init_calc_mem(SPD_MID_MBASE_HANDLER_INIT_8);
if (
(sql.real_alloc(init_sql_alloc_size)) ||
(insert_sql.real_alloc(init_sql_alloc_size)) ||
@@ -8636,7 +8355,7 @@ int spider_mbase_handler::init()
upd_tmp_tbl_prm.init();
upd_tmp_tbl_prm.field_count = 1;
if (!(link_for_hash = (SPIDER_LINK_FOR_HASH *)
- spider_bulk_alloc_mem(spider_current_trx, 141,
+ spider_bulk_alloc_mem(spider_current_trx, SPD_MID_MBASE_HANDLER_INIT_9,
__func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
&link_for_hash,
sizeof(SPIDER_LINK_FOR_HASH) * share->link_count,
@@ -8740,7 +8459,7 @@ int spider_mbase_handler::append_key_column_types(
spider_string tmp_str(tmp_buf, sizeof(tmp_buf), system_charset_info);
DBUG_ENTER("spider_mbase_handler::append_key_column_types");
DBUG_PRINT("info",("spider this=%p", this));
- tmp_str.init_calc_mem(115);
+ tmp_str.init_calc_mem(SPD_MID_MBASE_HANDLER_APPEND_KEY_COLUMN_TYPES_1);
start_key_part_map = start_key->keypart_map & full_key_part_map;
DBUG_PRINT("info", ("spider spider_user_defined_key_parts=%u",
@@ -8870,7 +8589,7 @@ int spider_mbase_handler::append_tmp_table_and_sql_for_bka(
const char *table_names[2], *table_aliases[2], *table_dot_aliases[2];
uint table_name_lengths[2], table_alias_lengths[2],
table_dot_alias_lengths[2];
- tgt_table_name_str.init_calc_mem(99);
+ tgt_table_name_str.init_calc_mem(SPD_MID_MBASE_HANDLER_APPEND_TMP_TABLE_AND_SQL_FOR_BKA_1);
tgt_table_name_str.length(0);
create_tmp_bka_table_name(tmp_table_name, &tmp_table_name_length,
first_link_idx);
@@ -9121,7 +8840,7 @@ int spider_mbase_handler::append_union_table_and_sql_for_bka(
const char *table_names[2], *table_aliases[2], *table_dot_aliases[2];
uint table_name_lengths[2], table_alias_lengths[2],
table_dot_alias_lengths[2];
- tgt_table_name_str.init_calc_mem(233);
+ tgt_table_name_str.init_calc_mem(SPD_MID_MBASE_HANDLER_APPEND_UNION_TABLE_AND_SQL_FOR_BKA_1);
tgt_table_name_str.length(0);
if ((error_num = append_table_name_with_adjusting(&tgt_table_name_str,
first_link_idx, SPIDER_SQL_TYPE_SELECT_SQL)))
@@ -11107,7 +10826,7 @@ int spider_mbase_handler::append_match_against(
char buf[MAX_FIELD_WIDTH];
spider_string tmp_str(buf, MAX_FIELD_WIDTH, share->access_charset);
- tmp_str.init_calc_mem(116);
+ tmp_str.init_calc_mem(SPD_MID_MBASE_HANDLER_APPEND_MATCH_AGAINST_1);
tmp_str.length(0);
if (
tmp_str.append(ft_init_key->ptr(), ft_init_key->length(),
@@ -13223,14 +12942,10 @@ int spider_mbase_handler::set_sql_for_exec(
int link_idx,
SPIDER_LINK_IDX_CHAIN *link_idx_chain
) {
- int error_num;
DBUG_ENTER("spider_mbase_handler::set_sql_for_exec");
DBUG_PRINT("info",("spider this=%p", this));
if (sql_type & SPIDER_SQL_TYPE_SELECT_SQL)
{
- if ((error_num = spider_db_mbase_utility->reappend_tables(
- spider->fields, link_idx_chain, &sql)))
- DBUG_RETURN(error_num);
exec_sql = &sql;
}
DBUG_RETURN(0);
@@ -13264,7 +12979,7 @@ int spider_mbase_handler::set_sql_for_exec(
mysql_share->db_names_str[link_idx].charset());
const char *table_names[2], *table_aliases[2];
uint table_name_lengths[2], table_alias_lengths[2];
- tgt_table_name_str.init_calc_mem(104);
+ tgt_table_name_str.init_calc_mem(SPD_MID_MBASE_HANDLER_SET_SQL_FOR_EXEC_1);
tgt_table_name_str.length(0);
if (result_list->tmp_table_join && spider->bka_mode != 2)
{
@@ -15213,7 +14928,7 @@ int spider_mbase_handler::init_union_table_name_pos()
DBUG_PRINT("info",("spider this=%p", this));
if (!union_table_name_pos_first)
{
- if (!spider_bulk_malloc(spider_current_trx, 236, MYF(MY_WME),
+ if (!spider_bulk_malloc(spider_current_trx, SPD_MID_MBASE_HANDLER_INIT_UNION_TABLE_NAME_POS_1, MYF(MY_WME),
&union_table_name_pos_first, (uint) (sizeof(SPIDER_INT_HLD)),
NullS)
) {
@@ -15234,7 +14949,7 @@ int spider_mbase_handler::set_union_table_name_pos()
{
if (!union_table_name_pos_current->next)
{
- if (!spider_bulk_malloc(spider_current_trx, 237, MYF(MY_WME),
+ if (!spider_bulk_malloc(spider_current_trx, SPD_MID_MBASE_HANDLER_SET_UNION_TABLE_NAME_POS_1, MYF(MY_WME),
&union_table_name_pos_current->next, (uint) (sizeof(SPIDER_INT_HLD)),
NullS)
) {
@@ -15296,8 +15011,7 @@ int spider_mbase_handler::append_from_and_tables_part(
default:
DBUG_RETURN(0);
}
- fields->set_pos_to_first_table_holder();
- table_holder = fields->get_next_table_holder();
+ table_holder = fields->get_first_table_holder();
table_list = table_holder->table->pos_in_table_list;
error_num = spider_db_mbase_utility->append_from_and_tables(
table_holder->spider, fields, str,
@@ -15305,27 +15019,6 @@ int spider_mbase_handler::append_from_and_tables_part(
DBUG_RETURN(error_num);
}
-int spider_mbase_handler::reappend_tables_part(
- spider_fields *fields,
- ulong sql_type
-) {
- int error_num;
- spider_string *str;
- DBUG_ENTER("spider_mbase_handler::reappend_tables_part");
- DBUG_PRINT("info",("spider this=%p", this));
- switch (sql_type)
- {
- case SPIDER_SQL_TYPE_SELECT_SQL:
- str = &sql;
- break;
- default:
- DBUG_RETURN(0);
- }
- error_num = spider_db_mbase_utility->reappend_tables(fields,
- link_idx_chain, str);
- DBUG_RETURN(error_num);
-}
-
int spider_mbase_handler::append_where_part(
ulong sql_type
) {
@@ -15678,7 +15371,7 @@ int spider_mbase_copy_table::init()
{
DBUG_ENTER("spider_mbase_copy_table::init");
DBUG_PRINT("info",("spider this=%p", this));
- sql.init_calc_mem(78);
+ sql.init_calc_mem(SPD_MID_MBASE_COPY_TABLE_INIT_1);
DBUG_RETURN(0);
}