Commit 8d22c5f3 authored by 's avatar

Bug #50095 Multi statement including CREATE EVENT causes rotten binlog entry

The log event of 'CREATE EVENT' was being binlogged with garbage
at the end of the query if 'CREATE EVENT' is followed by another SQL statement
and they were executed as one command.
for example:
    DELIMITER |;
    CREATE EVENT e1 ON EVERY DAY DO SELECT 1; SELECT 'a';
    DELIMITER ;|
When binlogging 'CREATE EVENT', we always create a new statement with definer
and write it into the log event. The new statement is made from cpp_buf(preprocessed buffer).
which is not a c string(end with '\0'), but it is copied as a c string.

In this patch, cpp_buf is copied with its length.
parent 8620be47
......@@ -208,8 +208,14 @@ CREATE /*!50000 DEFINER='user44331' */ EVENT event44331_4
ON SCHEDULE AT CURRENT_TIMESTAMP
ON COMPLETION PRESERVE DISABLE
DO INSERT INTO test.t1 VALUES('event event44331_4 fired - DEFINER=user1');
Warnings:
Note 1449 The user specified as a definer ('user44331'@'%') does not exist
# Test for bug#50095 Multi-statement including CREATE EVENT causes rotten
# binlog entry
SELECT 'ABC';
SELECT '123'|
ABC
ABC
123
123
#on master
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
where EVENT_NAME='event44331_1';
......
......@@ -69,10 +69,16 @@ CREATE DEFINER=CURRENT_USER() EVENT event44331_3
ON COMPLETION PRESERVE DISABLE
DO INSERT INTO test.t1 VALUES('event event44331_3 fired - DEFINER=CURRENT_USER() function');
DELIMITER |;
CREATE /*!50000 DEFINER='user44331' */ EVENT event44331_4
ON SCHEDULE AT CURRENT_TIMESTAMP
ON COMPLETION PRESERVE DISABLE
DO INSERT INTO test.t1 VALUES('event event44331_4 fired - DEFINER=user1');
# Test for bug#50095 Multi-statement including CREATE EVENT causes rotten
# binlog entry
SELECT 'ABC';
SELECT '123'|
DELIMITER ;|
--echo #on master
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
......
......@@ -362,7 +362,9 @@ create_query_string(THD *thd, String *buf)
/* Append definer */
append_definer(thd, buf, &(thd->lex->definer->user), &(thd->lex->definer->host));
/* Append the left part of thd->query after "DEFINER" part */
if (buf->append(thd->lex->stmt_definition_begin))
if (buf->append(thd->lex->stmt_definition_begin,
thd->lex->stmt_definition_end -
thd->lex->stmt_definition_begin))
return 1;
return 0;
......
......@@ -1729,6 +1729,7 @@ typedef struct st_lex : public Query_tables_list
- CREATE TRIGGER (points to "TRIGGER");
- CREATE PROCEDURE (points to "PROCEDURE");
- CREATE FUNCTION (points to "FUNCTION" or "AGGREGATE");
- CREATE EVENT (points to "EVENT")
This pointer is required to add possibly omitted DEFINER-clause to the
DDL-statement before dumping it to the binlog.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment