summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayuta Yanagisawa <nayuta.yanagisawa@hey.com>2022-10-23 19:59:34 +0900
committerNayuta Yanagisawa <nayuta.yanagisawa@hey.com>2022-11-24 17:11:41 +0900
commit162c1505052030e3496f83c5b711fd0ef5cb2bea (patch)
treebd2b81c897476eae78ce7ba22cda93be2ef66999
parentd569e6dea4c451469a0c293692c3db0e963309ce (diff)
downloadmariadb-git-162c1505052030e3496f83c5b711fd0ef5cb2bea.tar.gz
MDEV-29855 Crash with SPIDER_DIRECT_SQL and spider_udf_ds_use_real_table=1
The crash occurs because of the following call of TABLE_LIST::init_one_table(): table_list.init_one_table( &table_list.db, &table_list.table_name, 0, TL_WRITE); One should not pass table_list.db and table_list.table_name to the function because it update the very members internally. The function is called previously, and there is no need to call it again. So, simply removing the call will resolve the problem.
-rw-r--r--storage/spider/mysql-test/spider/bugfix/r/mdev_29855.result34
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_29855.cnf3
-rw-r--r--storage/spider/mysql-test/spider/bugfix/t/mdev_29855.test40
-rw-r--r--storage/spider/spd_direct_sql.cc11
4 files changed, 77 insertions, 11 deletions
diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29855.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29855.result
new file mode 100644
index 00000000000..4335d20f4c3
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29855.result
@@ -0,0 +1,34 @@
+#
+# MDEV-29855 Crash with SPIDER_DIRECT_SQL and spider_udf_ds_use_real_table=1
+#
+for master_1
+for child2
+child2_1
+child2_2
+child2_3
+for child3
+connection child2_1;
+CREATE DATABASE auto_test_remote;
+USE auto_test_remote;
+CREATE TABLE tbl_a (
+a INT
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+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"';
+SET spider_udf_ds_use_real_table=1;
+SELECT SPIDER_DIRECT_SQL('select 1 as 1', 'tbl_a', 'srv "s_2_1"');
+ERROR 3D000: No database selected
+connection master_1;
+DROP DATABASE IF EXISTS auto_test_local;
+connection child2_1;
+DROP DATABASE IF EXISTS auto_test_remote;
+for master_1
+for child2
+child2_1
+child2_2
+child2_3
+for child3
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29855.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_29855.cnf
new file mode 100644
index 00000000000..05dfd8a0bce
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29855.cnf
@@ -0,0 +1,3 @@
+!include include/default_mysqld.cnf
+!include ../my_1_1.cnf
+!include ../my_2_1.cnf
diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29855.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29855.test
new file mode 100644
index 00000000000..13cda064c72
--- /dev/null
+++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29855.test
@@ -0,0 +1,40 @@
+--echo #
+--echo # MDEV-29855 Crash with SPIDER_DIRECT_SQL and spider_udf_ds_use_real_table=1
+--echo #
+
+
+--disable_query_log
+--disable_result_log
+--source ../../t/test_init.inc
+--enable_result_log
+--enable_query_log
+
+--connection child2_1
+CREATE DATABASE auto_test_remote;
+USE auto_test_remote;
+eval CREATE TABLE tbl_a (
+ a INT
+) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
+
+--connection master_1
+CREATE DATABASE auto_test_local;
+USE auto_test_local;
+eval CREATE TABLE tbl_a (
+ a INT
+) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"';
+
+SET spider_udf_ds_use_real_table=1;
+--error ER_NO_DB_ERROR
+SELECT SPIDER_DIRECT_SQL('select 1 as 1', 'tbl_a', 'srv "s_2_1"');
+
+--connection master_1
+DROP DATABASE IF EXISTS auto_test_local;
+
+--connection child2_1
+DROP DATABASE IF EXISTS auto_test_remote;
+
+--disable_query_log
+--disable_result_log
+--source ../t/test_deinit.inc
+--enable_query_log
+--enable_result_log
diff --git a/storage/spider/spd_direct_sql.cc b/storage/spider/spd_direct_sql.cc
index 7237d0877a7..98338cd06f5 100644
--- a/storage/spider/spd_direct_sql.cc
+++ b/storage/spider/spd_direct_sql.cc
@@ -1738,17 +1738,6 @@ long long spider_direct_sql_body(
#else
}
TABLE_LIST *tables = &direct_sql->table_list[roop_count];
-#ifdef SPIDER_use_LEX_CSTRING_for_database_tablename_alias
- table_list.init_one_table(
- &table_list.db, &table_list.table_name, 0, TL_WRITE);
-#else
- tables->init_one_table(
- SPIDER_TABLE_LIST_db_str(&table_list),
- SPIDER_TABLE_LIST_db_length(&table_list),
- SPIDER_TABLE_LIST_table_name_str(&table_list),
- SPIDER_TABLE_LIST_table_name_length(&table_list),
- SPIDER_TABLE_LIST_table_name_str(&table_list), TL_WRITE);
-#endif
tables->mdl_request.init(MDL_key::TABLE,
SPIDER_TABLE_LIST_db_str(&table_list),
SPIDER_TABLE_LIST_table_name_str(&table_list),