Skip to content

Commit

Permalink
MDEV-29872 MSAN/Valgrind uninitialised value errors in TABLE::vers_sw…
Browse files Browse the repository at this point in the history
…itch_partition

Delayed_insert has its own THD (initialized at mysql_insert()) and
hence its own LEX. Delayed_insert initalizes a very few parameters for
LEX and 'duplicates' is not in this list. Now we copy this missing
parameter from parser LEX (as well as sql_command).
  • Loading branch information
midenok committed Apr 1, 2024
1 parent d966e55 commit c477697
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions mysql-test/suite/versioning/r/partition.result
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,11 @@ unlock tables;
drop table t1, t2;
set timestamp= default;
#
# MDEV-29872 MSAN/Valgrind uninitialised value errors in TABLE::vers_switch_partition
#
create table t (a int) with system versioning partition by system_time limit 100 partitions 3;
drop table t;
#
# End of 10.9 tests
#
set global innodb_stats_persistent= @save_persistent;
17 changes: 17 additions & 0 deletions mysql-test/suite/versioning/t/partition.test
Original file line number Diff line number Diff line change
Expand Up @@ -2690,6 +2690,23 @@ unlock tables;
drop table t1, t2;
set timestamp= default;

--echo #
--echo # MDEV-29872 MSAN/Valgrind uninitialised value errors in TABLE::vers_switch_partition
--echo #
create table t (a int) with system versioning partition by system_time limit 100 partitions 3;
let $emb= `select if(version() like '%embedded%', 1, 0)`;
if (!$emb)
{
--disable_result_log
--disable_query_log
--error ER_DELAYED_NOT_SUPPORTED
insert delayed into t () values ();
--enable_query_log
--enable_result_log
}
# cleanup
drop table t;

--echo #
--echo # End of 10.9 tests
--echo #
Expand Down
9 changes: 5 additions & 4 deletions sql/sql_insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,7 @@ class Delayed_insert :public ilink {
passed from connection thread to the handler thread.
*/
MDL_request grl_protection;
Delayed_insert(SELECT_LEX *current_select)
Delayed_insert(LEX *lex)
:locks_in_memory(0), thd(next_thread_id()),
table(0),tables_in_use(0), stacked_inserts(0),
status(0), retry(0), handler_thread_initialized(FALSE), group_count(0)
Expand All @@ -2414,8 +2414,9 @@ class Delayed_insert :public ilink {
strmake_buf(thd.security_ctx->priv_user, thd.security_ctx->user);
thd.current_tablenr=0;
thd.set_command(COM_DELAYED_INSERT);
thd.lex->current_select= current_select;
thd.lex->sql_command= SQLCOM_INSERT; // For innodb::store_lock()
thd.lex->current_select= lex->current_select;
thd.lex->sql_command= lex->sql_command; // For innodb::store_lock()
thd.lex->duplicates= lex->duplicates;
/*
Prevent changes to global.lock_wait_timeout from affecting
delayed insert threads as any timeouts in delayed inserts
Expand Down Expand Up @@ -2591,7 +2592,7 @@ bool delayed_get_table(THD *thd, MDL_request *grl_protection_request,
*/
if (! (di= find_handler(thd, table_list)))
{
if (!(di= new Delayed_insert(thd->lex->current_select)))
if (!(di= new Delayed_insert(thd->lex)))
goto end_create;

/*
Expand Down

0 comments on commit c477697

Please sign in to comment.