Skip to content

Commit 78ed44b

Browse files
committed
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.
1 parent 5a8cd03 commit 78ed44b

File tree

3 files changed

+50
-20
lines changed

3 files changed

+50
-20
lines changed

mysql-test/main/events_2.result

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,27 @@ Warnings:
437437
Note 1544 Event execution time is in the past. Event has been disabled
438438
drop event event_35981;
439439
drop database events_test;
440+
#
441+
# MDEV-37744 Table Charset Mismatch (Primary/Replica) via Event
442+
#
443+
set global event_scheduler=1;
444+
create schema andre default charset utf8mb4 collate utf8mb4_general_ci;
445+
use andre;
446+
create event daily_table_creation
447+
on schedule every 1 day starts now() + interval 5 second do
448+
create table andre_table (
449+
id int(11) not null auto_increment primary key,
450+
col_1 varchar(50) not null
451+
);
452+
show create table andre_table;
453+
Table Create Table
454+
andre_table CREATE TABLE `andre_table` (
455+
`id` int(11) NOT NULL AUTO_INCREMENT,
456+
`col_1` varchar(50) NOT NULL,
457+
PRIMARY KEY (`id`)
458+
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
459+
set global event_scheduler=0;
460+
drop event daily_table_creation;
461+
drop schema andre;
462+
use test;
463+
# End of 10.11 tests

mysql-test/main/events_2.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,26 @@ let $wait_condition=
526526

527527
drop database events_test;
528528
--enable_service_connection
529+
530+
--echo #
531+
--echo # MDEV-37744 Table Charset Mismatch (Primary/Replica) via Event
532+
--echo #
533+
set global event_scheduler=1;
534+
create schema andre default charset utf8mb4 collate utf8mb4_general_ci;
535+
use andre;
536+
create event daily_table_creation
537+
on schedule every 1 day starts now() + interval 5 second do
538+
create table andre_table (
539+
id int(11) not null auto_increment primary key,
540+
col_1 varchar(50) not null
541+
);
542+
543+
let $wait_condition= select count(*)= 1 from information_schema.tables where table_name = 'andre_table';
544+
source include/wait_condition.inc;
545+
show create table andre_table;
546+
set global event_scheduler=0;
547+
drop event daily_table_creation;
548+
drop schema andre;
549+
use test;
550+
551+
--echo # End of 10.11 tests

sql/event_data_objects.cc

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,30 +1371,13 @@ Event_job_data::execute(THD *thd, bool drop)
13711371
wsrep_open(thd);
13721372
wsrep_before_command(thd);
13731373
#endif /* WITH_WSREP */
1374-
/*
1375-
MySQL parser currently assumes that current database is either
1376-
present in THD or all names in all statements are fully specified.
1377-
And yet not fully specified names inside stored programs must be
1378-
be supported, even if the current database is not set:
1379-
CREATE PROCEDURE db1.p1() BEGIN CREATE TABLE t1; END//
1380-
-- in this example t1 should be always created in db1 and the statement
1381-
must parse even if there is no current database.
1382-
1383-
To support this feature and still address the parser limitation,
1384-
we need to set the current database here.
1385-
We don't have to call mysql_change_db, since the checks performed
1386-
in it are unnecessary for the purpose of parsing, and
1387-
mysql_change_db will be invoked anyway later, to activate the
1388-
procedure database before it's executed.
1389-
*/
1390-
thd->set_db(&dbname);
13911374

13921375
lex_start(thd);
13931376

13941377
#ifndef NO_EMBEDDED_ACCESS_CHECKS
1395-
if (event_sctx.change_security_context(thd,
1396-
&definer_user, &definer_host,
1397-
&dbname, &save_sctx))
1378+
if (event_sctx.change_security_context(thd, &definer_user, &definer_host,
1379+
&dbname, &save_sctx) ||
1380+
mysql_change_db(thd, &dbname, false))
13981381
{
13991382
sql_print_error("Event Scheduler: "
14001383
"[%s].[%s.%s] execution failed, "

0 commit comments

Comments
 (0)