diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_26582.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_26582.result new file mode 100644 index 00000000000..54a4fc44b48 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_26582.result @@ -0,0 +1,11 @@ +# +# MDEV-26582 SIGSEGV in spider_db_bulk_insert and spider_db_connect and spider_db_before_query, and hang in "End of update loop" / "Reset for next command" query states +# +CREATE DATABASE IF NOT EXISTS auto_test_local; +USE auto_test_local; +CREATE TABLE t (i CHAR) ENGINE=SPIDER; +INSERT INTO t VALUES (0); +ERROR HY000: Unable to connect to foreign data source: localhost +INSERT t SELECT 1 ON DUPLICATE KEY UPDATE c=1; +ERROR 42S22: Unknown column 'c' in 'field list' +DROP DATABASE IF EXISTS auto_test_local; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.cnf new file mode 100644 index 00000000000..b0853e32654 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.cnf @@ -0,0 +1,2 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.test new file mode 100644 index 00000000000..714a5e1c853 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_26582.test @@ -0,0 +1,27 @@ +--echo # +--echo # MDEV-26582 SIGSEGV in spider_db_bulk_insert and spider_db_connect and spider_db_before_query, and hang in "End of update loop" / "Reset for next command" query states +--echo # + +# NOTE: The bug does not reproduce if we import ../../t/test_init.inc instead. +--disable_query_log +--disable_result_log +--source ../../include/init_spider.inc +--enable_result_log +--enable_query_log + +CREATE DATABASE IF NOT EXISTS auto_test_local; +USE auto_test_local; + +CREATE TABLE t (i CHAR) ENGINE=SPIDER; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +INSERT INTO t VALUES (0); +--error ER_BAD_FIELD_ERROR +INSERT t SELECT 1 ON DUPLICATE KEY UPDATE c=1; + +DROP DATABASE IF EXISTS auto_test_local; + +--disable_query_log +--disable_result_log +--source ../../include/deinit_spider.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 22567d82bc1..d2cce0ba6d0 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -6661,7 +6661,11 @@ int spider_db_bulk_insert( #endif if ((error_num = spider->append_insert_values_sql_part( SPIDER_SQL_TYPE_INSERT_SQL))) + { + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); DBUG_RETURN(error_num); + } #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) } if (spider->sql_kinds & SPIDER_SQL_KIND_HS) @@ -6681,6 +6685,8 @@ int spider_db_bulk_insert( if ((error_num = spider->append_insert_terminator_sql_part( SPIDER_SQL_TYPE_INSERT_SQL))) { + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); DBUG_RETURN(error_num); } #ifdef HA_CAN_BULK_ACCESS @@ -6715,6 +6721,8 @@ int spider_db_bulk_insert( if ((error_num = dbton_handler->set_sql_for_exec(sql_type, roop_count2))) { + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); if (dbton_handler->need_lock_before_set_sql_for_exec(sql_type)) { SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); @@ -6744,6 +6752,8 @@ int spider_db_bulk_insert( conn->mta_conn_mutex_unlock_later = TRUE; if ((error_num = spider_db_set_names(spider, conn, roop_count2))) { + if (spider->sql_kinds & SPIDER_SQL_KIND_SQL) + spider->set_insert_to_pos_sql(SPIDER_SQL_TYPE_INSERT_SQL); DBUG_ASSERT(conn->mta_conn_mutex_lock_already); DBUG_ASSERT(conn->mta_conn_mutex_unlock_later); conn->mta_conn_mutex_lock_already = FALSE;