From 18990f007366863e2066c2905993358ceb941ce3 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Fri, 15 Sep 2023 13:15:33 +1000 Subject: [PATCH] MDEV-32157 MDEV-28856 Spider: Tests, documentation, small fixes and cleanups Removed some redundant hint related string literals from spd_db_conn.cc Clean up SPIDER_PARAM_*_[CHAR]LEN[S] Adding tests covering monitoring_kind=2. What it does is that it reads from mysql.spider_link_mon_servers with matching db_name, table_name, link_id, and does not do anything about that... How monitoring_* can be useful: in the deprecated spider high availability feature, when one remote fails, spider will try another remote, which apparently makes use of these table parameters. A test covering the query_cache_sync table param. Some further tests on some spider table params. Wrapper should be case insensitive. Code documentation on spider priority binary tree. Add an assertion that static_key_cardinality is always -1. All tests pass still --- storage/spider/ha_spider.cc | 4 + .../spider/bugfix/r/mdev_28856.result | 180 ++++++++++++++++++ .../spider/bugfix/t/mdev_28856.test | 163 ++++++++++++++++ storage/spider/spd_conn.cc | 13 ++ storage/spider/spd_copy_tables.cc | 25 ++- storage/spider/spd_db_conn.cc | 35 ++-- storage/spider/spd_direct_sql.cc | 24 +-- storage/spider/spd_include.h | 9 + storage/spider/spd_table.cc | 137 ++++++------- 9 files changed, 479 insertions(+), 111 deletions(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 7c5e7b86200..8b4cb85730c 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -8997,6 +8997,10 @@ ha_rows ha_spider::records_in_range( dbton_id = share->sql_dbton_ids[search_link_idx]; dbton_hdl = dbton_handler[dbton_id]; crd_mode = dbton_hdl->crd_mode_exchange(crd_mode); + /* This assertion simply demonstrates that the + static_key_cardinality field is unused. It will be deprecated + (MDEV-28861) and removed (MDEV-31146). */ + DBUG_ASSERT(share->static_key_cardinality[inx] == -1); if (crd_mode == 1 || crd_mode == 2) { DBUG_PRINT("info", ("spider static_key_cardinality[%u]=%lld", inx, diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result new file mode 100644 index 00000000000..fae3cc6b6ce --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result @@ -0,0 +1,180 @@ +# +# MDEV-28856 Spider: Implement more engine-defined options +# +for master_1 +for child2 +for child3 +CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); +# testing monitoring_* +INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server) VALUES +('test', 't1', '0', 1, 'srv'); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_kind "2"'; +/* 1 */ insert into t1 values (42); +ERROR HY000: Table 'test.t2' get a problem +/* 2 */ insert into t1 values (42); +ERROR HY000: All links of 'test.t1' are failed +create table t2 (c int); +/* 3 */ insert into t1 values (42); +ERROR HY000: All links of 'test.t1' are failed +drop table t1, t2; +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_bg_kind "2", + monitoring_bg_interval "500000"'; +/* 4 */ insert into t1 values (42); +ERROR 42S02: Table 'test.t2' doesn't exist +drop table t1; +# testing query_cache_sync +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", query_cache_sync "3"'; +create table t2 (c int); +/* 5 */ insert into t1 values (42); +select sql_cache * from t1; +c +42 +select sql_no_cache * from t1; +c +42 +drop table t1, t2; +# testing tgt_pk_names +create table t2 (c int); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 6 */ insert ignore into t1 values (42), (42); +select * from t1; +c +42 +42 +drop table t1, t2; +create table t2 (c int, primary key (c)); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 7 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1022 Can't write; duplicate key in table 't1' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, primary key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 8 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1062 Duplicate entry '42' for key 'PRIMARY' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, primary key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"'; +/* 9 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1022 Can't write; duplicate key in table 't1' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, unique key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"'; +/* 9.1 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1062 Duplicate entry '42' for key 'PRIMARY' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, unique key (c)); +create table t1 (c int, key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "f"'; +/* 10 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1062 Duplicate entry '42' for key 'c' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, primary key (c)); +create table t1 (c int, key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"'; +/* 11 */ insert ignore into t1 values (42), (42); +Warnings: +Warning 1022 Can't write; duplicate key in table 't1' +select * from t1; +c +42 +drop table t1, t2; +create table t2 (c int, d int, unique key (c), unique key (d)); +create table t1 (c int, d int, key (c), key (d)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"'; +/* 12 */ insert ignore into t1 values (42, 43), (43, 43); +Warnings: +Warning 1062 Duplicate entry '43' for key 'd' +select * from t1; +c d +42 43 +drop table t1, t2; +# Testing index hint +create table t2 (c int, d int, primary key (c), key (d)); +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c` int(11) NOT NULL, + `d` int(11) DEFAULT NULL, + PRIMARY KEY (`c`), + KEY `d` (`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +create table t1 (c int, d int, primary key (c), key (d)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f d"'; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) NOT NULL, + `d` int(11) DEFAULT NULL, + PRIMARY KEY (`c`), + KEY `d` (`d`) +) ENGINE=SPIDER DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f d"' +/* 13 */ insert into t1 values (42, 23), (37, 93); +select max(d) from t1; +max(d) +93 +drop table t1, t2; +create table t2 (c int, d int, e int, primary key (c), key (d), unique key (e)); +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c` int(11) NOT NULL, + `d` int(11) DEFAULT NULL, + `e` int(11) DEFAULT NULL, + PRIMARY KEY (`c`), + UNIQUE KEY `e` (`e`), + KEY `d` (`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +create table t1 (c int, d int, e int, primary key (c), key (d), unique key (e)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f PRIMARY", idx001 "u d", idx002 "ig e"'; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) NOT NULL, + `d` int(11) DEFAULT NULL, + `e` int(11) DEFAULT NULL, + PRIMARY KEY (`c`), + UNIQUE KEY `e` (`e`), + KEY `d` (`d`) +) ENGINE=SPIDER DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f PRIMARY", idx001 "u d", idx002 "ig e"' +/* 14 */ insert into t1 values (42, 23, 89), (37, 93, 47); +select max(d) from t1; +max(d) +93 +drop table t1, t2; +drop server srv; +for master_1 +for child2 +for child3 +# +# end of test mdev_28856 +# diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test new file mode 100644 index 00000000000..4f23168ec1b --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test @@ -0,0 +1,163 @@ +--echo # +--echo # MDEV-28856 Spider: Implement more engine-defined options +--echo # +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +# This test covers some table params under consideration for inclusion +# in the engine-defined options to be implemented in MDEV-28856. +evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql +OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root'); + +--echo # testing monitoring_* +INSERT INTO mysql.spider_link_mon_servers +(db_name, table_name, link_id, sid, server) VALUES +('test', 't1', '0', 1, 'srv'); + +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_kind "2"'; + +--error 12511 +/* 1 */ insert into t1 values (42); +--error 12514 +/* 2 */ insert into t1 values (42); +create table t2 (c int); +# Even though the table is available now, we still get "all links +# failed" error +--error 12514 +/* 3 */ insert into t1 values (42); +drop table t1, t2; + +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", monitoring_bg_kind "2", + monitoring_bg_interval "500000"'; + +# The monitoring thread was killed before it could ping the remote +# table, so the error is not 12511 or 12514 +--error ER_NO_SUCH_TABLE +/* 4 */ insert into t1 values (42); +drop table t1; + +--echo # testing query_cache_sync +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", query_cache_sync "3"'; +create table t2 (c int); +/* 5 */ insert into t1 values (42); +select sql_cache * from t1; +select sql_no_cache * from t1; + +drop table t1, t2; + +--echo # testing tgt_pk_names +# can insert duplicates... +create table t2 (c int); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 6 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# pk_names not used because no key declared in t1, 1022 +create table t2 (c int, primary key (c)); +create table t1 (c int) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 7 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# pk_name is the default "PRIMARY", 1062 +create table t2 (c int, primary key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"'; +/* 8 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# key name c does not match PRIMARY, 1022 +create table t2 (c int, primary key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"'; +/* 9 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# local primary key name c matches remote unique key name c, 1062 but +# warning says PRIMARY instead of c, because key->name is PRIMARY +# instead of c +create table t2 (c int, unique key (c)); +create table t1 (c int, primary key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "c"'; +/* 9.1 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# key name f does not match t2 key name, but it is not used any way +# because there's no primary key, 1062 +create table t2 (c int, unique key (c)); +create table t1 (c int, key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "f"'; +/* 10 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# key name blah does not match t2 error key name PRIMARY, and the +# non-primary key-route does not return PRIMARY, 1022 +create table t2 (c int, primary key (c)); +create table t1 (c int, key (c)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"'; +/* 11 */ insert ignore into t1 values (42), (42); +select * from t1; + +drop table t1, t2; + +# key name blah does not match t2 key name, but still 1062, because we +# go through the non-primary key route +create table t2 (c int, d int, unique key (c), unique key (d)); +create table t1 (c int, d int, key (c), key (d)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", pk_name "blah"'; +/* 12 */ insert ignore into t1 values (42, 43), (43, 43); +select * from t1; + +drop table t1, t2; + +--echo # Testing index hint +create table t2 (c int, d int, primary key (c), key (d)); +show create table t2; +create table t1 (c int, d int, primary key (c), key (d)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f d"'; +show create table t1; +/* 13 */ insert into t1 values (42, 23), (37, 93); +select max(d) from t1; + +drop table t1, t2; + +# multiple indices +create table t2 (c int, d int, e int, primary key (c), key (d), unique key (e)); +show create table t2; +create table t1 (c int, d int, e int, primary key (c), key (d), unique key (e)) ENGINE=Spider +COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2", idx000 "f PRIMARY", idx001 "u d", idx002 "ig e"'; +show create table t1; +/* 14 */ insert into t1 values (42, 23, 89), (37, 93, 47); +select max(d) from t1; + +drop table t1, t2; + +drop server srv; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--echo # +--echo # end of test mdev_28856 +--echo # diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index 4998c07370f..8c2a9d81e2b 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -1615,6 +1615,11 @@ void spider_conn_set_timeout_from_direct_sql( DBUG_VOID_RETURN; } +/** + Insert a connection to a binary tree ordered by priority + + Starting from `top', find the correct spot for `conn' and insert it. +*/ void spider_tree_insert( SPIDER_CONN *top, SPIDER_CONN *conn @@ -1652,6 +1657,7 @@ void spider_tree_insert( DBUG_VOID_RETURN; } +/* Returns the connection with the smallest priority in a tree */ SPIDER_CONN *spider_tree_first( SPIDER_CONN *top ) { @@ -1667,6 +1673,7 @@ SPIDER_CONN *spider_tree_first( DBUG_RETURN(current); } +/* Returns the connection with the biggest priority in a tree */ SPIDER_CONN *spider_tree_last( SPIDER_CONN *top ) { @@ -1682,6 +1689,12 @@ SPIDER_CONN *spider_tree_last( DBUG_RETURN(current); } +/* + Returns the next connection + + Find the connection in the tree with the smallest priority that is + bigger than that of the current connection. +*/ SPIDER_CONN *spider_tree_next( SPIDER_CONN *current ) { diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc index f898bf5d1cc..9128161dae9 100644 --- a/storage/spider/spd_copy_tables.cc +++ b/storage/spider/spd_copy_tables.cc @@ -73,21 +73,20 @@ int spider_udf_set_copy_tables_param_default( DBUG_RETURN(0); } -#define SPIDER_PARAM_STR_LEN(name) name ## _length -#define SPIDER_PARAM_STR(title_name, param_name) \ - if (!strncasecmp(parse.start_title, title_name, title_length)) \ - { \ - DBUG_PRINT("info",("spider " title_name " start")); \ - if (!copy_tables->param_name) \ - { \ +#define SPIDER_PARAM_LEN(name) name ## _length +#define SPIDER_PARAM_STR(title_name, param_name) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!copy_tables->param_name) \ + { \ if ((copy_tables->param_name = spider_create_string(parse.start_value, \ value_length))) \ - copy_tables->SPIDER_PARAM_STR_LEN(param_name) = \ - strlen(copy_tables->param_name); \ - else { \ - error_num= parse.fail(true); \ - goto error; \ - } \ + copy_tables->SPIDER_PARAM_LEN(param_name) = strlen(copy_tables->param_name); \ + else { \ + error_num= parse.fail(true); \ + goto error; \ + } \ DBUG_PRINT("info",("spider " title_name "=%s", copy_tables->param_name)); \ } \ break; \ diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 7250b53c192..cc8637ca488 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -58,12 +58,6 @@ extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; #define SPIDER_SQL_COALESCE_LEN (sizeof(SPIDER_SQL_COALESCE_STR) - 1) #define SPIDER_SQL_HEX_STR "0x" #define SPIDER_SQL_HEX_LEN (sizeof(SPIDER_SQL_HEX_STR) - 1) -#define SPIDER_SQL_SQL_FORCE_IDX_STR " force index(" -#define SPIDER_SQL_SQL_FORCE_IDX_LEN (sizeof(SPIDER_SQL_SQL_FORCE_IDX_STR) - 1) -#define SPIDER_SQL_SQL_USE_IDX_STR " use index(" -#define SPIDER_SQL_SQL_USE_IDX_LEN (sizeof(SPIDER_SQL_SQL_USE_IDX_STR) - 1) -#define SPIDER_SQL_SQL_IGNORE_IDX_STR " ignore index(" -#define SPIDER_SQL_SQL_IGNORE_IDX_LEN (sizeof(SPIDER_SQL_SQL_IGNORE_IDX_STR) - 1) #define SPIDER_SQL_SET_NAMES_STR "set names " #define SPIDER_SQL_SET_NAMES_LEN sizeof(SPIDER_SQL_SET_NAMES_STR) - 1 @@ -1599,34 +1593,37 @@ int spider_db_append_key_hint( if (hint_str_len >= 2 && (hint_str[0] == 'f' || hint_str[0] == 'F') && hint_str[1] == ' ' ) { - if (str->reserve(hint_str_len - 2 + - SPIDER_SQL_SQL_FORCE_IDX_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) + if (str->reserve( + hint_str_len - 2 + SPIDER_SQL_INDEX_FORCE_LEN + + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); hint_str += 2; - str->q_append(SPIDER_SQL_SQL_FORCE_IDX_STR, SPIDER_SQL_SQL_FORCE_IDX_LEN); + str->q_append(SPIDER_SQL_INDEX_FORCE_STR, SPIDER_SQL_INDEX_FORCE_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); str->q_append(hint_str, hint_str_len - 2); str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); } else if (hint_str_len >= 2 && (hint_str[0] == 'u' || hint_str[0] == 'U') && hint_str[1] == ' ' ) { - if (str->reserve(hint_str_len - 2 + - SPIDER_SQL_SQL_USE_IDX_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) - DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->reserve( + hint_str_len - 2 + SPIDER_SQL_INDEX_USE_LEN + + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) hint_str += 2; - str->q_append(SPIDER_SQL_SQL_USE_IDX_STR, SPIDER_SQL_SQL_USE_IDX_LEN); + str->q_append(SPIDER_SQL_INDEX_USE_STR, SPIDER_SQL_INDEX_USE_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); str->q_append(hint_str, hint_str_len - 2); str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); } else if (hint_str_len >= 3 && (hint_str[0] == 'i' || hint_str[0] == 'I') && (hint_str[1] == 'g' || hint_str[1] == 'G') && hint_str[2] == ' ' ) { - if (str->reserve(hint_str_len - 3 + - SPIDER_SQL_SQL_IGNORE_IDX_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) - DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (str->reserve( + hint_str_len - 3 + SPIDER_SQL_INDEX_IGNORE_LEN + + SPIDER_SQL_OPEN_PAREN_LEN + SPIDER_SQL_CLOSE_PAREN_LEN)) hint_str += 3; - str->q_append( - SPIDER_SQL_SQL_IGNORE_IDX_STR, SPIDER_SQL_SQL_IGNORE_IDX_LEN); - str->q_append(hint_str, hint_str_len - 3); + str->q_append(SPIDER_SQL_INDEX_IGNORE_STR, SPIDER_SQL_INDEX_IGNORE_LEN); + str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); + str->q_append(hint_str, hint_str_len - 2); str->q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); } else if (str->reserve(hint_str_len + SPIDER_SQL_SPACE_LEN)) DBUG_RETURN(HA_ERR_OUT_OF_MEM); diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc index dfbb0e04a81..53578623cc8 100644 --- a/storage/spider/spd_direct_sql.cc +++ b/storage/spider/spd_direct_sql.cc @@ -976,20 +976,20 @@ error: DBUG_RETURN(error_num); } -#define SPIDER_PARAM_STR_LEN(name) name ## _length -#define SPIDER_PARAM_STR(title_name, param_name) \ - if (!strncasecmp(parse.start_title, title_name, title_length)) \ - { \ - DBUG_PRINT("info",("spider " title_name " start")); \ - if (!direct_sql->param_name) \ - { \ +#define SPIDER_PARAM_LEN(name) name ## _length +#define SPIDER_PARAM_STR(title_name, param_name) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!direct_sql->param_name) \ + { \ if ((direct_sql->param_name = spider_create_string(parse.start_value, \ value_length))) \ - direct_sql->SPIDER_PARAM_STR_LEN(param_name) = strlen(direct_sql->param_name); \ - else { \ - error_num= parse.fail(true); \ - goto error; \ - } \ + direct_sql->SPIDER_PARAM_LEN(param_name) = strlen(direct_sql->param_name); \ + else { \ + error_num= parse.fail(true); \ + goto error; \ + } \ DBUG_PRINT("info",("spider " title_name "=%s", direct_sql->param_name)); \ } \ break; \ diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h index 81d812280d7..9c49ace318e 100644 --- a/storage/spider/spd_include.h +++ b/storage/spider/spd_include.h @@ -461,9 +461,18 @@ typedef struct st_spider_conn THD *thd; void *another_ha_first; void *another_ha_last; + /* Exactly one of p_small and p_big is not null */ + /* The parent node in the binary tree ordered by priority with a + smaller or equal priority */ st_spider_conn *p_small; + /* The parent node in the binary tree ordered by priority with a + bigger priority */ st_spider_conn *p_big; + /* The child node in the binary tree ordered by priority with a + smaller priority */ st_spider_conn *c_small; + /* The child node in the binary tree ordered by priority with a + bigger or equal priority */ st_spider_conn *c_big; longlong priority; bool server_lost; diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 30dc049213d..4c56edc92e6 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -1563,42 +1563,42 @@ static int spider_set_ll_value( DBUG_RETURN(error_num); } -#define SPIDER_PARAM_STR_LEN(name) name ## _length -#define SPIDER_PARAM_STR(title_name, param_name) \ - if (!strncasecmp(parse.start_title, title_name, title_length)) \ - { \ - DBUG_PRINT("info",("spider " title_name " start")); \ - if (!share->param_name) \ - { \ - if ((share->param_name = spider_create_string(parse.start_value, \ - value_length))) \ - share->SPIDER_PARAM_STR_LEN(param_name) = strlen(share->param_name); \ - else { \ - error_num= parse.fail(true); \ - goto error; \ - } \ +#define SPIDER_PARAM_LEN(name) name ## _length +#define SPIDER_PARAM_LENS(name) name ## _lengths +#define SPIDER_PARAM_CHARLEN(name) name ## _charlen +#define SPIDER_PARAM_STR(title_name, param_name) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!share->param_name) \ + { \ + if ((share->param_name = spider_create_string(parse.start_value, \ + value_length))) \ + share->SPIDER_PARAM_LEN(param_name) = strlen(share->param_name); \ + else { \ + error_num= parse.fail(true); \ + goto error; \ + } \ DBUG_PRINT("info",("spider " title_name "=%s", share->param_name)); \ } \ break; \ } -#define SPIDER_PARAM_STR_LENS(name) name ## _lengths -#define SPIDER_PARAM_STR_CHARLEN(name) name ## _charlen -#define SPIDER_PARAM_STR_LIST(title_name, param_name) \ - if (!strncasecmp(parse.start_title, title_name, title_length)) \ - { \ - DBUG_PRINT("info", ("spider " title_name " start")); \ - if (!share->param_name) \ - { \ - share->SPIDER_PARAM_STR_CHARLEN(param_name)= value_length; \ - if ((error_num= spider_create_string_list( \ - &share->param_name, \ - &share->SPIDER_PARAM_STR_LENS(param_name), \ - &share->SPIDER_PARAM_STR_LEN(param_name), \ - parse.start_value, \ - share->SPIDER_PARAM_STR_CHARLEN(param_name)))) \ - goto error; \ - } \ - break; \ +#define SPIDER_PARAM_STR_LIST(title_name, param_name) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info", ("spider " title_name " start")); \ + if (!share->param_name) \ + { \ + share->SPIDER_PARAM_CHARLEN(param_name)= value_length; \ + if ((error_num= spider_create_string_list( \ + &share->param_name, \ + &share->SPIDER_PARAM_LENS(param_name), \ + &share->SPIDER_PARAM_LEN(param_name), \ + parse.start_value, \ + share->SPIDER_PARAM_CHARLEN(param_name)))) \ + goto error; \ + } \ + break; \ } #define SPIDER_PARAM_HINT(title_name, param_name, check_length, max_size, append_method) \ if (!strncasecmp(parse.start_title, title_name, check_length)) \ @@ -1655,41 +1655,39 @@ static int spider_set_ll_value( } \ break; \ } -#define SPIDER_PARAM_LONG_LEN(name) name ## _length -#define SPIDER_PARAM_LONG_LIST_WITH_MAX(title_name, param_name, \ - min_val, max_val) \ - if (!strncasecmp(parse.start_title, title_name, title_length)) \ - { \ - DBUG_PRINT("info",("spider " title_name " start")); \ - if (!share->param_name) \ - { \ - if ((error_num = spider_create_long_list( \ - &share->param_name, \ - &share->SPIDER_PARAM_LONG_LEN(param_name), \ - parse.start_value, \ - value_length, \ - min_val, max_val))) \ - goto error; \ - } \ - break; \ +#define SPIDER_PARAM_LONG_LIST_WITH_MAX(title_name, param_name, \ + min_val, max_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!share->param_name) \ + { \ + if ((error_num = spider_create_long_list( \ + &share->param_name, \ + &share->SPIDER_PARAM_LEN(param_name), \ + parse.start_value, \ + value_length, \ + min_val, max_val))) \ + goto error; \ + } \ + break; \ } -#define SPIDER_PARAM_LONGLONG_LEN(name) name ## _length #define SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(title_name, param_name, \ - min_val, max_val) \ - if (!strncasecmp(parse.start_title, title_name, title_length)) \ - { \ - DBUG_PRINT("info",("spider " title_name " start")); \ - if (!share->param_name) \ - { \ - if ((error_num = spider_create_longlong_list( \ - &share->param_name, \ - &share->SPIDER_PARAM_LONGLONG_LEN(param_name), \ - parse.start_value, \ - value_length, \ - min_val, max_val))) \ - goto error; \ - } \ - break; \ + min_val, max_val) \ + if (!strncasecmp(parse.start_title, title_name, title_length)) \ + { \ + DBUG_PRINT("info",("spider " title_name " start")); \ + if (!share->param_name) \ + { \ + if ((error_num = spider_create_longlong_list( \ + &share->param_name, \ + &share->SPIDER_PARAM_LEN(param_name), \ + parse.start_value, \ + value_length, \ + min_val, max_val))) \ + goto error; \ + } \ + break; \ } #define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \ if (!strncasecmp(parse.start_title, title_name, title_length)) \ @@ -1747,6 +1745,10 @@ static int spider_set_ll_value( break; \ } +/** + Assign -1 to some `SPIDER_SHARE' numeric fields, to indicate they + have not been specified by the user yet. +*/ static void spider_minus_1(SPIDER_SHARE *share, TABLE_SHARE *table_share) { #ifndef WITHOUT_SPIDER_BG_SEARCH @@ -2113,6 +2115,7 @@ int spider_parse_connect_info( connect_string = NULL; } + /* Get the correct connect info for the current level. */ int error_num_1 = spider_get_connect_info(i, part_elem, sub_elem, table_share, connect_string); if (error_num_1 == 1) @@ -3140,7 +3143,7 @@ int spider_parse_connect_info( { if ( spider_dbton[roop_count2].wrapper && - !strcmp(share->tgt_wrappers[roop_count], + !strcasecmp(share->tgt_wrappers[roop_count], spider_dbton[roop_count2].wrapper) ) { break; @@ -4080,7 +4083,7 @@ int spider_create_conn_keys( spider_dbton[roop_count2].wrapper : "NULL")); if ( spider_dbton[roop_count2].wrapper && - !strcmp(share->tgt_wrappers[roop_count], + !strcasecmp(share->tgt_wrappers[roop_count], spider_dbton[roop_count2].wrapper) ) { spider_set_bit(share->dbton_bitmap, roop_count2);