1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

MDEV-37744 Table Charset Mismatch (Primary/Replica) via Event

Events should use proper mysql_change_db() to configure the current
database correctly, in particular to set the db_charset.
This commit is contained in:
Sergei Golubchik
2025-10-15 17:05:32 +02:00
parent 5a8cd03f0f
commit 78ed44beb3
3 changed files with 50 additions and 20 deletions

View File

@@ -437,3 +437,27 @@ Warnings:
Note 1544 Event execution time is in the past. Event has been disabled
drop event event_35981;
drop database events_test;
#
# MDEV-37744 Table Charset Mismatch (Primary/Replica) via Event
#
set global event_scheduler=1;
create schema andre default charset utf8mb4 collate utf8mb4_general_ci;
use andre;
create event daily_table_creation
on schedule every 1 day starts now() + interval 5 second do
create table andre_table (
id int(11) not null auto_increment primary key,
col_1 varchar(50) not null
);
show create table andre_table;
Table Create Table
andre_table CREATE TABLE `andre_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`col_1` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
set global event_scheduler=0;
drop event daily_table_creation;
drop schema andre;
use test;
# End of 10.11 tests

View File

@@ -526,3 +526,26 @@ let $wait_condition=
drop database events_test;
--enable_service_connection
--echo #
--echo # MDEV-37744 Table Charset Mismatch (Primary/Replica) via Event
--echo #
set global event_scheduler=1;
create schema andre default charset utf8mb4 collate utf8mb4_general_ci;
use andre;
create event daily_table_creation
on schedule every 1 day starts now() + interval 5 second do
create table andre_table (
id int(11) not null auto_increment primary key,
col_1 varchar(50) not null
);
let $wait_condition= select count(*)= 1 from information_schema.tables where table_name = 'andre_table';
source include/wait_condition.inc;
show create table andre_table;
set global event_scheduler=0;
drop event daily_table_creation;
drop schema andre;
use test;
--echo # End of 10.11 tests

View File

@@ -1371,30 +1371,13 @@ Event_job_data::execute(THD *thd, bool drop)
wsrep_open(thd);
wsrep_before_command(thd);
#endif /* WITH_WSREP */
/*
MySQL parser currently assumes that current database is either
present in THD or all names in all statements are fully specified.
And yet not fully specified names inside stored programs must be
be supported, even if the current database is not set:
CREATE PROCEDURE db1.p1() BEGIN CREATE TABLE t1; END//
-- in this example t1 should be always created in db1 and the statement
must parse even if there is no current database.
To support this feature and still address the parser limitation,
we need to set the current database here.
We don't have to call mysql_change_db, since the checks performed
in it are unnecessary for the purpose of parsing, and
mysql_change_db will be invoked anyway later, to activate the
procedure database before it's executed.
*/
thd->set_db(&dbname);
lex_start(thd);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (event_sctx.change_security_context(thd,
&definer_user, &definer_host,
&dbname, &save_sctx))
if (event_sctx.change_security_context(thd, &definer_user, &definer_host,
&dbname, &save_sctx) ||
mysql_change_db(thd, &dbname, false))
{
sql_print_error("Event Scheduler: "
"[%s].[%s.%s] execution failed, "