Commit 9705ad5e authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-340 Save replication comments for DROP TABLE.

      mysql_rm_table_no_locks() function was modified.
      When we construct log record for the DROP TABLE, now we
      look if there's a comment before the first table name and
      add it to the record if so.
  
per-file comments:
  sql/sql_table.cc
  MDEV-340 Save replication comments for DROP TABLE.
        comment_length() function implemented to find comments in the query,
        call it in mysql_rm_table_no_locks() and use the result to form log record.
  mysql-test/suite/binlog/r/binlog_drop_if_exists.result
  MDEV-340 Save replication comments for DROP TABLE.
        test result updated.
  mysql-test/suite/binlog/t/binlog_drop_if_exists.test
  MDEV-340 Save replication comments for DROP TABLE.
        test case added.
parent 7368ef56
......@@ -96,3 +96,21 @@ master-bin.000001 # Query # # use `test`; DROP VIEW IF EXISTS db_bug_13684.v
master-bin.000001 # Query # # use `test`; DROP EVENT IF EXISTS db_bug_13684.e
master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS `db_bug_13684`.`t` /* generated by server */
master-bin.000001 # Query # # DROP DATABASE IF EXISTS db_bug_13684
CREATE TABLE t1(id int);
DROP TABLE /* comment */ t1;
CREATE TABLE t1(id int);
DROP TABLE IF EXISTS /* comment */ t1;
CREATE TABLE t1(id int);
DROP TABLE /**/ t1;
CREATE TABLE t1(id int);
DROP TABLE IF EXISTS /* */ t1;
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # use `test`; CREATE TABLE t1(id int)
master-bin.000001 # Query # # use `test`; DROP TABLE /* comment */ `t1` /* generated by server */
master-bin.000001 # Query # # use `test`; CREATE TABLE t1(id int)
master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS /* comment */ `t1` /* generated by server */
master-bin.000001 # Query # # use `test`; CREATE TABLE t1(id int)
master-bin.000001 # Query # # use `test`; DROP TABLE /**/ `t1` /* generated by server */
master-bin.000001 # Query # # use `test`; CREATE TABLE t1(id int)
master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS /* */ `t1` /* generated by server */
......@@ -113,3 +113,18 @@ if($fixed_bug_25705)
--source include/show_binlog_events.inc
enable_warnings;
# Drop comments in binlog
let $binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
CREATE TABLE t1(id int);
DROP TABLE /* comment */ t1;
CREATE TABLE t1(id int);
DROP TABLE IF EXISTS /* comment */ t1;
CREATE TABLE t1(id int);
DROP TABLE /**/ t1;
CREATE TABLE t1(id int);
DROP TABLE IF EXISTS /* */ t1;
--source include/show_binlog_events.inc
......@@ -1943,6 +1943,49 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
}
/**
Find the comment in the query.
That's auxiliary function to be used handling DROP TABLE [comment].
@param thd Thread handler
@param comment_pos How many characters to skip before the comment.
Can be either 9 for DROP TABLE or
17 for DROP TABLE IF EXISTS
@param comment_start returns the beginning of the comment if found.
@retval 0 no comment found
@retval >0 the lenght of the comment found
*/
static uint32 comment_length(THD *thd, uint32 comment_pos,
const char **comment_start)
{
const char *query= thd->query();
const char *query_end= query + thd->query_length();
const uchar *const state_map= thd->charset()->state_map;
for (; query < query_end; query++)
{
if (state_map[*query] == MY_LEX_SKIP)
continue;
if (comment_pos-- == 0)
break;
}
if (query > query_end - 3 /* comment can't be shorter than 4 */ ||
state_map[*query] != MY_LEX_LONG_COMMENT || query[1] != '*')
return 0;
*comment_start= query;
for (query+= 3; query < query_end; query++)
{
if (query[-1] == '*' && query[0] == '/')
return query - *comment_start + 1;
}
return 0;
}
/**
Execute the drop of a normal or temporary table.
......@@ -2018,11 +2061,20 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
{
if (!drop_temporary)
{
const char *comment_start;
uint32 comment_len;
built_query.set_charset(system_charset_info);
if (if_exists)
built_query.append("DROP TABLE IF EXISTS ");
else
built_query.append("DROP TABLE ");
if ((comment_len= comment_length(thd, if_exists ? 17:9, &comment_start)))
{
built_query.append(comment_start, comment_len);
built_query.append(" ");
}
}
if (thd->is_current_stmt_binlog_format_row() || if_exists)
......
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