summaryrefslogtreecommitdiffstats
path: root/storage/spider
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--storage/spider/ha_spider.cc77
-rw-r--r--storage/spider/ha_spider.h27
-rw-r--r--storage/spider/mysql-test/spider/bg/r/spider3_fixes.result1
-rw-r--r--storage/spider/mysql-test/spider/bg/r/spider3_fixes_part.result1
-rw-r--r--storage/spider/mysql-test/spider/bg/r/spider_fixes.result1
-rw-r--r--storage/spider/mysql-test/spider/bg/r/spider_fixes_part.result1
-rw-r--r--storage/spider/mysql-test/spider/bg/t/slave_test_init.inc2
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_default.result1
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mariadb.result1
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mysql.result1
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result2
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result3
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result3
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_30727.result24
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33242.result4
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result12
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33441.result7
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33441_fail.result10
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result4
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33538.result12
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33538_fail_init.result10
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result4
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result25
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_33731.result10
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_34003.result18
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/plugin_load_add_all.result4
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/slave_transaction_retry_errors_5digit.result3
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result1
-rw-r--r--[l---------]storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result44
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test4
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_30727.test30
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33242.test6
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test15
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33441.opt1
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33441.test10
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.opt2
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.test10
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test11
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33538.opt2
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33538.test2
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33538_fail_init.test17
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test11
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test29
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_33731.test16
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_34003.test20
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_all.test1
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/self_reference_multi.test2
-rw-r--r--storage/spider/mysql-test/spider/feature/r/pushdown_case.result57
-rw-r--r--storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result111
-rw-r--r--storage/spider/mysql-test/spider/feature/r/slave_transaction_retry_errors.result3
-rw-r--r--storage/spider/mysql-test/spider/feature/t/pushdown_case.test50
-rw-r--r--storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test93
-rw-r--r--storage/spider/mysql-test/spider/include/clean_up_spider.inc1
-rw-r--r--storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result2
-rw-r--r--storage/spider/mysql-test/spider/r/slave_trx_isolation.result1
-rw-r--r--storage/spider/mysql-test/spider/r/spider3_fixes.result1
-rw-r--r--storage/spider/mysql-test/spider/r/spider3_fixes_part.result1
-rw-r--r--storage/spider/mysql-test/spider/r/spider_fixes.result1
-rw-r--r--storage/spider/mysql-test/spider/r/spider_fixes_part.result2
-rw-r--r--storage/spider/mysql-test/spider/t/slave_test_init.inc2
-rw-r--r--storage/spider/mysql-test/spider/t/spider_fixes_part.opt1
-rw-r--r--storage/spider/mysql-test/spider/t/spider_fixes_part.test16
-rw-r--r--storage/spider/spd_conn.cc4
-rw-r--r--storage/spider/spd_copy_tables.cc50
-rw-r--r--storage/spider/spd_db_conn.cc14
-rw-r--r--storage/spider/spd_db_include.cc16
-rw-r--r--storage/spider/spd_db_include.h6
-rw-r--r--storage/spider/spd_db_mysql.cc308
-rw-r--r--storage/spider/spd_db_mysql.h5
-rw-r--r--storage/spider/spd_direct_sql.cc162
-rw-r--r--storage/spider/spd_i_s.cc5
-rw-r--r--storage/spider/spd_include.h2
-rw-r--r--storage/spider/spd_init_query.h10
-rw-r--r--storage/spider/spd_ping_table.cc134
-rw-r--r--storage/spider/spd_sys_table.cc60
-rw-r--r--storage/spider/spd_sys_table.h3
-rw-r--r--storage/spider/spd_table.cc76
-rw-r--r--storage/spider/spd_trx.cc2
78 files changed, 1213 insertions, 488 deletions
diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc
index 5b85b3a2..c998fd18 100644
--- a/storage/spider/ha_spider.cc
+++ b/storage/spider/ha_spider.cc
@@ -269,19 +269,19 @@ int ha_spider::open(
spider_bulk_malloc(spider_current_trx, 16, MYF(MY_WME | MY_ZEROFILL),
&wide_handler, sizeof(SPIDER_WIDE_HANDLER),
&searched_bitmap,
- (uint) sizeof(uchar) * no_bytes_in_map(table->read_set),
+ (uint) sizeof(uchar) * my_bitmap_buffer_size(table->read_set),
&ft_discard_bitmap,
- (uint) sizeof(uchar) * no_bytes_in_map(table->read_set),
+ (uint) sizeof(uchar) * my_bitmap_buffer_size(table->read_set),
&position_bitmap,
- (uint) sizeof(uchar) * no_bytes_in_map(table->read_set),
+ (uint) sizeof(uchar) * my_bitmap_buffer_size(table->read_set),
&idx_read_bitmap,
- (uint) sizeof(uchar) * no_bytes_in_map(table->read_set),
+ (uint) sizeof(uchar) * my_bitmap_buffer_size(table->read_set),
&idx_write_bitmap,
- (uint) sizeof(uchar) * no_bytes_in_map(table->read_set),
+ (uint) sizeof(uchar) * my_bitmap_buffer_size(table->read_set),
&rnd_read_bitmap,
- (uint) sizeof(uchar) * no_bytes_in_map(table->read_set),
+ (uint) sizeof(uchar) * my_bitmap_buffer_size(table->read_set),
&rnd_write_bitmap,
- (uint) sizeof(uchar) * no_bytes_in_map(table->read_set),
+ (uint) sizeof(uchar) * my_bitmap_buffer_size(table->read_set),
&partition_handler,
(uint) sizeof(SPIDER_PARTITION_HANDLER),
NullS)
@@ -305,9 +305,9 @@ int ha_spider::open(
wide_handler->top_share = table->s;
owner->wide_handler_owner = TRUE;
memset(wide_handler->ft_discard_bitmap, 0xFF,
- no_bytes_in_map(table->read_set));
+ my_bitmap_buffer_size(table->read_set));
memset(wide_handler->searched_bitmap, 0,
- no_bytes_in_map(table->read_set));
+ my_bitmap_buffer_size(table->read_set));
wide_handler_alloc = TRUE;
if (!share && !spider_get_share(name, table, thd, this, &error_num))
@@ -347,12 +347,23 @@ int ha_spider::open(
result_list.last = NULL;
result_list.current = NULL;
result_list.record_num = 0;
- if (
- !(result_list.sqls = new spider_string[share->link_count]) ||
- !(result_list.insert_sqls = new spider_string[share->link_count]) ||
- !(result_list.update_sqls = new spider_string[share->link_count]) ||
- !(result_list.tmp_sqls = new spider_string[share->link_count])
- ) {
+ if (!(result_list.sqls = new spider_string[share->link_count]))
+ {
+ error_num = HA_ERR_OUT_OF_MEM;
+ goto error_init_result_list;
+ }
+ if (!(result_list.insert_sqls = new spider_string[share->link_count]))
+ {
+ error_num = HA_ERR_OUT_OF_MEM;
+ goto error_init_result_list;
+ }
+ if (!(result_list.update_sqls = new spider_string[share->link_count]))
+ {
+ error_num = HA_ERR_OUT_OF_MEM;
+ goto error_init_result_list;
+ }
+ if (!(result_list.tmp_sqls = new spider_string[share->link_count]))
+ {
error_num = HA_ERR_OUT_OF_MEM;
goto error_init_result_list;
}
@@ -1000,9 +1011,9 @@ int ha_spider::reset()
if (!is_clone)
{
memset(wide_handler->ft_discard_bitmap, 0xFF,
- no_bytes_in_map(table->read_set));
+ my_bitmap_buffer_size(table->read_set));
memset(wide_handler->searched_bitmap, 0,
- no_bytes_in_map(table->read_set));
+ my_bitmap_buffer_size(table->read_set));
}
while (wide_handler->condition)
{
@@ -1230,7 +1241,7 @@ int ha_spider::index_init(
bitmap_set_all(table->read_set);
if (is_clone)
memset(wide_handler->searched_bitmap, 0xFF,
- no_bytes_in_map(table->read_set));
+ my_bitmap_buffer_size(table->read_set));
}
}
@@ -3125,7 +3136,7 @@ ha_rows ha_spider::multi_range_read_info_const(
bitmap_set_all(table->read_set);
if (is_clone)
memset(wide_handler->searched_bitmap, 0xFF,
- no_bytes_in_map(table->read_set));
+ my_bitmap_buffer_size(table->read_set));
}
}
@@ -3178,7 +3189,7 @@ ha_rows ha_spider::multi_range_read_info(
bitmap_set_all(table->read_set);
if (is_clone)
memset(wide_handler->searched_bitmap, 0xFF,
- no_bytes_in_map(table->read_set));
+ my_bitmap_buffer_size(table->read_set));
}
}
@@ -5437,7 +5448,7 @@ int ha_spider::rnd_init(
bitmap_set_all(table->read_set);
if (is_clone)
memset(wide_handler->searched_bitmap, 0xFF,
- no_bytes_in_map(table->read_set));
+ my_bitmap_buffer_size(table->read_set));
}
set_select_column_mode();
@@ -9023,27 +9034,35 @@ bool ha_spider::auto_repair() const
}
int ha_spider::disable_indexes(
- uint mode
+ key_map map, bool persist
) {
int error_num;
backup_error_status();
DBUG_ENTER("ha_spider::disable_indexes");
DBUG_PRINT("info",("spider this=%p", this));
- if ((error_num = spider_db_disable_keys(this)))
- DBUG_RETURN(check_error_mode(error_num));
- DBUG_RETURN(0);
+ if (persist)
+ {
+ if ((error_num = spider_db_disable_keys(this)))
+ DBUG_RETURN(check_error_mode(error_num));
+ DBUG_RETURN(0);
+ }
+ DBUG_RETURN(HA_ERR_WRONG_COMMAND);
}
int ha_spider::enable_indexes(
- uint mode
+ key_map map, bool persist
) {
int error_num;
backup_error_status();
DBUG_ENTER("ha_spider::enable_indexes");
DBUG_PRINT("info",("spider this=%p", this));
- if ((error_num = spider_db_enable_keys(this)))
- DBUG_RETURN(check_error_mode(error_num));
- DBUG_RETURN(0);
+ if (persist)
+ {
+ if ((error_num = spider_db_enable_keys(this)))
+ DBUG_RETURN(check_error_mode(error_num));
+ DBUG_RETURN(0);
+ }
+ DBUG_RETURN(HA_ERR_WRONG_COMMAND);
}
diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h
index 4dffdf78..4c178a33 100644
--- a/storage/spider/ha_spider.h
+++ b/storage/spider/ha_spider.h
@@ -483,10 +483,10 @@ public:
bool auto_repair() const;
#endif
int disable_indexes(
- uint mode
+ key_map map, bool persist
);
int enable_indexes(
- uint mode
+ key_map map, bool persist
);
int check(
THD* thd,
@@ -792,3 +792,26 @@ public:
int lock_tables();
int dml_init();
};
+
+
+/* This is a hack for ASAN
+ * Libraries such as libxml2 and libodbc do not like being unloaded before
+ * exit and will show as a leak in ASAN with no stack trace (as the plugin
+ * has been unloaded from memory).
+ *
+ * The below is designed to trick the compiler into adding a "UNIQUE" symbol
+ * which can be seen using:
+ * readelf -s storage/spider/ha_spider.so | grep UNIQUE
+ *
+ * Having this symbol means that the plugin remains in memory after dlclose()
+ * has been called. Thereby letting the libraries clean up properly.
+ */
+#if defined(__SANITIZE_ADDRESS__)
+__attribute__((__used__))
+inline int dummy(void)
+{
+ static int d;
+ d++;
+ return d;
+}
+#endif
diff --git a/storage/spider/mysql-test/spider/bg/r/spider3_fixes.result b/storage/spider/mysql-test/spider/bg/r/spider3_fixes.result
index aa734573..e3510042 100644
--- a/storage/spider/mysql-test/spider/bg/r/spider3_fixes.result
+++ b/storage/spider/mysql-test/spider/bg/r/spider3_fixes.result
@@ -8,6 +8,7 @@ child3_1
child3_2
child3_3
for slave1_1
+include/start_slave.inc
drop and create databases
connection master_1;
diff --git a/storage/spider/mysql-test/spider/bg/r/spider3_fixes_part.result b/storage/spider/mysql-test/spider/bg/r/spider3_fixes_part.result
index b793346d..361fd336 100644
--- a/storage/spider/mysql-test/spider/bg/r/spider3_fixes_part.result
+++ b/storage/spider/mysql-test/spider/bg/r/spider3_fixes_part.result
@@ -8,6 +8,7 @@ child3_1
child3_2
child3_3
for slave1_1
+include/start_slave.inc
drop and create databases
connection master_1;
diff --git a/storage/spider/mysql-test/spider/bg/r/spider_fixes.result b/storage/spider/mysql-test/spider/bg/r/spider_fixes.result
index 51045e0b..a751d803 100644
--- a/storage/spider/mysql-test/spider/bg/r/spider_fixes.result
+++ b/storage/spider/mysql-test/spider/bg/r/spider_fixes.result
@@ -8,6 +8,7 @@ child3_1
child3_2
child3_3
for slave1_1
+include/start_slave.inc
drop and create databases
connection master_1;
diff --git a/storage/spider/mysql-test/spider/bg/r/spider_fixes_part.result b/storage/spider/mysql-test/spider/bg/r/spider_fixes_part.result
index faf0b6ef..3ce8dfbf 100644
--- a/storage/spider/mysql-test/spider/bg/r/spider_fixes_part.result
+++ b/storage/spider/mysql-test/spider/bg/r/spider_fixes_part.result
@@ -8,6 +8,7 @@ child3_1
child3_2
child3_3
for slave1_1
+include/start_slave.inc
drop and create databases
connection master_1;
diff --git a/storage/spider/mysql-test/spider/bg/t/slave_test_init.inc b/storage/spider/mysql-test/spider/bg/t/slave_test_init.inc
index 739d8897..84de2c7d 100644
--- a/storage/spider/mysql-test/spider/bg/t/slave_test_init.inc
+++ b/storage/spider/mysql-test/spider/bg/t/slave_test_init.inc
@@ -19,7 +19,7 @@ if (!$SLAVE1_1_SLAVE_STATUS)
MASTER_PORT = $MASTER_1_MYPORT
;
}
-START SLAVE;
+--source include/start_slave.inc
--connection master_1
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
--connection slave1_1
diff --git a/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_default.result b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_default.result
index cb1b190f..8b193975 100644
--- a/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_default.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_default.result
@@ -5,6 +5,7 @@ child2_2
child2_3
for child3
for slave1_1
+include/start_slave.inc
connection slave1_1;
connection master_1;
set @old_binlog_format= @@binlog_format;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mariadb.result b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mariadb.result
index cb1b190f..8b193975 100644
--- a/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mariadb.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mariadb.result
@@ -5,6 +5,7 @@ child2_2
child2_3
for child3
for slave1_1
+include/start_slave.inc
connection slave1_1;
connection master_1;
set @old_binlog_format= @@binlog_format;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mysql.result b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mysql.result
index 11310212..1e5d7d31 100644
--- a/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mysql.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/delete_with_float_column_mysql.result
@@ -5,6 +5,7 @@ child2_2
child2_3
for child3
for slave1_1
+include/start_slave.inc
connection slave1_1;
connection master_1;
set @old_binlog_format= @@binlog_format;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result
index 4386b4cb..dbf0f54c 100644
--- a/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_19866.result
@@ -72,7 +72,6 @@ SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argum
argument
select `pkey`,`val` from `auto_test_remote`.`tbl_a`
select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1
-select 1 from (select 1) t0
select `pkey`,`val` from `auto_test_remote`.`tbl_a`
select `pkey`,`val` from `auto_test_remote`.`tbl_a`
SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'
@@ -86,7 +85,6 @@ argument
select `pkey`,`val` from `auto_test_remote2`.`tbl_a`
select `pkey`,`val` from `auto_test_remote2`.`tbl_a`
select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 2
-select 1 from (select 1) t0
select `pkey`,`val` from `auto_test_remote2`.`tbl_a`
SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'
SELECT pkey, val FROM tbl_a ORDER BY pkey;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result
index 531e48b8..60ef8e2d 100644
--- a/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27172.result
@@ -66,9 +66,6 @@ id greeting
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE 'select `id`,`greeting` from %';
argument
-select `id`,`greeting` from `auto_test_remote`.`tbl_a` where `greeting` = 'Aloha!' and ((`greeting` = 'Aloha!'))
-select `id`,`greeting` from `auto_test_remote`.`tbl_b` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!'))
-select `id`,`greeting` from `auto_test_remote`.`tbl_c` where `greeting` like 'Aloha%' and ((`greeting` = 'Aloha!'))
connection child2_1;
SET @@global.general_log = @general_log_backup;
SET @@global.log_output = @log_output_backup;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result
index 7e4fd3cd..5fd412b6 100644
--- a/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28856.result
@@ -5,6 +5,8 @@ for master_1
for child2
for child3
set spider_same_server_link=1;
+set @old_spider_same_server_link=@@global.spider_same_server_link;
+set global spider_same_server_link=1;
CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
# testing monitoring_*
@@ -173,6 +175,7 @@ max(d)
93
drop table t1, t2;
drop server srv;
+set global spider_same_server_link=@old_spider_same_server_link;
for master_1
for child2
for child3
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_30727.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_30727.result
new file mode 100644
index 00000000..79a383fe
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_30727.result
@@ -0,0 +1,24 @@
+CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.so';
+SELECT spider_direct_sql ('SELECT * FROM s','a','srv "b"');
+ERROR HY000: Can't initialize function 'spider_direct_sql'; Plugin 'SPIDER' is not loaded
+CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so';
+SELECT spider_bg_direct_sql ('SELECT * FROM s','a','srv "b"');
+ERROR HY000: Can't initialize function 'spider_bg_direct_sql'; Plugin 'SPIDER' is not loaded
+CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.so';
+SELECT spider_copy_tables ('t', '0', '0');
+ERROR HY000: Can't initialize function 'spider_copy_tables'; Plugin 'SPIDER' is not loaded
+CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.so';
+SELECT spider_flush_table_mon_cache ();
+spider_flush_table_mon_cache ()
+1
+install soname 'ha_spider';
+SELECT spider_direct_sql ('SELECT * FROM s','a','srv "b"');
+ERROR HY000: The foreign server name you are trying to reference does not exist. Data source error: b
+call mtr.add_suppression(".*\\[Error\\] (mysqld|mariadbd): Can't find record in 'spider_tables'");
+SELECT spider_copy_tables ('t', '0', '0');
+ERROR HY000: Can't find record in 'spider_tables'
+SELECT spider_flush_table_mon_cache ();
+spider_flush_table_mon_cache ()
+1
+Warnings:
+Warning 1620 Plugin is busy and will be uninstalled on shutdown
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33242.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33242.result
new file mode 100644
index 00000000..bbbc4499
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33242.result
@@ -0,0 +1,4 @@
+set @old_old_mode=@@global.old_mode;
+set global old_mode=4;
+INSTALL SONAME 'ha_spider.so';
+set global old_mode=@old_old_mode;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result
new file mode 100644
index 00000000..2cbcff38
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33434.result
@@ -0,0 +1,12 @@
+#
+# MDEV-33434 MDEV-33434 UBSAN null pointer passed as argument 2, which is declared to never be null in spider_udf_direct_sql_create_conn
+#
+INSTALL SONAME 'ha_spider';
+SET character_set_connection=ucs2;
+SELECT SPIDER_DIRECT_SQL('SELECT SLEEP(1)', '', 'srv "dummy", port "3307"');
+ERROR HY000: Unable to connect to foreign data source: localhost
+Warnings:
+Warning 1620 Plugin is busy and will be uninstalled on shutdown
+#
+# end of test mdev_33434
+#
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33441.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33441.result
new file mode 100644
index 00000000..b19194f1
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33441.result
@@ -0,0 +1,7 @@
+#
+# MDEV-33441 No spider variables available is Spider is loaded upon server startup
+#
+set spider_same_server_link=0;
+#
+# end of test mdev_33441
+#
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33441_fail.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33441_fail.result
new file mode 100644
index 00000000..e6123ed4
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33441_fail.result
@@ -0,0 +1,10 @@
+#
+# MDEV-33441 No spider variables available is Spider is loaded upon server startup
+#
+select * from mysql.plugin;
+name dl
+show variables like 'spider%';
+Variable_name Value
+#
+# end of test mdev_33441_fail
+#
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result
new file mode 100644
index 00000000..3db28c0f
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33494.result
@@ -0,0 +1,4 @@
+set @old_sql_mode=@@global.sql_mode;
+set global sql_mode=(SELECT CONCAT (@@sql_mode,',no_zero_date'));
+install soname 'ha_spider';
+set global sql_mode=@old_sql_mode;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33538.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33538.result
new file mode 100644
index 00000000..a5ab3c1d
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33538.result
@@ -0,0 +1,12 @@
+show create table information_schema.SPIDER_ALLOC_MEM;
+Table Create Table
+SPIDER_ALLOC_MEM CREATE TEMPORARY TABLE `SPIDER_ALLOC_MEM` (
+ `ID` int(10) unsigned NOT NULL,
+ `FUNC_NAME` varchar(64),
+ `FILE_NAME` varchar(64),
+ `LINE_NO` int(10) unsigned,
+ `TOTAL_ALLOC_MEM` bigint(20) unsigned,
+ `CURRENT_ALLOC_MEM` bigint(20),
+ `ALLOC_MEM_COUNT` bigint(20) unsigned,
+ `FREE_MEM_COUNT` bigint(20) unsigned
+) ENGINE=MEMORY DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33538_fail_init.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33538_fail_init.result
new file mode 100644
index 00000000..7535da83
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33538_fail_init.result
@@ -0,0 +1,10 @@
+call mtr.add_suppression("\\[ERROR\\] SPIDER plugin initialization failed");
+call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER' registration as a STORAGE ENGINE failed.");
+call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER_WRAPPER_PROTOCOLS' registration as a INFORMATION SCHEMA failed.");
+call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER_ALLOC_MEM' registration as a INFORMATION SCHEMA failed.");
+create table mysql.spider_tables (c int);
+# restart: --plugin-load-add=ha_spider
+SELECT * FROM information_schema.SPIDER_ALLOC_MEM;
+ID FUNC_NAME FILE_NAME LINE_NO TOTAL_ALLOC_MEM CURRENT_ALLOC_MEM ALLOC_MEM_COUNT FREE_MEM_COUNT
+SELECT * FROM information_schema.SPIDER_WRAPPER_PROTOCOLS;
+WRAPPER_NAME WRAPPER_VERSION WRAPPER_DESCRIPTION WRAPPER_MATURITY
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result
new file mode 100644
index 00000000..796c75cc
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33584.result
@@ -0,0 +1,4 @@
+set @old_sql_mode=@@global.sql_mode;
+set global sql_mode='traditional';
+install soname 'ha_spider';
+set global sql_mode=@old_sql_mode;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result
new file mode 100644
index 00000000..c021bc70
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33679.result
@@ -0,0 +1,25 @@
+#
+# MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to ()
+#
+for master_1
+for child2
+for child3
+CREATE SERVER srv FOREIGN DATA WRAPPER mysql
+OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
+CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM;
+CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM;
+SET spider_same_server_link= on;
+CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER;
+CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL
+, PRIMARY KEY (`a`) USING BTREE
+) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER;
+INSERT INTO t1_spider VALUES(1,'oooo');
+INSERT INTO t2_spider VALUES(1,1);
+SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1;
+a c
+1 1
+drop table t1, t2, t1_spider, t2_spider;
+drop server srv;
+for master_1
+for child2
+for child3
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_33731.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_33731.result
new file mode 100644
index 00000000..a63830f1
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_33731.result
@@ -0,0 +1,10 @@
+for master_1
+for child2
+for child3
+CREATE TABLE t (a INT) ENGINE=Spider PARTITION BY LIST (a) PARTITIONS 2 (PARTITION p1 VALUES IN (0,1),PARTITION p2 VALUES IN (2,3));
+DELETE FROM t PARTITION (p2);
+ERROR HY000: Unable to connect to foreign data source: localhost
+drop table t;
+for master_1
+for child2
+for child3
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_34003.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_34003.result
new file mode 100644
index 00000000..b78f18d1
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_34003.result
@@ -0,0 +1,18 @@
+for master_1
+for child2
+for child3
+set spider_same_server_link= 1;
+CREATE SERVER srv FOREIGN DATA WRAPPER mysql
+OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
+create table t2 (c INT KEY,c1 BLOB,c2 TEXT) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (0,1,0),(1,0,0),(2,0,0);
+create table t1 (c INT KEY,c1 BLOB,c2 TEXT) ENGINE=Spider
+COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
+SELECT * FROM t1 WHERE c=0;
+c c1 c2
+0 1 0
+drop table t1, t2;
+drop server srv;
+for master_1
+for child2
+for child3
diff --git a/storage/spider/mysql-test/spider/bugfix/r/plugin_load_add_all.result b/storage/spider/mysql-test/spider/bugfix/r/plugin_load_add_all.result
index 04e5ed6d..4d161a2f 100644
--- a/storage/spider/mysql-test/spider/bugfix/r/plugin_load_add_all.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/plugin_load_add_all.result
@@ -3,5 +3,9 @@
#
select * from mysql.plugin;
name dl
+select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = "information_schema" and TABLE_NAME like "SPIDER_%";
+TABLE_NAME
+SPIDER_ALLOC_MEM
+SPIDER_WRAPPER_PROTOCOLS
create table t (c int) Engine=SPIDER;
drop table t;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/slave_transaction_retry_errors_5digit.result b/storage/spider/mysql-test/spider/bugfix/r/slave_transaction_retry_errors_5digit.result
index f2cab6b0..83dab07f 100644
--- a/storage/spider/mysql-test/spider/bugfix/r/slave_transaction_retry_errors_5digit.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/slave_transaction_retry_errors_5digit.result
@@ -5,11 +5,12 @@ child2_2
child2_3
for child3
for slave1_1
+include/start_slave.inc
connection slave1_1;
SHOW VARIABLES LIKE 'slave_transaction_retry_errors';
Variable_name Value
-slave_transaction_retry_errors 1158,1159,1160,1161,1205,1213,1429,2013,12701,10000,20000,30000
+slave_transaction_retry_errors 1158,1159,1160,1161,1205,1213,1020,1429,2013,12701,10000,20000,30000
connection slave1_1;
for slave1_1
for master_1
diff --git a/storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result b/storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result
index e84d42bb..239402a5 100644
--- a/storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/slave_trx_isolation.result
@@ -5,6 +5,7 @@ child2_2
child2_3
for child3
for slave1_1
+include/start_slave.inc
connection slave1_1;
set @old_spider_slave_trx_isolation= @@spider_slave_trx_isolation;
set global spider_slave_trx_isolation= 1;
diff --git a/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result b/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result
index 045ddc43..b84f60a6 120000..100644
--- a/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result
+++ b/storage/spider/mysql-test/spider/bugfix/r/udf_mysql_func_early_init_file.result
@@ -1 +1,43 @@
-udf_mysql_func_early.result \ No newline at end of file
+#
+# Test that udf created by inserting into mysql_func works as expected
+#
+CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
+HOST 'localhost',
+DATABASE 'auto_test_local',
+USER 'root',
+PASSWORD '',
+SOCKET '$MASTER_1_MYSOCK'
+ );
+CREATE SERVER s_2_1 FOREIGN DATA WRAPPER mysql OPTIONS (
+HOST 'localhost',
+DATABASE 'auto_test_remote',
+USER 'root',
+PASSWORD '',
+SOCKET '$CHILD2_1_MYSOCK'
+ );
+connect master_1, localhost, root, , , $MASTER_1_MYPORT, $MASTER_1_MYSOCK;
+connect child2_1, localhost, root, , , $CHILD2_1_MYPORT, $CHILD2_1_MYSOCK;
+connection child2_1;
+CREATE DATABASE auto_test_remote;
+USE auto_test_remote;
+CREATE TABLE tbl_a (
+a INT
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+insert into tbl_a values (42);
+connection master_1;
+CREATE DATABASE auto_test_local;
+USE auto_test_local;
+CREATE TABLE tbl_a (
+a INT
+) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"';
+create temporary table results (a int);
+SELECT SPIDER_DIRECT_SQL('select * from tbl_a', 'results', 'srv "s_2_1", database "auto_test_remote"');
+SPIDER_DIRECT_SQL('select * from tbl_a', 'results', 'srv "s_2_1", database "auto_test_remote"')
+1
+select * from results;
+a
+42
+connection master_1;
+DROP DATABASE IF EXISTS auto_test_local;
+connection child2_1;
+DROP DATABASE IF EXISTS auto_test_remote;
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test
index a1642f7a..9ccfc378 100644
--- a/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28856.test
@@ -10,6 +10,9 @@
# This test covers some table params under consideration for inclusion
# in the engine-defined options to be implemented in MDEV-28856.
set spider_same_server_link=1;
+set @old_spider_same_server_link=@@global.spider_same_server_link;
+set global spider_same_server_link=1;
+
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
@@ -153,6 +156,7 @@ select max(d) from t1;
drop table t1, t2;
drop server srv;
+set global spider_same_server_link=@old_spider_same_server_link;
--disable_query_log
--disable_result_log
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_30727.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_30727.test
new file mode 100644
index 00000000..ebd08edc
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_30727.test
@@ -0,0 +1,30 @@
+CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.so';
+--error ER_CANT_INITIALIZE_UDF
+SELECT spider_direct_sql ('SELECT * FROM s','a','srv "b"');
+
+CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so';
+--error ER_CANT_INITIALIZE_UDF
+SELECT spider_bg_direct_sql ('SELECT * FROM s','a','srv "b"');
+
+CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.so';
+--error ER_CANT_INITIALIZE_UDF
+SELECT spider_copy_tables ('t', '0', '0');
+
+# spider_flush_table_mon_cache does not require spider init to function
+CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.so';
+SELECT spider_flush_table_mon_cache ();
+
+# The function functions properly after the plugin is installed
+install soname 'ha_spider';
+
+--error ER_FOREIGN_SERVER_DOESNT_EXIST
+SELECT spider_direct_sql ('SELECT * FROM s','a','srv "b"');
+
+call mtr.add_suppression(".*\\[Error\\] (mysqld|mariadbd): Can't find record in 'spider_tables'");
+--error ER_KEY_NOT_FOUND
+SELECT spider_copy_tables ('t', '0', '0');
+
+SELECT spider_flush_table_mon_cache ();
+
+--disable_query_log
+--source ../../include/clean_up_spider.inc
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33242.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33242.test
new file mode 100644
index 00000000..215dab25
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33242.test
@@ -0,0 +1,6 @@
+set @old_old_mode=@@global.old_mode;
+set global old_mode=4;
+INSTALL SONAME 'ha_spider.so';
+set global old_mode=@old_old_mode;
+--disable_query_log
+--source ../../include/clean_up_spider.inc
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test
new file mode 100644
index 00000000..dd9f882f
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33434.test
@@ -0,0 +1,15 @@
+--echo #
+--echo # MDEV-33434 MDEV-33434 UBSAN null pointer passed as argument 2, which is declared to never be null in spider_udf_direct_sql_create_conn
+--echo #
+
+INSTALL SONAME 'ha_spider';
+SET character_set_connection=ucs2;
+--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE
+SELECT SPIDER_DIRECT_SQL('SELECT SLEEP(1)', '', 'srv "dummy", port "3307"');
+--disable_query_log
+--source ../../include/clean_up_spider.inc
+--enable_query_log
+
+--echo #
+--echo # end of test mdev_33434
+--echo #
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.opt
new file mode 100644
index 00000000..924ea4e3
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.opt
@@ -0,0 +1 @@
+--plugin-load-add=ha_spider
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.test
new file mode 100644
index 00000000..a2e0ddaf
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441.test
@@ -0,0 +1,10 @@
+--echo #
+--echo # MDEV-33441 No spider variables available is Spider is loaded upon server startup
+--echo #
+
+# We test that at least one spider variable exists.
+set spider_same_server_link=0;
+
+--echo #
+--echo # end of test mdev_33441
+--echo #
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.opt
new file mode 100644
index 00000000..28f1ce48
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.opt
@@ -0,0 +1,2 @@
+--plugin-load-add=ha_spider
+--debug-dbug=d,fail_spider_init_retry
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.test
new file mode 100644
index 00000000..6734b477
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33441_fail.test
@@ -0,0 +1,10 @@
+--source include/have_debug.inc
+--echo #
+--echo # MDEV-33441 No spider variables available is Spider is loaded upon server startup
+--echo #
+# We test that when retry fails, spider variables are deleted.
+select * from mysql.plugin;
+show variables like 'spider%';
+--echo #
+--echo # end of test mdev_33441_fail
+--echo #
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test
new file mode 100644
index 00000000..30beca77
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33494.test
@@ -0,0 +1,11 @@
+# This test tests spider init with global no_zero_date sql mode
+set @old_sql_mode=@@global.sql_mode;
+set global sql_mode=(SELECT CONCAT (@@sql_mode,',no_zero_date'));
+install soname 'ha_spider';
+set global sql_mode=@old_sql_mode;
+
+--disable_query_log
+--disable_result_log
+--source ../../include/clean_up_spider.inc
+--enable_result_log
+--enable_query_log
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33538.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_33538.opt
new file mode 100644
index 00000000..a90c3a39
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33538.opt
@@ -0,0 +1,2 @@
+--plugin-load-add=ha_spider
+--transaction-read-only=on
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33538.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33538.test
new file mode 100644
index 00000000..e2d4d8b4
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33538.test
@@ -0,0 +1,2 @@
+# we check that information_schema.SPIDER_ALLOC_MEM exists
+show create table information_schema.SPIDER_ALLOC_MEM;
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33538_fail_init.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33538_fail_init.test
new file mode 100644
index 00000000..fafc2fdb
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33538_fail_init.test
@@ -0,0 +1,17 @@
+call mtr.add_suppression("\\[ERROR\\] SPIDER plugin initialization failed");
+call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER' registration as a STORAGE ENGINE failed.");
+call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER_WRAPPER_PROTOCOLS' registration as a INFORMATION SCHEMA failed.");
+call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER_ALLOC_MEM' registration as a INFORMATION SCHEMA failed.");
+# We create a table with identical name of the spider system table, to
+# fail the spider init query ([ERROR] SPIDER plugin initialization
+# failed at 'alter table mysql.spider_tables add column if not exists
+# link_id int not null default 0 after table_name, drop primary key,
+# add primary key (db_name, table_name, link_id), algorithm=copy,
+# lock=shared;' by 'Unknown column 'table_name' in 'spider_tables'')
+# This will cause the init of spider_alloc_mem to fail because it
+# depends on the main spider plugin.
+create table mysql.spider_tables (c int);
+--let $restart_parameters= --plugin-load-add=ha_spider
+--source include/restart_mysqld.inc
+SELECT * FROM information_schema.SPIDER_ALLOC_MEM;
+SELECT * FROM information_schema.SPIDER_WRAPPER_PROTOCOLS;
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test
new file mode 100644
index 00000000..88644971
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33584.test
@@ -0,0 +1,11 @@
+# This test tests spider init with global no_zero_date sql mode
+set @old_sql_mode=@@global.sql_mode;
+set global sql_mode='traditional';
+install soname 'ha_spider';
+set global sql_mode=@old_sql_mode;
+
+--disable_query_log
+--disable_result_log
+--source ../../include/clean_up_spider.inc
+--enable_result_log
+--enable_query_log
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test
new file mode 100644
index 00000000..eee47a21
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33679.test
@@ -0,0 +1,29 @@
+--echo #
+--echo # MDEV-33679 spider returns parsing failure on valid left join select by translating the on expression to ()
+--echo #
+--disable_query_log
+--disable_result_log
+--source ../../t/test_init.inc
+--enable_result_log
+--enable_query_log
+evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
+OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
+
+CREATE TABLE `t1` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) ENGINE=MYISAM;
+CREATE TABLE `t2` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL ) ENGINE=MYISAM;
+SET spider_same_server_link= on;
+CREATE TABLE `t1_spider` (`c` INT(10) UNSIGNED NOT NULL, `b` VARCHAR(255) NOT NULL , PRIMARY KEY (`c`) USING BTREE ) COMMENT='wrapper "mysql",srv "srv", table "t1"' ENGINE=SPIDER;
+CREATE TABLE `t2_spider` (`a` INT(10) UNSIGNED NOT NULL, `c` INT(10) UNSIGNED NOT NULL
+, PRIMARY KEY (`a`) USING BTREE
+) COMMENT='wrapper "mysql",srv "srv",table "t2"' ENGINE=SPIDER;
+INSERT INTO t1_spider VALUES(1,'oooo');
+INSERT INTO t2_spider VALUES(1,1);
+SELECT t2_spider.a,t1_spider.c FRoM t2_spider LEFT join t1_spider ON (t2_spider.c = t1_spider.c) WHERE t2_spider.a = 1;
+
+drop table t1, t2, t1_spider, t2_spider;
+drop server srv;
+--disable_query_log
+--disable_result_log
+--source ../../t/test_deinit.inc
+--enable_result_log
+--enable_query_log
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_33731.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_33731.test
new file mode 100644
index 00000000..b98c9620
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_33731.test
@@ -0,0 +1,16 @@
+--disable_query_log
+--disable_result_log
+--source ../../t/test_init.inc
+--enable_result_log
+--enable_query_log
+
+CREATE TABLE t (a INT) ENGINE=Spider PARTITION BY LIST (a) PARTITIONS 2 (PARTITION p1 VALUES IN (0,1),PARTITION p2 VALUES IN (2,3));
+--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE
+DELETE FROM t PARTITION (p2);
+drop table t;
+
+--disable_query_log
+--disable_result_log
+--source ../../t/test_deinit.inc
+--enable_result_log
+--enable_query_log
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_34003.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_34003.test
new file mode 100644
index 00000000..f81259b9
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_34003.test
@@ -0,0 +1,20 @@
+--disable_query_log
+--disable_result_log
+--source ../../t/test_init.inc
+--enable_result_log
+--enable_query_log
+set spider_same_server_link= 1;
+evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
+OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
+create table t2 (c INT KEY,c1 BLOB,c2 TEXT) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (0,1,0),(1,0,0),(2,0,0);
+create table t1 (c INT KEY,c1 BLOB,c2 TEXT) ENGINE=Spider
+COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
+SELECT * FROM t1 WHERE c=0;
+drop table t1, t2;
+drop server srv;
+--disable_query_log
+--disable_result_log
+--source ../../t/test_deinit.inc
+--enable_result_log
+--enable_query_log
diff --git a/storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_all.test b/storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_all.test
index 396145fb..35242b20 100644
--- a/storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_all.test
+++ b/storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_all.test
@@ -3,5 +3,6 @@
--echo #
# A simple test that tests plugin-load-add=ha_spider
select * from mysql.plugin;
+select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = "information_schema" and TABLE_NAME like "SPIDER_%";
create table t (c int) Engine=SPIDER;
drop table t;
diff --git a/storage/spider/mysql-test/spider/bugfix/t/self_reference_multi.test b/storage/spider/mysql-test/spider/bugfix/t/self_reference_multi.test
index 4263560b..de75f0ee 100644
--- a/storage/spider/mysql-test/spider/bugfix/t/self_reference_multi.test
+++ b/storage/spider/mysql-test/spider/bugfix/t/self_reference_multi.test
@@ -19,8 +19,10 @@ eval create table t0 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",
eval alter table t2 ENGINE=Spider COMMENT='WRAPPER "mysql", srv "$srv",TABLE "t0"';
--error 12719
select * from t0;
+--replace_result test.t1 test.t0 test.t2 test.t0
--error 12719
select * from t1;
+--replace_result test.t1 test.t0 test.t2 test.t0
--error 12719
select * from t2;
drop table t0, t1, t2;
diff --git a/storage/spider/mysql-test/spider/feature/r/pushdown_case.result b/storage/spider/mysql-test/spider/feature/r/pushdown_case.result
new file mode 100644
index 00000000..613ce377
--- /dev/null
+++ b/storage/spider/mysql-test/spider/feature/r/pushdown_case.result
@@ -0,0 +1,57 @@
+#
+# MDEV-28993 Spider: Push down CASE statement
+#
+for master_1
+for child2
+for child3
+set spider_same_server_link= 1;
+CREATE SERVER srv FOREIGN DATA WRAPPER mysql
+OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
+create table t2 (c int);
+create table t1 (c int) ENGINE=Spider
+COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
+insert into t1 values (42), (3), (848), (100);
+explain select case c when 3 then "three" when 42 then "answer" else "other" end from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select case c when 3 then "three" when 42 then "answer" else "other" end from t1;
+case c when 3 then "three" when 42 then "answer" else "other" end
+answer
+three
+other
+other
+explain select case c when 3 then "three" when 42 then "answer" end from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select case c when 3 then "three" when 42 then "answer" end from t1;
+case c when 3 then "three" when 42 then "answer" end
+answer
+three
+NULL
+NULL
+explain select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1;
+case when c = 3 then "three" when c = 42 then "answer" else "other" end
+answer
+three
+other
+other
+explain select case when c = 3 then "three" when c = 42 then "answer" end from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select case when c = 3 then "three" when c = 42 then "answer" end from t1;
+case when c = 3 then "three" when c = 42 then "answer" end
+answer
+three
+NULL
+NULL
+drop table t1, t2;
+drop server srv;
+for master_1
+for child2
+for child3
+#
+# end of test pushdown_case
+#
diff --git a/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result b/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result
new file mode 100644
index 00000000..3acd8912
--- /dev/null
+++ b/storage/spider/mysql-test/spider/feature/r/pushdown_timestamp_diff.result
@@ -0,0 +1,111 @@
+#
+# MDEV-28992 Spider: Push down TIMESTAMPDIFF function
+#
+for master_1
+for child2
+for child3
+set spider_same_server_link= 1;
+CREATE SERVER srv FOREIGN DATA WRAPPER mysql
+OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
+create table t2 (
+a INT,
+b CHAR(1),
+c DATETIME,
+PRIMARY KEY(a)
+);
+CREATE TABLE t1 (
+a INT,
+b CHAR(1),
+c DATETIME,
+PRIMARY KEY(a)
+) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
+INSERT INTO t1 (a, b, c) VALUES
+(1, 'a', '2018-11-01 10:21:39'),
+(2, 'b', '2015-06-30 23:59:59'),
+(3, 'c', '2013-11-01 01:01:01');
+interval year
+explain select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1;
+a b timestampdiff(year, '2000-01-01 00:00:00', c)
+1 a 18
+2 b 15
+3 c 13
+interval quarter
+explain select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1;
+a b timestampdiff(quarter, '2000-01-01 00:00:00', c)
+1 a 75
+2 b 61
+3 c 55
+interval month
+explain select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1;
+a b timestampdiff(month, '2000-01-01 00:00:00', c)
+1 a 226
+2 b 185
+3 c 166
+interval week
+explain select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1;
+a b timestampdiff(week, '2000-01-01 00:00:00', c)
+1 a 982
+2 b 808
+3 c 721
+interval day
+explain select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1;
+a b timestampdiff(day, '2000-01-01 00:00:00', c)
+1 a 6879
+2 b 5659
+3 c 5053
+internal hour
+explain select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1;
+a b timestampdiff(hour, '2000-01-01 00:00:00', c)
+1 a 165106
+2 b 135839
+3 c 121273
+internal minute
+explain select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1;
+a b timestampdiff(minute, '2000-01-01 00:00:00', c)
+1 a 9906381
+2 b 8150399
+3 c 7276381
+internal second
+explain select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1;
+a b timestampdiff(second, '2000-01-01 00:00:00', c)
+1 a 594382899
+2 b 489023999
+3 c 436582861
+internal microsecond
+explain select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Storage engine handles GROUP BY
+select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1;
+a b timestampdiff(microsecond, '2000-01-01 00:00:00', c)
+1 a 594382899000000
+2 b 489023999000000
+3 c 436582861000000
+drop table t1, t2;
+drop server srv;
+for master_1
+for child2
+for child3
diff --git a/storage/spider/mysql-test/spider/feature/r/slave_transaction_retry_errors.result b/storage/spider/mysql-test/spider/feature/r/slave_transaction_retry_errors.result
index 0a147c03..f7d4341c 100644
--- a/storage/spider/mysql-test/spider/feature/r/slave_transaction_retry_errors.result
+++ b/storage/spider/mysql-test/spider/feature/r/slave_transaction_retry_errors.result
@@ -5,11 +5,12 @@ child2_2
child2_3
for child3
for slave1_1
+include/start_slave.inc
connection slave1_1;
SHOW VARIABLES LIKE 'slave_transaction_retry_errors';
Variable_name Value
-slave_transaction_retry_errors 1158,1159,1160,1161,1205,1213,1429,2013,12701
+slave_transaction_retry_errors 1158,1159,1160,1161,1205,1213,1020,1429,2013,12701
connection slave1_1;
for slave1_1
for master_1
diff --git a/storage/spider/mysql-test/spider/feature/t/pushdown_case.test b/storage/spider/mysql-test/spider/feature/t/pushdown_case.test
new file mode 100644
index 00000000..b86edceb
--- /dev/null
+++ b/storage/spider/mysql-test/spider/feature/t/pushdown_case.test
@@ -0,0 +1,50 @@
+--echo #
+--echo # MDEV-28993 Spider: Push down CASE statement
+--echo #
+--disable_query_log
+--disable_result_log
+--source ../../t/test_init.inc
+--enable_result_log
+--enable_query_log
+set spider_same_server_link= 1;
+evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
+OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
+create table t2 (c int);
+create table t1 (c int) ENGINE=Spider
+COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
+insert into t1 values (42), (3), (848), (100);
+
+# everything
+let $query=
+select case c when 3 then "three" when 42 then "answer" else "other" end from t1;
+eval explain $query;
+eval $query;
+
+# no else
+let $query=
+select case c when 3 then "three" when 42 then "answer" end from t1;
+eval explain $query;
+eval $query;
+
+# no value
+let $query=
+select case when c = 3 then "three" when c = 42 then "answer" else "other" end from t1;
+eval explain $query;
+eval $query;
+
+# neither
+let $query=
+select case when c = 3 then "three" when c = 42 then "answer" end from t1;
+eval explain $query;
+eval $query;
+
+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 pushdown_case
+--echo #
diff --git a/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test b/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test
new file mode 100644
index 00000000..81251860
--- /dev/null
+++ b/storage/spider/mysql-test/spider/feature/t/pushdown_timestamp_diff.test
@@ -0,0 +1,93 @@
+--echo #
+--echo # MDEV-28992 Spider: Push down TIMESTAMPDIFF function
+--echo #
+--disable_query_log
+--disable_result_log
+--source ../../t/test_init.inc
+--enable_result_log
+--enable_query_log
+
+set spider_same_server_link= 1;
+evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
+OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
+
+create table t2 (
+ a INT,
+ b CHAR(1),
+ c DATETIME,
+ PRIMARY KEY(a)
+);
+CREATE TABLE t1 (
+ a INT,
+ b CHAR(1),
+ c DATETIME,
+ PRIMARY KEY(a)
+) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
+
+INSERT INTO t1 (a, b, c) VALUES
+ (1, 'a', '2018-11-01 10:21:39'),
+ (2, 'b', '2015-06-30 23:59:59'),
+ (3, 'c', '2013-11-01 01:01:01');
+
+--echo interval year
+let $query=
+select a, b, timestampdiff(year, '2000-01-01 00:00:00', c) from t1;
+eval explain $query;
+eval $query;
+
+--echo interval quarter
+let $query=
+select a, b, timestampdiff(quarter, '2000-01-01 00:00:00', c) from t1;
+eval explain $query;
+eval $query;
+
+--echo interval month
+let $query=
+select a, b, timestampdiff(month, '2000-01-01 00:00:00', c) from t1;
+eval explain $query;
+eval $query;
+
+--echo interval week
+let $query=
+select a, b, timestampdiff(week, '2000-01-01 00:00:00', c) from t1;
+eval explain $query;
+eval $query;
+
+--echo interval day
+let $query=
+select a, b, timestampdiff(day, '2000-01-01 00:00:00', c) from t1;
+eval explain $query;
+eval $query;
+
+--echo internal hour
+let $query=
+select a, b, timestampdiff(hour, '2000-01-01 00:00:00', c) from t1;
+eval explain $query;
+eval $query;
+
+--echo internal minute
+let $query=
+select a, b, timestampdiff(minute, '2000-01-01 00:00:00', c) from t1;
+eval explain $query;
+eval $query;
+
+--echo internal second
+let $query=
+select a, b, timestampdiff(second, '2000-01-01 00:00:00', c) from t1;
+eval explain $query;
+eval $query;
+
+--echo internal microsecond
+let $query=
+select a, b, timestampdiff(microsecond, '2000-01-01 00:00:00', c) from t1;
+eval explain $query;
+eval $query;
+
+drop table t1, t2;
+drop server srv;
+
+--disable_query_log
+--disable_result_log
+--source ../../t/test_deinit.inc
+--enable_result_log
+--enable_query_log
diff --git a/storage/spider/mysql-test/spider/include/clean_up_spider.inc b/storage/spider/mysql-test/spider/include/clean_up_spider.inc
index 1c977bfb..249606ec 100644
--- a/storage/spider/mysql-test/spider/include/clean_up_spider.inc
+++ b/storage/spider/mysql-test/spider/include/clean_up_spider.inc
@@ -3,7 +3,6 @@ DROP FUNCTION spider_copy_tables;
DROP FUNCTION spider_ping_table;
DROP FUNCTION spider_bg_direct_sql;
DROP FUNCTION spider_direct_sql;
---replace_regex /\.dll/.so/
UNINSTALL SONAME IF EXISTS 'ha_spider';
DROP TABLE IF EXISTS mysql.spider_xa;
DROP TABLE IF EXISTS mysql.spider_xa_member;
diff --git a/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result
index 850546fa..3eed8df2 100644
--- a/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result
+++ b/storage/spider/mysql-test/spider/r/partition_join_pushdown_for_single_partition.result
@@ -86,10 +86,8 @@ SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argum
argument
select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5
select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5
-select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1
select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5
select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5
-select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1
SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %'
SELECT value FROM tbl_a ORDER BY value;
value
diff --git a/storage/spider/mysql-test/spider/r/slave_trx_isolation.result b/storage/spider/mysql-test/spider/r/slave_trx_isolation.result
index 28aaf74f..2f850b26 100644
--- a/storage/spider/mysql-test/spider/r/slave_trx_isolation.result
+++ b/storage/spider/mysql-test/spider/r/slave_trx_isolation.result
@@ -8,6 +8,7 @@ child3_1
child3_2
child3_3
for slave1_1
+include/start_slave.inc
connection slave1_1;
set @old_spider_slave_trx_isolation= @@spider_slave_trx_isolation;
set global spider_slave_trx_isolation= 1;
diff --git a/storage/spider/mysql-test/spider/r/spider3_fixes.result b/storage/spider/mysql-test/spider/r/spider3_fixes.result
index 7a80e102..614920be 100644
--- a/storage/spider/mysql-test/spider/r/spider3_fixes.result
+++ b/storage/spider/mysql-test/spider/r/spider3_fixes.result
@@ -8,6 +8,7 @@ child3_1
child3_2
child3_3
for slave1_1
+include/start_slave.inc
drop and create databases
connection master_1;
diff --git a/storage/spider/mysql-test/spider/r/spider3_fixes_part.result b/storage/spider/mysql-test/spider/r/spider3_fixes_part.result
index 937f222f..94390ff7 100644
--- a/storage/spider/mysql-test/spider/r/spider3_fixes_part.result
+++ b/storage/spider/mysql-test/spider/r/spider3_fixes_part.result
@@ -8,6 +8,7 @@ child3_1
child3_2
child3_3
for slave1_1
+include/start_slave.inc
drop and create databases
connection master_1;
diff --git a/storage/spider/mysql-test/spider/r/spider_fixes.result b/storage/spider/mysql-test/spider/r/spider_fixes.result
index 273f37a8..9083ad70 100644
--- a/storage/spider/mysql-test/spider/r/spider_fixes.result
+++ b/storage/spider/mysql-test/spider/r/spider_fixes.result
@@ -8,6 +8,7 @@ child3_1
child3_2
child3_3
for slave1_1
+include/start_slave.inc
drop and create databases
connection master_1;
diff --git a/storage/spider/mysql-test/spider/r/spider_fixes_part.result b/storage/spider/mysql-test/spider/r/spider_fixes_part.result
index 571af94c..a59d2d2b 100644
--- a/storage/spider/mysql-test/spider/r/spider_fixes_part.result
+++ b/storage/spider/mysql-test/spider/r/spider_fixes_part.result
@@ -8,6 +8,7 @@ child3_1
child3_2
child3_3
for slave1_1
+include/start_slave.inc
drop and create databases
connection master_1;
@@ -109,6 +110,7 @@ a b c
2.26
auto_increment with partition
connection master_1;
+include/save_master_pos.inc
connection slave1_1;
connection master_1;
DROP TABLE IF EXISTS t1;
diff --git a/storage/spider/mysql-test/spider/t/slave_test_init.inc b/storage/spider/mysql-test/spider/t/slave_test_init.inc
index 739d8897..84de2c7d 100644
--- a/storage/spider/mysql-test/spider/t/slave_test_init.inc
+++ b/storage/spider/mysql-test/spider/t/slave_test_init.inc
@@ -19,7 +19,7 @@ if (!$SLAVE1_1_SLAVE_STATUS)
MASTER_PORT = $MASTER_1_MYPORT
;
}
-START SLAVE;
+--source include/start_slave.inc
--connection master_1
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
--connection slave1_1
diff --git a/storage/spider/mysql-test/spider/t/spider_fixes_part.opt b/storage/spider/mysql-test/spider/t/spider_fixes_part.opt
new file mode 100644
index 00000000..1f24df45
--- /dev/null
+++ b/storage/spider/mysql-test/spider/t/spider_fixes_part.opt
@@ -0,0 +1 @@
+--log-warnings=3
diff --git a/storage/spider/mysql-test/spider/t/spider_fixes_part.test b/storage/spider/mysql-test/spider/t/spider_fixes_part.test
index bff2e574..9604f83b 100644
--- a/storage/spider/mysql-test/spider/t/spider_fixes_part.test
+++ b/storage/spider/mysql-test/spider/t/spider_fixes_part.test
@@ -488,7 +488,23 @@ if ($HAVE_PARTITION)
if ($USE_REPLICATION)
{
save_master_pos;
+ --source include/save_master_pos.inc
--connection slave1_1
+ --let $rc= `select master_pos_wait('$_master_file', $_master_pos, 300, '')`
+ if (`select $rc is NULL OR $rc < 0`)
+ {
+ --vertical_results
+ show slave status;
+ --horizontal_results
+ show global status;
+ show global variables;
+ --let $MYSQLD_DATADIR= `select @@datadir`
+ --exec $MYSQL_BINLOG -v $MYSQLD_DATADIR/mysqld-relay-bin.000001;
+ # Check that the relay-log file is fully on disk.
+ --exec ls -l $MYSQLD_DATADIR;
+ # After that try to restart the slave SQL thread
+ start slave sql_thread;
+ }
sync_with_master;
--connection master_1
--disable_query_log
diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc
index 92775896..68c5362d 100644
--- a/storage/spider/spd_conn.cc
+++ b/storage/spider/spd_conn.cc
@@ -56,7 +56,7 @@ extern struct charset_info_st *spd_charset_utf8mb3_bin;
extern LEX_CSTRING spider_unique_id;
pthread_mutex_t spider_conn_id_mutex;
pthread_mutex_t spider_ipport_conn_mutex;
-ulonglong spider_conn_id = 1;
+ulonglong spider_conn_id;
extern pthread_attr_t spider_pt_attr;
@@ -93,7 +93,7 @@ extern sql_mode_t pushdown_sql_mode;
HASH spider_open_connections;
uint spider_open_connections_id;
HASH spider_ipport_conns;
-long spider_conn_mutex_id = 0;
+long spider_conn_mutex_id;
const char *spider_open_connections_func_name;
const char *spider_open_connections_file_name;
diff --git a/storage/spider/spd_copy_tables.cc b/storage/spider/spd_copy_tables.cc
index 70ca17f8..4b608721 100644
--- a/storage/spider/spd_copy_tables.cc
+++ b/storage/spider/spd_copy_tables.cc
@@ -298,7 +298,7 @@ int spider_udf_get_copy_tgt_tables(
if (
(error_num = spider_get_sys_tables_connect_info(
- table_tables, tmp_share, 0, mem_root)) ||
+ table_tables, tmp_share, mem_root)) ||
(error_num = spider_get_sys_tables_link_status(
table_tables, tmp_share, 0, mem_root)) ||
(error_num = spider_get_sys_tables_link_idx(
@@ -968,7 +968,12 @@ long long spider_copy_tables_body(
all_link_cnt =
copy_tables->link_idx_count[0] + copy_tables->link_idx_count[1];
if (
- !(tmp_sql = new spider_string[all_link_cnt]) ||
+ !(tmp_sql = new spider_string[all_link_cnt])
+ ) {
+ my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
+ goto error;
+ }
+ if (
!(spider = new ha_spider[all_link_cnt])
) {
my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
@@ -997,13 +1002,6 @@ long long spider_copy_tables_body(
tmp_spider->share = table_conn->share;
tmp_spider->wide_handler = wide_handler;
wide_handler->trx = copy_tables->trx;
-/*
- if (spider_db_append_set_names(table_conn->share))
- {
- my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
- goto error_append_set_names;
- }
-*/
tmp_spider->conns = &table_conn->conn;
tmp_sql[roop_count].init_calc_mem(SPD_MID_COPY_TABLES_BODY_3);
tmp_sql[roop_count].set_charset(copy_tables->access_charset);
@@ -1043,13 +1041,6 @@ long long spider_copy_tables_body(
tmp_spider->share = table_conn->share;
tmp_spider->wide_handler = wide_handler;
wide_handler->trx = copy_tables->trx;
-/*
- if (spider_db_append_set_names(table_conn->share))
- {
- my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
- goto error_append_set_names;
- }
-*/
tmp_spider->conns = &table_conn->conn;
tmp_sql[roop_count].init_calc_mem(SPD_MID_COPY_TABLES_BODY_5);
tmp_sql[roop_count].set_charset(copy_tables->access_charset);
@@ -1076,14 +1067,6 @@ long long spider_copy_tables_body(
bulk_insert_rows)))
goto error_db_udf_copy_tables;
-/*
- for (table_conn = copy_tables->table_conn[0];
- table_conn; table_conn = table_conn->next)
- spider_db_free_set_names(table_conn->share);
- for (table_conn = copy_tables->table_conn[1];
- table_conn; table_conn = table_conn->next)
- spider_db_free_set_names(table_conn->share);
-*/
if (table_list->table)
{
(thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd));
@@ -1104,8 +1087,7 @@ long long spider_copy_tables_body(
}
delete [] spider;
}
- if (tmp_sql)
- delete [] tmp_sql;
+ delete [] tmp_sql;
spider_udf_free_copy_tables_alloc(copy_tables);
DBUG_RETURN(1);
@@ -1113,17 +1095,6 @@ long long spider_copy_tables_body(
error_db_udf_copy_tables:
error_create_dbton_handler:
error_init_dbton_handler:
-/*
-error_append_set_names:
-*/
-/*
- for (table_conn = copy_tables->table_conn[0];
- table_conn; table_conn = table_conn->next)
- spider_db_free_set_names(table_conn->share);
- for (table_conn = copy_tables->table_conn[1];
- table_conn; table_conn = table_conn->next)
- spider_db_free_set_names(table_conn->share);
-*/
error:
if (spider)
{
@@ -1181,6 +1152,11 @@ my_bool spider_copy_tables_init_body(
char *message
) {
DBUG_ENTER("spider_copy_tables_init_body");
+ if (!spider_hton_ptr)
+ {
+ strcpy(message, "Plugin 'SPIDER' is not loaded");
+ goto error;
+ }
if (args->arg_count != 3 && args->arg_count != 4)
{
strcpy(message, "spider_copy_tables() requires 3 or 4 arguments");
diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc
index 16d5b836..7c56ede2 100644
--- a/storage/spider/spd_db_conn.cc
+++ b/storage/spider/spd_db_conn.cc
@@ -63,7 +63,7 @@ pthread_mutex_t spider_open_conn_mutex;
const char spider_dig_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* UTC time zone for timestamp columns */
-Time_zone *UTC = 0;
+Time_zone *UTC;
int spider_db_connect(
const SPIDER_SHARE *share,
@@ -344,7 +344,6 @@ int spider_db_conn_queue_action(
) ||
(
conn->loop_check_queue.records &&
- conn->db_conn->set_loop_check_in_bulk_sql() &&
(error_num = spider_dbton[conn->dbton_id].db_util->
append_loop_check(&sql_str, conn))
) ||
@@ -444,13 +443,6 @@ int spider_db_conn_queue_action(
DBUG_RETURN(error_num);
}
if (
- conn->loop_check_queue.records &&
- !conn->db_conn->set_loop_check_in_bulk_sql() &&
- (error_num = conn->db_conn->set_loop_check((int *) conn->need_mon))
- ) {
- DBUG_RETURN(error_num);
- }
- if (
conn->queued_trx_isolation &&
!conn->queued_semi_trx_isolation &&
conn->queued_trx_isolation_val != conn->trx_isolation &&
@@ -9138,6 +9130,9 @@ int spider_db_udf_ping_table_append_select(
DBUG_RETURN(0);
}
+/* Stack size 33032 with clang */
+PRAGMA_DISABLE_CHECK_STACK_FRAME
+
int spider_db_udf_ping_table_mon_next(
THD *thd,
SPIDER_TABLE_MON *table_mon,
@@ -9284,6 +9279,7 @@ int spider_db_udf_ping_table_mon_next(
delete res;
DBUG_RETURN(error_num);
}
+PRAGMA_REENABLE_CHECK_STACK_FRAME
int spider_db_udf_copy_key_row(
spider_string *str,
diff --git a/storage/spider/spd_db_include.cc b/storage/spider/spd_db_include.cc
index a4d7d4b4..514470a2 100644
--- a/storage/spider/spd_db_include.cc
+++ b/storage/spider/spd_db_include.cc
@@ -64,22 +64,6 @@ spider_db_conn::spider_db_conn(
DBUG_VOID_RETURN;
}
-bool spider_db_conn::set_loop_check_in_bulk_sql()
-{
- DBUG_ENTER("spider_db_conn::set_loop_check_in_bulk_sql");
- DBUG_PRINT("info",("spider this=%p", this));
- DBUG_RETURN(FALSE);
-}
-
-int spider_db_conn::set_loop_check(
- int *need_mon
-) {
- DBUG_ENTER("spider_db_conn::set_loop_check");
- DBUG_PRINT("info",("spider this=%p", this));
- /* nothing to do */
- DBUG_RETURN(0);
-}
-
int spider_db_conn::fin_loop_check()
{
st_spider_conn_loop_check *lcptr;
diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h
index c2cbe5f2..4e9d6b1a 100644
--- a/storage/spider/spd_db_include.h
+++ b/storage/spider/spd_db_include.h
@@ -79,7 +79,6 @@ typedef st_spider_result SPIDER_RESULT;
#define SPIDER_SQL_HS_LTEQUAL_STR "<="
#define SPIDER_SQL_HS_LTEQUAL_LEN (sizeof(SPIDER_SQL_HS_LTEQUAL_STR) - 1)
-#ifdef ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC
#define SPIDER_SQL_CASE_STR "case "
#define SPIDER_SQL_CASE_LEN (sizeof(SPIDER_SQL_CASE_STR) - 1)
#define SPIDER_SQL_WHEN_STR " when "
@@ -90,7 +89,6 @@ typedef st_spider_result SPIDER_RESULT;
#define SPIDER_SQL_ELSE_LEN (sizeof(SPIDER_SQL_ELSE_STR) - 1)
#define SPIDER_SQL_END_STR " end"
#define SPIDER_SQL_END_LEN (sizeof(SPIDER_SQL_END_STR) - 1)
-#endif
#define SPIDER_SQL_USING_STR " using "
#define SPIDER_SQL_USING_LEN (sizeof(SPIDER_SQL_USING_STR) - 1)
@@ -1024,10 +1022,6 @@ public:
Time_zone *time_zone,
int *need_mon
) = 0;
- virtual bool set_loop_check_in_bulk_sql();
- virtual int set_loop_check(
- int *need_mon
- );
virtual int fin_loop_check();
virtual int show_master_status(
SPIDER_TRX *trx,
diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc
index c2f0c6b8..450e1a02 100644
--- a/storage/spider/spd_db_mysql.cc
+++ b/storage/spider/spd_db_mysql.cc
@@ -1191,7 +1191,7 @@ int spider_db_mbase_result::fetch_table_cardinality(
uint num_fields = this->num_fields();
if (num_fields < 12 || num_fields > 14)
{
- DBUG_PRINT("info",("spider num_fields < 12 || num_fields > 13"));
+ DBUG_PRINT("info",("spider num_fields < 12 || num_fields > 14"));
DBUG_RETURN(ER_SPIDER_INVALID_REMOTE_TABLE_INFO_NUM);
}
@@ -3266,110 +3266,6 @@ int spider_db_mbase::set_time_zone(
DBUG_RETURN(0);
}
-bool spider_db_mbase::set_loop_check_in_bulk_sql()
-{
- DBUG_ENTER("spider_db_mbase::set_loop_check_in_bulk_sql");
- DBUG_PRINT("info",("spider this=%p", this));
- DBUG_RETURN(TRUE);
-}
-
-int spider_db_mbase::set_loop_check(
- int *need_mon
-) {
- SPIDER_CONN_LOOP_CHECK *lcptr;
- char sql_buf[MAX_FIELD_WIDTH];
- 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(SPD_MID_DB_MBASE_SET_LOOP_CHECK_1);
- while ((lcptr = (SPIDER_CONN_LOOP_CHECK *) my_hash_element(
- &conn->loop_check_queue, 0)))
- {
- sql_str.length(0);
- if (sql_str.reserve(SPIDER_SQL_SET_USER_VAL_LEN +
- SPIDER_SQL_LOP_CHK_PRM_PRF_LEN + lcptr->to_name.length +
- SPIDER_SQL_NAME_QUOTE_LEN + SPIDER_SQL_EQUAL_LEN +
- SPIDER_SQL_VALUE_QUOTE_LEN +
- lcptr->merged_value.length + SPIDER_SQL_VALUE_QUOTE_LEN))
- {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- sql_str.q_append(SPIDER_SQL_SET_USER_VAL_STR, SPIDER_SQL_SET_USER_VAL_LEN);
- sql_str.q_append(SPIDER_SQL_LOP_CHK_PRM_PRF_STR,
- SPIDER_SQL_LOP_CHK_PRM_PRF_LEN);
- sql_str.q_append(lcptr->to_name.str, lcptr->to_name.length);
- sql_str.q_append(SPIDER_SQL_NAME_QUOTE_STR, SPIDER_SQL_NAME_QUOTE_LEN);
- sql_str.q_append(SPIDER_SQL_EQUAL_STR, SPIDER_SQL_EQUAL_LEN);
- sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
- sql_str.q_append(lcptr->merged_value.str, lcptr->merged_value.length);
- sql_str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
-
- pthread_mutex_assert_not_owner(&conn->mta_conn_mutex);
- pthread_mutex_lock(&conn->mta_conn_mutex);
- SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
- conn->need_mon = need_mon;
- DBUG_ASSERT(!conn->mta_conn_mutex_lock_already);
- DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later);
- conn->mta_conn_mutex_lock_already = TRUE;
- conn->mta_conn_mutex_unlock_later = TRUE;
- if (spider_db_query(
- conn,
- sql_str.ptr(),
- sql_str.length(),
- -1,
- need_mon)
- ) {
- DBUG_ASSERT(conn->mta_conn_mutex_lock_already);
- DBUG_ASSERT(conn->mta_conn_mutex_unlock_later);
- conn->mta_conn_mutex_lock_already = FALSE;
- conn->mta_conn_mutex_unlock_later = FALSE;
- DBUG_RETURN(spider_db_errorno(conn));
- }
- DBUG_ASSERT(conn->mta_conn_mutex_lock_already);
- DBUG_ASSERT(conn->mta_conn_mutex_unlock_later);
- 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);
-
- my_hash_delete(&conn->loop_check_queue, (uchar*) lcptr);
- }
- DBUG_RETURN(0);
-}
-
-int spider_db_mbase::fin_loop_check()
-{
- st_spider_conn_loop_check *lcptr;
- DBUG_ENTER("spider_db_mbase::fin_loop_check");
- DBUG_PRINT("info",("spider this=%p", this));
- if (conn->loop_check_queue.records)
- {
- uint l = 0;
- while ((lcptr = (SPIDER_CONN_LOOP_CHECK *) my_hash_element(
- &conn->loop_check_queue, l)))
- {
- lcptr->flag = 0;
- ++l;
- }
- my_hash_reset(&conn->loop_check_queue);
- }
- lcptr = conn->loop_check_ignored_first;
- while (lcptr)
- {
- lcptr->flag = 0;
- lcptr = lcptr->next;
- }
- conn->loop_check_ignored_first = NULL;
- lcptr = conn->loop_check_meraged_first;
- while (lcptr)
- {
- lcptr->flag = 0;
- lcptr = lcptr->next;
- }
- conn->loop_check_meraged_first = NULL;
- DBUG_RETURN(0);
-}
-
int spider_db_mbase::exec_simple_sql_with_result(
SPIDER_TRX *trx,
SPIDER_SHARE *share,
@@ -5503,14 +5399,6 @@ int spider_db_mbase_util::open_item_func(
alias_length, use_fields, fields));
}
-static bool item_func_is_timestampdiff(
- const char *func_name,
- int func_name_length
-) {
- return func_name_length == 13 &&
- !strncasecmp("timestampdiff", func_name, func_name_length);
-}
-
static bool not_func_should_be_skipped(
Item_func *item_func
){
@@ -5580,16 +5468,10 @@ int spider_db_mbase_util::check_item_func(
Item_func::Functype func_type = item_func->functype();
DBUG_PRINT("info",("spider functype = %d", func_type));
- const char *func_name = (char*) item_func->func_name();
- int func_name_length = strlen(func_name);
- DBUG_PRINT("info",("spider func_name = %s", func_name));
-
/* The blacklist of the functions that cannot be pushed down */
switch (func_type)
{
case Item_func::TRIG_COND_FUNC:
- case Item_func::CASE_SEARCHED_FUNC:
- case Item_func::CASE_SIMPLE_FUNC:
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
case Item_func::NOT_FUNC:
/* Why the following check is necessary? */
@@ -5598,13 +5480,6 @@ int spider_db_mbase_util::check_item_func(
break;
case Item_func::FUNC_SP:
case Item_func::UDF_FUNC:
- /* Notes on merging regarding MDEV-29447: please refer to the
- following commits for build error or merge conflicts:
- 10.6: 1ed20b993b0dd4e95450cab2e8347e5bf4617a69
- 10.9: dd316b6e20265cfd832bb5585cb4c96e716387c8
- 10.10-11: 3f67f110ba1b23a89c5ede0fbeeb203cf5e164f4
- 11.0-1: 17ba6748afa8834df5658361088e6c8e65aca16f
- Please remove this comment after merging. */
use_pushdown_udf= spider_param_use_pushdown_udf(
spider->wide_handler->trx->thd, spider->share->use_pushdown_udf);
if (!use_pushdown_udf)
@@ -5614,12 +5489,18 @@ int spider_db_mbase_util::check_item_func(
if (spider_db_check_ft_idx(item_func, spider) == MAX_KEY)
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
break;
-#ifndef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC
- case Item_func::UNKNOWN_FUNC:
- if (item_func_is_timestampdiff(func_name, func_name_length))
- DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
- break;
-#endif
+ case Item_func::MULT_EQUAL_FUNC:
+ /* If there is still Item_equal by the time of
+ JOIN::make_aggr_tables_info() where the spider group by handler
+ is created, it indicates a bug in the optimizer, because there
+ shouldn't be any. */
+ push_warning_printf(
+ spider->wide_handler->trx->thd, SPIDER_WARN_LEVEL_WARN,
+ ER_INTERNAL_ERROR,
+ ER_THD(spider->wide_handler->trx->thd, ER_INTERNAL_ERROR),
+ "Spider group by handler: Encountered multiple equalities, likely "
+ "an optimizer bug");
+ DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
default:
break;
}
@@ -5661,7 +5542,7 @@ int spider_db_mbase_util::print_item_func(
Item *item, **item_list = item_func->arguments();
Field *field;
spider_string tmp_str;
- uint roop_count, item_count = item_func->argument_count(), start_item = 0;
+ uint i, item_count = item_func->argument_count(), start_item = 0;
LEX_CSTRING org_func_name= {SPIDER_SQL_NULL_CHAR_STR,
SPIDER_SQL_NULL_CHAR_LEN};
const char *func_name = SPIDER_SQL_NULL_CHAR_STR,
@@ -5670,8 +5551,8 @@ int spider_db_mbase_util::print_item_func(
int func_name_length = SPIDER_SQL_NULL_CHAR_LEN,
separator_str_length = SPIDER_SQL_NULL_CHAR_LEN,
last_str_length = SPIDER_SQL_NULL_CHAR_LEN;
- int use_pushdown_udf;
- bool merge_func = FALSE;
+ int use_pushdown_udf, case_when_start, case_when_count;
+ bool merge_func = FALSE, case_with_else;
DBUG_ENTER("spider_db_mbase_util::print_item_func");
DBUG_ASSERT(!check_item_func(item_func, spider, alias, alias_length,
use_fields, fields));
@@ -5989,12 +5870,11 @@ int spider_db_mbase_util::print_item_func(
alias, alias_length, dbton_id, use_fields, fields));
} else if (!strncasecmp("timestampdiff", func_name, func_name_length))
{
-#ifdef ITEM_FUNC_TIMESTAMPDIFF_ARE_PUBLIC
Item_func_timestamp_diff *item_func_timestamp_diff =
(Item_func_timestamp_diff *) item_func;
const char *interval_str;
uint interval_len;
- switch (item_func_timestamp_diff->int_type)
+ switch (item_func_timestamp_diff->get_int_type())
{
case INTERVAL_YEAR:
interval_str = SPIDER_SQL_YEAR_STR;
@@ -6045,7 +5925,7 @@ int spider_db_mbase_util::print_item_func(
str->q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN);
str->q_append(interval_str, interval_len);
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
-
+
if ((error_num = spider_db_print_item_type(item_list[0], NULL, spider,
str, alias, alias_length, dbton_id, use_fields, fields)))
DBUG_RETURN(error_num);
@@ -6066,9 +5946,6 @@ int spider_db_mbase_util::print_item_func(
SPIDER_SQL_CLOSE_PAREN_LEN);
}
DBUG_RETURN(0);
-#else
- DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
-#endif
}
} else if (func_name_length == 14)
{
@@ -6562,7 +6439,83 @@ int spider_db_mbase_util::print_item_func(
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
case Item_func::CASE_SEARCHED_FUNC:
case Item_func::CASE_SIMPLE_FUNC:
- DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
+ /*
+ Arrangement of arguments:
+ - Item_func_case_searched:
+ when1 when2 ... whenk then1 then2 .. thenk [else]
+ - Item_func_case_simple:
+ value when1 when2 ... whenk then1 then2 .. thenk [else]
+ */
+ if (item_func->functype() == Item_func::CASE_SEARCHED_FUNC)
+ {
+ case_when_start= 0;
+ case_when_count= item_count / 2;
+ case_with_else= item_count % 2;
+ }
+ else
+ {
+ case_when_start= 1;
+ case_when_count= (item_count - 1) / 2;
+ case_with_else= item_count % 2 == 0;
+ }
+ if (str)
+ {
+ if (str->reserve(SPIDER_SQL_CASE_LEN))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ str->q_append(SPIDER_SQL_CASE_STR, SPIDER_SQL_CASE_LEN);
+ }
+ if (case_when_start > 0)
+ {
+ if ((error_num = spider_db_print_item_type(
+ item_list[0], NULL, spider, str,
+ alias, alias_length, dbton_id, use_fields, fields)))
+ DBUG_RETURN(error_num);
+ }
+ for (i = 0; i < (uint) case_when_count; i++)
+ {
+ if (str)
+ {
+ if (str->reserve(SPIDER_SQL_WHEN_LEN))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ str->q_append(SPIDER_SQL_WHEN_STR, SPIDER_SQL_WHEN_LEN);
+ }
+ if ((error_num = spider_db_print_item_type(
+ item_list[i + case_when_start], NULL, spider, str,
+ alias, alias_length, dbton_id, use_fields, fields)))
+ DBUG_RETURN(error_num);
+ if (str)
+ {
+ if (str->reserve(SPIDER_SQL_THEN_LEN))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ str->q_append(SPIDER_SQL_THEN_STR, SPIDER_SQL_THEN_LEN);
+ }
+ if ((error_num = spider_db_print_item_type(
+ item_list[i + case_when_start + case_when_count], NULL, spider, str,
+ alias, alias_length, dbton_id, use_fields, fields)))
+ DBUG_RETURN(error_num);
+ }
+ if (case_with_else)
+ {
+ if (str)
+ {
+ if (str->reserve(SPIDER_SQL_ELSE_LEN))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ str->q_append(SPIDER_SQL_ELSE_STR, SPIDER_SQL_ELSE_LEN);
+ }
+ if ((error_num = spider_db_print_item_type(
+ item_list[item_count - 1], NULL, spider, str,
+ alias, alias_length, dbton_id, use_fields, fields)))
+ DBUG_RETURN(error_num);
+ }
+ if (str)
+ {
+ if (str->reserve(SPIDER_SQL_END_LEN + SPIDER_SQL_CLOSE_PAREN_LEN))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ str->q_append(SPIDER_SQL_END_STR, SPIDER_SQL_END_LEN);
+ str->q_append(SPIDER_SQL_CLOSE_PAREN_STR,
+ SPIDER_SQL_CLOSE_PAREN_LEN);
+ }
+ DBUG_RETURN(0);
case Item_func::JSON_EXTRACT_FUNC:
func_name = (char*) item_func->func_name();
func_name_length = strlen(func_name);
@@ -6577,6 +6530,18 @@ int spider_db_mbase_util::print_item_func(
last_str = SPIDER_SQL_CLOSE_PAREN_STR;
last_str_length = SPIDER_SQL_CLOSE_PAREN_LEN;
break;
+ case Item_func::MULT_EQUAL_FUNC:
+ /* If there is still Item_equal by the time of
+ JOIN::make_aggr_tables_info() where the spider group by handler
+ is created, it indicates a bug in the optimizer, because there
+ shouldn't be any. */
+ push_warning_printf(
+ spider->wide_handler->trx->thd,
+ SPIDER_WARN_LEVEL_WARN, ER_INTERNAL_ERROR,
+ ER_THD(spider->wide_handler->trx->thd, ER_INTERNAL_ERROR),
+ "Spider group by handler: Encountered multiple equalities, likely "
+ "an optimizer bug");
+ DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM);
default:
THD *thd = spider->wide_handler->trx->thd;
SPIDER_SHARE *share = spider->share;
@@ -6606,13 +6571,13 @@ int spider_db_mbase_util::print_item_func(
Loop through the items of the current function expression to
print its portion of the statement
*/
- for (roop_count = start_item; roop_count < item_count; roop_count++)
+ for (i = start_item; i < item_count; i++)
{
- item = item_list[roop_count];
+ item = item_list[i];
if ((error_num = spider_db_print_item_type(item, field, spider, str,
alias, alias_length, dbton_id, use_fields, fields)))
DBUG_RETURN(error_num);
- if (roop_count == 1)
+ if (i == 1)
{
/* Remaining operands need to be preceded by the separator */
func_name = separator_str;
@@ -6626,7 +6591,7 @@ int spider_db_mbase_util::print_item_func(
}
/* Print the last operand value */
- item = item_list[roop_count];
+ item = item_list[i];
if ((error_num = spider_db_print_item_type(item, field, spider, str,
alias, alias_length, dbton_id, use_fields, fields)))
DBUG_RETURN(error_num);
@@ -7259,11 +7224,9 @@ int spider_mbase_share::init()
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
- if (keys > 0 &&
- !(key_hint = new spider_string[keys])
- ) {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
+ if (keys > 0)
+ if (!(key_hint = new spider_string[keys]))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
for (roop_count = 0; roop_count < keys; roop_count++)
{
key_hint[roop_count].init_calc_mem(SPD_MID_MBASE_SHARE_INIT_2);
@@ -7271,12 +7234,12 @@ int spider_mbase_share::init()
}
DBUG_PRINT("info",("spider key_hint=%p", key_hint));
- if (
- !(table_select = new spider_string[1]) ||
- (keys > 0 &&
- !(key_select = new spider_string[keys])
- ) ||
- (error_num = create_table_names_str()) ||
+ if (!(table_select = new spider_string[1]))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ if (keys > 0)
+ if (!(key_select = new spider_string[keys]))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ if ((error_num = create_table_names_str()) ||
(table_share &&
(
(error_num = create_column_name_str()) ||
@@ -7427,11 +7390,18 @@ int spider_mbase_share::create_table_names_str()
table_names_str = NULL;
db_names_str = NULL;
db_table_str = NULL;
- if (
- !(table_names_str = new spider_string[spider_share->all_link_count]) ||
- !(db_names_str = new spider_string[spider_share->all_link_count]) ||
- !(db_table_str = new spider_string[spider_share->all_link_count])
- ) {
+ if (!(table_names_str = new spider_string[spider_share->all_link_count]))
+ {
+ error_num = HA_ERR_OUT_OF_MEM;
+ goto error;
+ }
+ if (!(db_names_str = new spider_string[spider_share->all_link_count]))
+ {
+ error_num = HA_ERR_OUT_OF_MEM;
+ goto error;
+ }
+ if (!(db_table_str = new spider_string[spider_share->all_link_count]))
+ {
error_num = HA_ERR_OUT_OF_MEM;
goto error;
}
@@ -7580,11 +7550,9 @@ int spider_mbase_share::create_column_name_str()
Field **field;
TABLE_SHARE *table_share = spider_share->table_share;
DBUG_ENTER("spider_mbase_share::create_column_name_str");
- if (
- table_share->fields &&
- !(column_name_str = new spider_string[table_share->fields])
- )
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+ if (table_share->fields)
+ if (!(column_name_str = new spider_string[table_share->fields]))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
for (field = table_share->field, str = column_name_str;
*field; field++, str++)
{
@@ -8360,7 +8328,7 @@ int spider_mbase_handler::init()
&link_for_hash,
sizeof(SPIDER_LINK_FOR_HASH) * share->link_count,
&minimum_select_bitmap,
- table ? sizeof(uchar) * no_bytes_in_map(table->read_set) : 0,
+ table ? sizeof(uchar) * my_bitmap_buffer_size(table->read_set) : 0,
NullS))
) {
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
@@ -14829,7 +14797,7 @@ void spider_mbase_handler::minimum_select_bitmap_create()
Field **field_p;
DBUG_ENTER("spider_mbase_handler::minimum_select_bitmap_create");
DBUG_PRINT("info",("spider this=%p", this));
- memset(minimum_select_bitmap, 0, no_bytes_in_map(table->read_set));
+ memset(minimum_select_bitmap, 0, my_bitmap_buffer_size(table->read_set));
if (
spider->use_index_merge ||
spider->is_clone
@@ -14840,7 +14808,7 @@ void spider_mbase_handler::minimum_select_bitmap_create()
table_share->primary_key == MAX_KEY
) {
/* need all columns */
- memset(minimum_select_bitmap, 0xFF, no_bytes_in_map(table->read_set));
+ memset(minimum_select_bitmap, 0xFF, my_bitmap_buffer_size(table->read_set));
DBUG_VOID_RETURN;
} else {
/* need primary key columns */
diff --git a/storage/spider/spd_db_mysql.h b/storage/spider/spd_db_mysql.h
index 9ccc0e33..50b21117 100644
--- a/storage/spider/spd_db_mysql.h
+++ b/storage/spider/spd_db_mysql.h
@@ -519,11 +519,6 @@ public:
Time_zone *time_zone,
int *need_mon
);
- bool set_loop_check_in_bulk_sql();
- int set_loop_check(
- int *need_mon
- );
- int fin_loop_check();
int exec_simple_sql_with_result(
SPIDER_TRX *trx,
SPIDER_SHARE *share,
diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc
index d345bb04..89c872ee 100644
--- a/storage/spider/spd_direct_sql.cc
+++ b/storage/spider/spd_direct_sql.cc
@@ -364,6 +364,23 @@ int spider_udf_direct_sql_create_conn_key(
DBUG_RETURN(0);
}
+static inline void spider_maybe_memcpy_string(
+ char **dest,
+ char *src,
+ char *tmp,
+ uint *dest_len,
+ uint src_len)
+{
+ *dest_len= src_len;
+ if (src_len)
+ {
+ *dest= tmp;
+ memcpy(*dest, src, src_len);
+ } else
+ *dest= NULL;
+}
+
+
SPIDER_CONN *spider_udf_direct_sql_create_conn(
const SPIDER_DIRECT_SQL *direct_sql,
int *error_num
@@ -433,105 +450,49 @@ SPIDER_CONN *spider_udf_direct_sql_create_conn(
conn->tgt_host = tmp_host;
memcpy(conn->tgt_host, direct_sql->tgt_host, direct_sql->tgt_host_length);
conn->tgt_port = direct_sql->tgt_port;
- conn->tgt_socket_length = direct_sql->tgt_socket_length;
- conn->tgt_socket = tmp_socket;
- memcpy(conn->tgt_socket, direct_sql->tgt_socket,
- direct_sql->tgt_socket_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_socket, direct_sql->tgt_socket, tmp_socket,
+ &conn->tgt_socket_length, 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,
- direct_sql->tgt_username_length);
- conn->tgt_password_length = direct_sql->tgt_password_length;
- conn->tgt_password = tmp_password;
- memcpy(conn->tgt_password, direct_sql->tgt_password,
- direct_sql->tgt_password_length);
- conn->tgt_ssl_ca_length = direct_sql->tgt_ssl_ca_length;
- if (conn->tgt_ssl_ca_length)
- {
- conn->tgt_ssl_ca = tmp_ssl_ca;
- memcpy(conn->tgt_ssl_ca, direct_sql->tgt_ssl_ca,
- direct_sql->tgt_ssl_ca_length);
- } else
- conn->tgt_ssl_ca = NULL;
- conn->tgt_ssl_capath_length = direct_sql->tgt_ssl_capath_length;
- if (conn->tgt_ssl_capath_length)
- {
- conn->tgt_ssl_capath = tmp_ssl_capath;
- memcpy(conn->tgt_ssl_capath, direct_sql->tgt_ssl_capath,
- direct_sql->tgt_ssl_capath_length);
- } else
- conn->tgt_ssl_capath = NULL;
- conn->tgt_ssl_cert_length = direct_sql->tgt_ssl_cert_length;
- if (conn->tgt_ssl_cert_length)
- {
- conn->tgt_ssl_cert = tmp_ssl_cert;
- memcpy(conn->tgt_ssl_cert, direct_sql->tgt_ssl_cert,
- direct_sql->tgt_ssl_cert_length);
- } else
- conn->tgt_ssl_cert = NULL;
- conn->tgt_ssl_cipher_length = direct_sql->tgt_ssl_cipher_length;
- if (conn->tgt_ssl_cipher_length)
- {
- conn->tgt_ssl_cipher = tmp_ssl_cipher;
- memcpy(conn->tgt_ssl_cipher, direct_sql->tgt_ssl_cipher,
- direct_sql->tgt_ssl_cipher_length);
- } else
- conn->tgt_ssl_cipher = NULL;
- conn->tgt_ssl_key_length = direct_sql->tgt_ssl_key_length;
- if (conn->tgt_ssl_key_length)
- {
- conn->tgt_ssl_key = tmp_ssl_key;
- memcpy(conn->tgt_ssl_key, direct_sql->tgt_ssl_key,
- direct_sql->tgt_ssl_key_length);
- } else
- conn->tgt_ssl_key = NULL;
- conn->tgt_default_file_length = direct_sql->tgt_default_file_length;
- if (conn->tgt_default_file_length)
- {
- conn->tgt_default_file = tmp_default_file;
- memcpy(conn->tgt_default_file, direct_sql->tgt_default_file,
- direct_sql->tgt_default_file_length);
- } else
- conn->tgt_default_file = NULL;
- conn->tgt_default_group_length = direct_sql->tgt_default_group_length;
- if (conn->tgt_default_group_length)
- {
- conn->tgt_default_group = tmp_default_group;
- memcpy(conn->tgt_default_group, direct_sql->tgt_default_group,
- direct_sql->tgt_default_group_length);
- } else
- conn->tgt_default_group = NULL;
- conn->tgt_dsn_length = direct_sql->tgt_dsn_length;
- if (conn->tgt_dsn_length)
- {
- conn->tgt_dsn = tmp_dsn;
- memcpy(conn->tgt_dsn, direct_sql->tgt_dsn,
- direct_sql->tgt_dsn_length);
- } else
- conn->tgt_dsn = NULL;
- conn->tgt_filedsn_length = direct_sql->tgt_filedsn_length;
- if (conn->tgt_filedsn_length)
- {
- conn->tgt_filedsn = tmp_filedsn;
- memcpy(conn->tgt_filedsn, direct_sql->tgt_filedsn,
- direct_sql->tgt_filedsn_length);
- } else
- conn->tgt_filedsn = NULL;
- conn->tgt_driver_length = direct_sql->tgt_driver_length;
- if (conn->tgt_driver_length)
- {
- conn->tgt_driver = tmp_driver;
- memcpy(conn->tgt_driver, direct_sql->tgt_driver,
- direct_sql->tgt_driver_length);
- } else
- conn->tgt_driver = NULL;
+ spider_maybe_memcpy_string(
+ &conn->tgt_db, direct_sql->tgt_default_db_name, tmp_db,
+ &conn->tgt_db_length, direct_sql->tgt_default_db_name_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_username, direct_sql->tgt_username, tmp_username,
+ &conn->tgt_username_length, direct_sql->tgt_username_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_password, direct_sql->tgt_password, tmp_password,
+ &conn->tgt_password_length, direct_sql->tgt_password_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_ssl_ca, direct_sql->tgt_ssl_ca, tmp_ssl_ca,
+ &conn->tgt_ssl_ca_length, direct_sql->tgt_ssl_ca_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_ssl_capath, direct_sql->tgt_ssl_capath, tmp_ssl_capath,
+ &conn->tgt_ssl_capath_length, direct_sql->tgt_ssl_capath_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_ssl_cert, direct_sql->tgt_ssl_cert, tmp_ssl_cert,
+ &conn->tgt_ssl_cert_length, direct_sql->tgt_ssl_cert_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_ssl_cipher, direct_sql->tgt_ssl_cipher, tmp_ssl_cipher,
+ &conn->tgt_ssl_cipher_length, direct_sql->tgt_ssl_cipher_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_ssl_key, direct_sql->tgt_ssl_key, tmp_ssl_key,
+ &conn->tgt_ssl_key_length, direct_sql->tgt_ssl_key_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_default_file, direct_sql->tgt_default_file, tmp_default_file,
+ &conn->tgt_default_file_length, direct_sql->tgt_default_file_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_default_group, direct_sql->tgt_default_group, tmp_default_group,
+ &conn->tgt_default_group_length, direct_sql->tgt_default_group_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_dsn, direct_sql->tgt_dsn, tmp_dsn,
+ &conn->tgt_dsn_length, direct_sql->tgt_dsn_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_filedsn, direct_sql->tgt_filedsn, tmp_filedsn,
+ &conn->tgt_filedsn_length, direct_sql->tgt_filedsn_length);
+ spider_maybe_memcpy_string(
+ &conn->tgt_driver, direct_sql->tgt_driver, tmp_driver,
+ &conn->tgt_driver_length, direct_sql->tgt_driver_length);
conn->tgt_ssl_vsc = direct_sql->tgt_ssl_vsc;
conn->dbton_id = direct_sql->dbton_id;
conn->conn_need_mon = need_mon;
@@ -1658,6 +1619,11 @@ my_bool spider_direct_sql_init_body(
) {
SPIDER_BG_DIRECT_SQL *bg_direct_sql;
DBUG_ENTER("spider_direct_sql_init_body");
+ if (!spider_hton_ptr)
+ {
+ strcpy(message, "Plugin 'SPIDER' is not loaded");
+ goto error;
+ }
if (args->arg_count != 3)
{
strcpy(message, "spider_(bg)_direct_sql() requires 3 arguments");
diff --git a/storage/spider/spd_i_s.cc b/storage/spider/spd_i_s.cc
index 7db95371..8ae88102 100644
--- a/storage/spider/spd_i_s.cc
+++ b/storage/spider/spd_i_s.cc
@@ -28,6 +28,7 @@
#include "spd_table.h"
extern pthread_mutex_t spider_mem_calc_mutex;
+extern handlerton *spider_hton_ptr;
extern const char *spider_alloc_func_name[SPIDER_MEM_CALC_LIST_NUM];
extern const char *spider_alloc_file_name[SPIDER_MEM_CALC_LIST_NUM];
@@ -63,6 +64,8 @@ static int spider_i_s_alloc_mem_fill_table(
uint roop_count;
TABLE *table = tables->table;
DBUG_ENTER("spider_i_s_alloc_mem_fill_table");
+ if (!spider_hton_ptr)
+ DBUG_RETURN(0);
for (roop_count = 0; roop_count < SPIDER_MEM_CALC_LIST_NUM; roop_count++)
{
table->field[0]->store(roop_count, TRUE);
@@ -177,6 +180,8 @@ static int spider_i_s_wrapper_protocols_fill_table(
SPIDER_DBTON *dbton;
TABLE *table = tables->table;
DBUG_ENTER("spider_i_s_wrapper_protocols_fill_table");
+ if (!spider_hton_ptr)
+ DBUG_RETURN(0);
for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
{
dbton = &spider_dbton[roop_count];
diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h
index 0f61984e..3828f19b 100644
--- a/storage/spider/spd_include.h
+++ b/storage/spider/spd_include.h
@@ -250,7 +250,6 @@ enum spider_malloc_id {
SPD_MID_DB_MBASE_RESULT_FETCH_ROW_FROM_TMP_TABLE_3,
SPD_MID_DB_MBASE_ROW_APPEND_ESCAPED_TO_STR_1,
SPD_MID_DB_MBASE_ROW_CLONE_1,
- SPD_MID_DB_MBASE_SET_LOOP_CHECK_1,
SPD_MID_DB_MBASE_SET_SQL_MODE_1,
SPD_MID_DB_MBASE_SET_TIME_ZONE_1,
SPD_MID_DB_MBASE_SET_WAIT_TIMEOUT_1,
@@ -1417,6 +1416,7 @@ typedef struct st_spider_table_mon
st_spider_table_mon *next;
} SPIDER_TABLE_MON;
+/* List of `SPIDER_TABLE_MON's */
typedef struct st_spider_table_mon_list
{
char *key;
diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h
index 35a250c7..ced68e03 100644
--- a/storage/spider/spd_init_query.h
+++ b/storage/spider/spd_init_query.h
@@ -20,8 +20,16 @@
*/
static LEX_STRING spider_init_queries[] = {
+ /* Use the default SQL_MODE for this connection. */
{C_STRING_WITH_LEN(
- "SET @@SQL_MODE = REPLACE(@@SQL_MODE, 'ORACLE', '');"
+ "SET @@SQL_MODE = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,"
+ "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';"
+ )},
+ {C_STRING_WITH_LEN(
+ "SET @@OLD_MODE = CONCAT(@@OLD_MODE, ',UTF8_IS_UTF8MB3');"
+ )},
+ {C_STRING_WITH_LEN(
+ "SET tx_read_only = off;"
)},
{C_STRING_WITH_LEN(
"create table if not exists mysql.spider_xa("
diff --git a/storage/spider/spd_ping_table.cc b/storage/spider/spd_ping_table.cc
index 722b4cca..80b40c62 100644
--- a/storage/spider/spd_ping_table.cc
+++ b/storage/spider/spd_ping_table.cc
@@ -50,6 +50,8 @@ extern PSI_mutex_key spd_key_mutex_mon_list_update_status;
extern PSI_mutex_key spd_key_mutex_mon_table_cache;
#endif
+/* Array (of size `spider_udf_table_mon_mutex_count') of hashes of
+`SPIDER_TABLE_MON_LIST'. */
HASH *spider_udf_table_mon_list_hash;
uint spider_udf_table_mon_list_hash_id;
const char *spider_udf_table_mon_list_hash_func_name;
@@ -59,23 +61,43 @@ pthread_mutex_t *spider_udf_table_mon_mutexes;
pthread_cond_t *spider_udf_table_mon_conds;
pthread_mutex_t spider_mon_table_cache_mutex;
+/* A cache to store distinct SPIDER_MON_KEYs with db name, table name
+and link id read from mysql.spider_link_mon_servers table. Initialised
+and populated in spider_init_ping_table_mon_cache(), and used in
+spider_ping_table_cache_compare(). The udf
+spider_flush_table_mon_cache is used to flag a initialisation. */
DYNAMIC_ARRAY spider_mon_table_cache;
uint spider_mon_table_cache_id;
const char *spider_mon_table_cache_func_name;
const char *spider_mon_table_cache_file_name;
ulong spider_mon_table_cache_line_no;
-volatile ulonglong spider_mon_table_cache_version = 0;
-volatile ulonglong spider_mon_table_cache_version_req = 1;
-
+/* The mon table cache version, initialised at 0, and always no
+greater than spider_mon_table_cache_version_req. When the inequality
+is strict, an initialisation of spider_mon_table_cache will be
+triggered. */
+volatile ulonglong spider_mon_table_cache_version;
+/* The required mon table cache version, incremented by one by the
+udf spider_flush_table_mon_cache */
+volatile ulonglong spider_mon_table_cache_version_req;
+
+ /* Get or create a `SPIDER_TABLE_MON_LIST' for a key `str' */
SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
SPIDER_TRX *trx,
THD *thd,
- spider_string *str,
+ spider_string *str, /* The key to search in
+ `spider_udf_table_mon_list_hash',
+ usually in the format of
+ "./$db_name/$table_name000000000$link_idx" */
uint conv_name_length,
int link_idx,
char *static_link_id,
uint static_link_id_length,
- uint32 server_id,
+ uint32 server_id, /* The server id of the monitor
+ server, used for creating a new
+ table mon list having a
+ `SPIDER_TABLE_MON' corresponding to
+ the server id as the `current'
+ field */
bool need_lock,
int *error_num
) {
@@ -85,6 +107,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
ulonglong mon_table_cache_version;
my_hash_value_type hash_value;
DBUG_ENTER("spider_get_ping_table_mon_list");
+ /* Reset the cache if the version does not match the requirement */
if (spider_mon_table_cache_version != spider_mon_table_cache_version_req)
{
SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
@@ -97,6 +120,9 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
free_root(&mem_root, MYF(0));
}
+ /* Search for the table mon list in the hash, if one is not found or
+ if it is found but has the wrong cache version, create and
+ initialise a new one. */
mutex_hash=
spider_udf_calc_hash(str->c_ptr(), spider_udf_table_mon_mutex_count);
DBUG_PRINT("info",("spider hash key=%s", str->c_ptr()));
@@ -113,12 +139,15 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
table_mon_list->mon_table_cache_version != mon_table_cache_version
)
{
+ /* If table_mon_list is found but the cache version does not
+ match, remove it from the hash and free it. */
if (
table_mon_list &&
table_mon_list->mon_table_cache_version != mon_table_cache_version
)
spider_release_ping_table_mon_list_loop(mutex_hash, table_mon_list);
-
+ /* create and initialise `table_mon_list' and insert it into the
+ hash */
if (!(table_mon_list = spider_get_ping_table_tgt(thd, str->c_ptr(),
conv_name_length, link_idx, static_link_id, static_link_id_length,
server_id, str, need_lock, error_num)))
@@ -240,6 +269,14 @@ int spider_release_ping_table_mon_list(
DBUG_RETURN(0);
}
+/*
+ Look for a `SPIDER_MON_KEY` in `spider_mon_table_cache' whose db and
+ table name and link_idx matching `name' and `link_idx' with wild
+ card matching. If a match is found, create `SPIDER_TABLE_MON's from
+ all rows in mysql.spider_link_mon_servers that match the info in the
+ `SPIDER_MON_KEY' and populate the `table_mon_list' with these
+ `SPIDER_TABLE_MON's.
+*/
int spider_get_ping_table_mon(
THD *thd,
SPIDER_TABLE_MON_LIST *table_mon_list,
@@ -316,6 +353,8 @@ int spider_get_ping_table_mon(
goto error;
create_table_mon:
+ /* Find the first row in mysql.spider_link_mon_servers matching the
+ db name, table name and link_idx */
if ((error_num = spider_get_sys_table_by_idx(table_link_mon, table_key,
table_link_mon->s->primary_key, 3)))
{
@@ -323,6 +362,9 @@ create_table_mon:
goto error;
}
+ /* create one `SPIDER_TABLE_MON' per row in
+ mysql.spider_link_mon_servers with matching db name, table name and
+ link_idx, and add it to `table_mon_list'. */
do {
if (!(table_mon = (SPIDER_TABLE_MON *)
spider_bulk_malloc(spider_current_trx, SPD_MID_GET_PING_TABLE_MON_1, MYF(MY_WME | MY_ZEROFILL),
@@ -356,7 +398,7 @@ create_table_mon:
(error_num = spider_get_sys_link_mon_server_id(
table_link_mon, &table_mon->server_id, mem_root)) ||
(error_num = spider_get_sys_link_mon_connect_info(
- table_link_mon, tmp_share, 0, mem_root))
+ table_link_mon, tmp_share, mem_root))
) {
table_link_mon->file->print_error(error_num, MYF(0));
spider_sys_index_end(table_link_mon);
@@ -418,15 +460,21 @@ error:
DBUG_RETURN(error_num);
}
+/*
+ creates and return table_mon_list associated with table with `name'
+ and `link_idx'th link.
+*/
SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
THD *thd,
- char *name,
+ char *name, /* The table name, usually fully qualified */
uint name_length,
int link_idx,
char *static_link_id,
uint static_link_id_length,
- uint32 server_id,
- spider_string *str,
+ uint32 server_id, /* The server_id will determine the
+ `current' field of the returned
+ `SPIDER_TABLE_MON_LIST'. */
+ spider_string *str, /* str->c_ptr() == name */
bool need_lock,
int *error_num
) {
@@ -471,6 +519,7 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
memcpy(key_str, str->ptr(), table_mon_list->key_length);
tmp_share->access_charset = thd->variables.character_set_client;
+ /* Open mysql.spider_tables */
if (
!(table_tables = spider_open_sys_table(
thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
@@ -480,6 +529,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
my_error(*error_num, MYF(0));
goto error;
}
+ /* store db and table names and link idx in mysql.spider_tables for
+ reading */
spider_store_tables_name(table_tables, name, name_length);
if (static_link_id)
{
@@ -503,9 +554,10 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
goto error;
}
}
+ /* Populate tmp_share with info read from mysql.spider_tables */
if (
(*error_num = spider_get_sys_tables_connect_info(
- table_tables, tmp_share, 0, &mem_root)) ||
+ table_tables, tmp_share, &mem_root)) ||
(*error_num = spider_get_sys_tables_link_status(
table_tables, tmp_share, 0, &mem_root))
) {
@@ -527,9 +579,8 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_tgt(
tmp_share, name, name_length
)) ||
(*error_num = spider_create_conn_keys(tmp_share)) ||
-/*
- (*error_num = spider_db_create_table_names_str(tmp_share)) ||
-*/
+ /* Pinally, populate `table_mon_list' with newly created
+ `SPIDER_TABLE_MON's */
(*error_num = spider_get_ping_table_mon(
thd, table_mon_list, name, name_length, link_idx, server_id, &mem_root,
need_lock))
@@ -819,6 +870,11 @@ error_open_table_tables:
DBUG_RETURN(error_num);
}
+/*
+ Initialise `spider_mon_table_cache' by scanning the
+ mysql.spider_link_mon_servers table, creating distinct
+ `SPIDER_MON_KEY's with the info and inserting them into the cache.
+*/
int spider_init_ping_table_mon_cache(
THD *thd,
MEM_ROOT *mem_root,
@@ -847,6 +903,7 @@ int spider_init_ping_table_mon_cache(
/* reset */
spider_mon_table_cache.elements = 0;
+ /* start at the first row */
if ((error_num = spider_sys_index_first(table_link_mon,
table_link_mon->s->primary_key)))
{
@@ -863,10 +920,16 @@ int spider_init_ping_table_mon_cache(
mon_key.table_name_length = SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE + 1;
mon_key.link_id_length = SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + 1;
do {
+ /* update content of `mon_key' */
if ((error_num = spider_get_sys_link_mon_key(table_link_mon, &mon_key,
mem_root, &same)))
goto error_get_sys_link_mon_key;
+ /* `mon_key' has changed content. since
+ mysql.spider_link_mon_servers is indexed by db_name,
+ table_name, link_idx, and server_id, it is possible that
+ different server_ids share the same mon_key which only has
+ db_name, table_name, link_idx */
if (!same)
{
mon_key.sort = spider_calc_for_sort(3, mon_key.db_name,
@@ -937,6 +1000,13 @@ error_open_sys_table:
DBUG_RETURN(error_num);
}
+/*
+ Read from msyql.spider_link_mon_servers table fields the db name,
+ table name and link_id and search for them with wild card matching
+ in `spider_mon_table_cache'. store the db name, table name, and
+ link_id of the matching `SPIDER_MON_KEY' back to the table field on
+ success.
+*/
int spider_ping_table_cache_compare(
TABLE *table,
MEM_ROOT *mem_root
@@ -1213,9 +1283,6 @@ long long spider_ping_table_body(
DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 2"));
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{
-/*
- pthread_mutex_lock(&table_mon_list->update_status_mutex);
-*/
pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{
@@ -1230,9 +1297,6 @@ long long spider_ping_table_body(
conv_name.c_ptr(), conv_name_length, link_idx, TRUE);
status_changed_to_ng = TRUE;
}
-/*
- pthread_mutex_unlock(&table_mon_list->update_status_mutex);
-*/
pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (status_changed_to_ng)
{
@@ -1286,9 +1350,6 @@ long long spider_ping_table_body(
DBUG_PRINT("info",("spider mon_table_result->result_status=SPIDER_LINK_MON_NG 3"));
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{
-/*
- pthread_mutex_lock(&table_mon_list->update_status_mutex);
-*/
pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{
@@ -1303,9 +1364,6 @@ long long spider_ping_table_body(
conv_name.c_ptr(), conv_name_length, link_idx, TRUE);
status_changed_to_ng = TRUE;
}
-/*
- pthread_mutex_unlock(&table_mon_list->update_status_mutex);
-*/
pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (status_changed_to_ng)
{
@@ -1349,9 +1407,6 @@ long long spider_ping_table_body(
mon_table_result->result_status == SPIDER_LINK_MON_NG &&
table_mon_list->mon_status != SPIDER_LINK_MON_NG
) {
-/*
- pthread_mutex_lock(&table_mon_list->update_status_mutex);
-*/
pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{
@@ -1366,9 +1421,6 @@ long long spider_ping_table_body(
conv_name.c_ptr(), conv_name_length, link_idx, TRUE);
status_changed_to_ng = TRUE;
}
-/*
- pthread_mutex_unlock(&table_mon_list->update_status_mutex);
-*/
pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (status_changed_to_ng)
{
@@ -1539,9 +1591,9 @@ int spider_ping_table_mon_from_table(
SPIDER_SHARE *share,
int base_link_idx,
uint32 server_id,
- char *conv_name,
+ char *conv_name, /* Usually fully qualified table name */
uint conv_name_length,
- int link_idx,
+ int link_idx, /* The link id to ping */
char *where_clause,
uint where_clause_length,
long monitoring_kind,
@@ -1551,9 +1603,6 @@ int spider_ping_table_mon_from_table(
) {
int error_num = 0, current_mon_count, flags;
uint32 first_sid;
-/*
- THD *thd = trx->thd;
-*/
SPIDER_TABLE_MON_LIST *table_mon_list;
SPIDER_TABLE_MON *table_mon;
SPIDER_MON_TABLE_RESULT mon_table_result;
@@ -1622,6 +1671,7 @@ int spider_ping_table_mon_from_table(
if (monitoring_flag & 1)
flags |= SPIDER_UDF_PING_TABLE_USE_ALL_MONITORING_NODES;
+ /* Get or create `table_mon_list' for `conv_name_str'. */
if (!(table_mon_list = spider_get_ping_table_mon_list(trx, thd,
&conv_name_str, conv_name_length, link_idx,
share->static_link_ids[link_idx],
@@ -1653,6 +1703,8 @@ int spider_ping_table_mon_from_table(
table_mon = table_mon_list->current;
first_sid = table_mon->server_id;
current_mon_count = 1;
+ /* Call spider_ping_table on each table_mon of `table_mon_list',
+ until one succeeds */
while (TRUE)
{
DBUG_PRINT("info",("spider thd->killed=%s",
@@ -1697,16 +1749,13 @@ int spider_ping_table_mon_from_table(
if (!spider_db_udf_ping_table_mon_next(
thd, table_mon, mon_conn, &mon_table_result, conv_name,
conv_name_length, link_idx,
- where_clause, where_clause_length, -1, table_mon_list->list_size,
+ where_clause, where_clause_length, /*first_sid=*/-1, table_mon_list->list_size,
0, 0, 0, flags, monitoring_limit))
{
if (
mon_table_result.result_status == SPIDER_LINK_MON_NG &&
table_mon_list->mon_status != SPIDER_LINK_MON_NG
) {
-/*
- pthread_mutex_lock(&table_mon_list->update_status_mutex);
-*/
pthread_mutex_lock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
if (table_mon_list->mon_status != SPIDER_LINK_MON_NG)
{
@@ -1721,9 +1770,6 @@ int spider_ping_table_mon_from_table(
spider_sys_log_tables_link_failed(thd, conv_name,
conv_name_length, link_idx, need_lock);
}
-/*
- pthread_mutex_unlock(&table_mon_list->update_status_mutex);
-*/
pthread_mutex_unlock(&spider_udf_table_mon_mutexes[table_mon_list->mutex_hash]);
}
table_mon_list->last_caller_result = mon_table_result.result_status;
diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc
index 912e02a7..bd3e7a6f 100644
--- a/storage/spider/spd_sys_table.cc
+++ b/storage/spider/spd_sys_table.cc
@@ -574,6 +574,11 @@ int spider_check_sys_table_for_update_all_columns(
HA_WHOLE_KEY, HA_READ_KEY_EXACT));
}
+/*
+ Creates a key (`table_key') consisting of `col_count' key parts of
+ `idx'th index of the table, then positions an index cursor to that
+ key.
+*/
int spider_get_sys_table_by_idx(
TABLE *table,
char *table_key,
@@ -629,7 +634,7 @@ int spider_sys_index_next_same(
int spider_sys_index_first(
TABLE *table,
- const int idx
+ const int idx /* which index to use */
) {
int error_num;
DBUG_ENTER("spider_sys_index_first");
@@ -871,6 +876,10 @@ void spider_store_xa_member_info(
DBUG_VOID_RETURN;
}
+/*
+ Store db and table names from `name' to `table's corresponding
+ fields
+*/
void spider_store_tables_name(
TABLE *table,
const char *name,
@@ -2149,14 +2158,16 @@ int spider_get_sys_tables(
DBUG_RETURN(0);
}
+/* Read table info from mysql.spider_tables into a `SPIDER_SHARE' */
int spider_get_sys_tables_connect_info(
- TABLE *table,
- SPIDER_SHARE *share,
- int link_idx,
+ TABLE *table, /* The mysql.spider_tables table */
+ SPIDER_SHARE *share, /* The `SPIDER_SHARE' to
+ update info */
MEM_ROOT *mem_root
) {
char *ptr;
int error_num = 0;
+ const int link_idx= 0;
DBUG_ENTER("spider_get_sys_tables_connect_info");
DBUG_PRINT("info",("spider link_idx:%d", link_idx));
if ((ptr = get_field(mem_root, table->field[SPIDER_TABLES_PRIORITY_POS])))
@@ -2431,9 +2442,14 @@ int spider_get_sys_tables_monitoring_binlog_pos_at_failing(
DBUG_RETURN(error_num);
}
+/*
+ Read the link status from mysql.spider_tables into a `SPIDER_SHARE'
+ with default value 1 (`SPIDER_LINK_STATUS_OK')
+*/
int spider_get_sys_tables_link_status(
- TABLE *table,
- SPIDER_SHARE *share,
+ TABLE *table, /* The mysql.spider_tables table */
+ SPIDER_SHARE *share, /* The share to read link
+ status into */
int link_idx,
MEM_ROOT *mem_root
) {
@@ -2607,11 +2623,17 @@ error:
DBUG_RETURN(error_num);
}
+/* Populate `mon_key' from the current row in `table' */
int spider_get_sys_link_mon_key(
- TABLE *table,
- SPIDER_MON_KEY *mon_key,
+ TABLE *table, /* the mysql.spider_link_mon_servers
+ table */
+ SPIDER_MON_KEY *mon_key, /* output, to be populated in this
+ function */
MEM_ROOT *mem_root,
- int *same
+ int *same /* output, true if the data from the
+ current row in the table agrees with
+ existing data in `mon_key' and false
+ otherwise */
) {
char *db_name, *table_name, *link_id;
uint db_name_length, table_name_length, link_id_length;
@@ -2627,6 +2649,7 @@ int spider_get_sys_link_mon_key(
DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM);
}
+ /* get data for `mon_key' from the table record */
if (!(db_name=
get_field(mem_root,
table->field[SPIDER_LINK_MON_SERVERS_DB_NAME_POS])))
@@ -2678,9 +2701,12 @@ int spider_get_sys_link_mon_key(
DBUG_RETURN(0);
}
+/* Get the server id from the spider_link_mon_servers table field */
int spider_get_sys_link_mon_server_id(
- TABLE *table,
- uint32 *server_id,
+ TABLE *table, /* the
+ mysql.spider_link_mon_servers
+ table */
+ uint32 *server_id, /* output to server_id */
MEM_ROOT *mem_root
) {
char *ptr;
@@ -2694,14 +2720,17 @@ int spider_get_sys_link_mon_server_id(
DBUG_RETURN(error_num);
}
+/* Get connect info from the spider_link_mon_servers table fields */
int spider_get_sys_link_mon_connect_info(
- TABLE *table,
- SPIDER_SHARE *share,
- int link_idx,
+ TABLE *table, /* The
+ mysql.spider_link_mon_servers
+ table */
+ SPIDER_SHARE *share, /* The output spider_share */
MEM_ROOT *mem_root
) {
char *ptr;
int error_num = 0;
+ const int link_idx= 0;
DBUG_ENTER("spider_get_sys_link_mon_connect_info");
if (
!table->field[SPIDER_LINK_MON_SERVERS_SERVER_POS]->is_null() &&
@@ -2930,9 +2959,6 @@ int spider_get_link_statuses(
if (
(error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE)
) {
-/*
- table->file->print_error(error_num, MYF(0));
-*/
DBUG_RETURN(error_num);
}
} else if ((error_num =
diff --git a/storage/spider/spd_sys_table.h b/storage/spider/spd_sys_table.h
index f1983323..ce3897c7 100644
--- a/storage/spider/spd_sys_table.h
+++ b/storage/spider/spd_sys_table.h
@@ -56,6 +56,7 @@
#define SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE 64
#define SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE 64
+/* For insertion into `spider_mon_table_cache'. */
class SPIDER_MON_KEY: public SPIDER_SORT
{
public:
@@ -401,7 +402,6 @@ int spider_get_sys_tables(
int spider_get_sys_tables_connect_info(
TABLE *table,
SPIDER_SHARE *share,
- int link_idx,
MEM_ROOT *mem_root
);
@@ -478,7 +478,6 @@ int spider_get_sys_link_mon_server_id(
int spider_get_sys_link_mon_connect_info(
TABLE *table,
SPIDER_SHARE *share,
- int link_idx,
MEM_ROOT *mem_root
);
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index 208b804f..4b0690be 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -124,6 +124,11 @@ extern SPIDER_DBTON spider_dbton_mysql;
extern SPIDER_DBTON spider_dbton_mariadb;
SPIDER_THREAD *spider_table_sts_threads;
SPIDER_THREAD *spider_table_crd_threads;
+extern volatile ulonglong spider_mon_table_cache_version;
+extern volatile ulonglong spider_mon_table_cache_version_req;
+extern ulonglong spider_conn_id;
+extern Time_zone *UTC;
+extern ulonglong spider_thread_id;
#ifdef HAVE_PSI_INTERFACE
PSI_mutex_key spd_key_mutex_tbl;
@@ -3468,11 +3473,13 @@ error_alloc_conn_string:
DBUG_RETURN(error_num);
}
+/* Set default connect info of a SPIDER_SHARE if needed */
int spider_set_connect_info_default(
- SPIDER_SHARE *share,
- partition_element *part_elem,
- partition_element *sub_elem,
- TABLE_SHARE *table_share
+ SPIDER_SHARE *share, /* The `SPIDER_SHARE' to set
+ default connect info */
+ partition_element *part_elem, /* partition info used as input */
+ partition_element *sub_elem, /* subpartition info used as input */
+ TABLE_SHARE *table_share /* table share info used as input */
) {
bool check_socket;
bool check_database;
@@ -3706,22 +3713,6 @@ int spider_set_connect_info_default(
}
}
-/*
- if (!share->static_link_ids[roop_count])
- {
- DBUG_PRINT("info",("spider create default static_link_ids"));
- share->static_link_ids_lengths[roop_count] =
- SPIDER_DB_STATIC_LINK_ID_LEN;
- if (
- !(share->static_link_ids[roop_count] = spider_create_string(
- SPIDER_DB_STATIC_LINK_ID_STR,
- share->static_link_ids_lengths[roop_count]))
- ) {
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- }
- }
-*/
-
if (port_has_default_value)
{
share->tgt_ports[roop_count] = MYSQL_PORT;
@@ -3811,7 +3802,11 @@ int spider_set_connect_info_default(
DBUG_RETURN(0);
}
-
+/*
+ This function is a no-op if all share->tgt_dbs and
+ share->tgt_table_names are non-null, otherwise it may assign them
+ with db_name and table_name
+*/
int spider_set_connect_info_default_db_table(
SPIDER_SHARE *share,
const char *db_name,
@@ -3897,6 +3892,11 @@ int spider_set_connect_info_default_db_table(
DBUG_RETURN(0);
}
+/*
+ Parse `dbtable_name' into db name and table name, and call
+ spider_set_connect_info_default_db_table() to set the db/table name
+ values of `share' if needed
+*/
int spider_set_connect_info_default_dbtable(
SPIDER_SHARE *share,
const char *dbtable_name,
@@ -4256,12 +4256,12 @@ SPIDER_SHARE *spider_create_share(
share->table.key_info = table_share->key_info;
share->table.read_set = &table_share->all_set;
- if (table_share->keys > 0 &&
- !(share->key_hint = new spider_string[table_share->keys])
- ) {
- *error_num = HA_ERR_OUT_OF_MEM;
- goto error_init_hint_string;
- }
+ if (table_share->keys > 0)
+ if (!(share->key_hint = new spider_string[table_share->keys]))
+ {
+ *error_num = HA_ERR_OUT_OF_MEM;
+ goto error_init_hint_string;
+ }
for (roop_count = 0; roop_count < (int) table_share->keys; roop_count++)
share->key_hint[roop_count].init_calc_mem(SPD_MID_CREATE_SHARE_2);
DBUG_PRINT("info",("spider share->key_hint=%p", share->key_hint));
@@ -5797,7 +5797,7 @@ int spider_open_all_tables(
(error_num = spider_get_sys_tables(
table_tables, &db_name, &table_name, &mem_root)) ||
(error_num = spider_get_sys_tables_connect_info(
- table_tables, &tmp_share, 0, &mem_root)) ||
+ table_tables, &tmp_share, &mem_root)) ||
(error_num = spider_set_connect_info_default(
&tmp_share,
NULL,
@@ -6084,7 +6084,11 @@ int spider_close_connection(
}
spider_rollback(spider_hton_ptr, thd, TRUE);
+
+ Dummy_error_handler deh; // suppress network errors at this stage
+ thd->push_internal_handler(&deh);
spider_free_trx(trx, TRUE, false);
+ thd->pop_internal_handler();
DBUG_RETURN(0);
}
@@ -6255,6 +6259,7 @@ int spider_db_done(
pthread_mutex_destroy(&spider_tbl_mutex);
pthread_attr_destroy(&spider_pt_attr);
+ spider_hton_ptr= NULL;
for (roop_count = 0; roop_count < SPIDER_MEM_CALC_LIST_NUM; roop_count++)
{
if (spider_alloc_func_name[roop_count])
@@ -6346,6 +6351,12 @@ int spider_db_init(
handlerton *spider_hton = (handlerton *)p;
DBUG_ENTER("spider_db_init");
+ spider_mon_table_cache_version= 0;
+ spider_mon_table_cache_version_req= 1;
+ spider_conn_id= 1;
+ spider_conn_mutex_id= 0;
+ UTC = 0;
+ spider_thread_id = 1;
const LEX_CSTRING aria_name={STRING_WITH_LEN("Aria")};
if (!plugin_is_ready(&aria_name, MYSQL_STORAGE_ENGINE_PLUGIN))
DBUG_RETURN(HA_ERR_RETRY_INIT);
@@ -6579,11 +6590,6 @@ int spider_db_init(
spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
}
- if (spider_init_system_tables())
- {
- goto error_system_table_creation;
- }
-
if (!(spider_table_sts_threads = (SPIDER_THREAD *)
spider_bulk_malloc(NULL, SPD_MID_DB_INIT_12, MYF(MY_WME | MY_ZEROFILL),
&spider_table_sts_threads, (uint) (sizeof(SPIDER_THREAD) *
@@ -6592,7 +6598,7 @@ int spider_db_init(
spider_param_table_crd_thread_count()),
NullS))
)
- goto error_alloc_mon_mutxes;
+ goto error_alloc_table_sts_crd_threads;
for (roop_count = 0;
roop_count < (int) spider_param_table_sts_thread_count();
@@ -6653,6 +6659,7 @@ error_init_table_sts_threads:
{
spider_free_sts_threads(&spider_table_sts_threads[roop_count]);
}
+error_alloc_table_sts_crd_threads:
spider_free(NULL, spider_table_sts_threads, MYF(0));
roop_count= spider_udf_table_mon_mutex_count - 1;
error_init_udf_table_mon_list_hash:
@@ -6668,7 +6675,6 @@ error_init_udf_table_mon_list_hash:
error_init_udf_table_mon_cond:
for (; roop_count >= 0; roop_count--)
pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]);
-error_system_table_creation:
roop_count= spider_udf_table_mon_mutex_count - 1;
error_init_udf_table_mon_mutex:
for (; roop_count >= 0; roop_count--)
diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc
index ebf9a777..b7a92286 100644
--- a/storage/spider/spd_trx.cc
+++ b/storage/spider/spd_trx.cc
@@ -41,7 +41,7 @@ extern struct charset_info_st *spd_charset_utf8mb3_bin;
extern handlerton *spider_hton_ptr;
extern SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
pthread_mutex_t spider_thread_id_mutex;
-ulonglong spider_thread_id = 1;
+ulonglong spider_thread_id;
#ifdef HAVE_PSI_INTERFACE
extern PSI_mutex_key spd_key_mutex_udf_table;