Skip to content

Commit

Permalink
MDEV-7817 ALTER TABLE {ADD|DROP} INDEX IF [NOT] EXISTS does not get w…
Browse files Browse the repository at this point in the history
…ritten into binlog if nothing to do.

Just log the ALTER statement even if there's nothing to do.
  • Loading branch information
Alexey Botchkov committed Oct 5, 2015
1 parent 3c47809 commit 90f2c82
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
45 changes: 45 additions & 0 deletions mysql-test/r/create_drop_binlog.result
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,48 @@ RESET MASTER;
SHOW MASTER STATUS;
File Position Binlog_Do_DB Binlog_Ignore_DB
master-bin.000001 <pos>
CREATE TABLE t1(a INT, b INT);
CREATE TABLE IF NOT EXISTS t1(a INT, b INT);
Warnings:
Note 1050 Table 't1' already exists
CREATE INDEX IF NOT EXISTS i1 ON t1(a);
CREATE INDEX IF NOT EXISTS i1 ON t1(a);
Warnings:
Note 1061 Duplicate key name 'i1'
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `i1` (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP INDEX IF EXISTS i1 ON t1;
DROP INDEX IF EXISTS i1 ON t1;
Warnings:
Note 1091 Can't DROP 'i1'; check that column/key exists
DROP TABLE t1;
DROP TABLE IF EXISTS t1;
Warnings:
Note 1051 Unknown table 'test.t1'
SHOW BINLOG EVENTS;
Log_name Pos Event_type Server_id End_log_pos Info
# # Format_desc 1 # VER
# # Gtid_list 1 # []
# # Binlog_checkpoint 1 # master-bin.000001
# # Gtid 1 # GTID #-#-#
# # Query 1 # use `test`; CREATE TABLE t1(a INT, b INT)
# # Gtid 1 # GTID #-#-#
# # Query 1 # use `test`; CREATE TABLE IF NOT EXISTS t1(a INT, b INT)
# # Gtid 1 # GTID #-#-#
# # Query 1 # use `test`; CREATE INDEX IF NOT EXISTS i1 ON t1(a)
# # Gtid 1 # GTID #-#-#
# # Query 1 # use `test`; CREATE INDEX IF NOT EXISTS i1 ON t1(a)
# # Gtid 1 # GTID #-#-#
# # Query 1 # use `test`; DROP INDEX IF EXISTS i1 ON t1
# # Gtid 1 # GTID #-#-#
# # Query 1 # use `test`; DROP INDEX IF EXISTS i1 ON t1
# # Gtid 1 # GTID #-#-#
# # Query 1 # use `test`; DROP TABLE `t1` /* generated by server */
# # Gtid 1 # GTID #-#-#
# # Query 1 # use `test`; DROP TABLE IF EXISTS `t1` /* generated by server */
RESET MASTER;
19 changes: 19 additions & 0 deletions mysql-test/t/create_drop_binlog.test
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,22 @@ SHOW MASTER STATUS;
RESET MASTER;
--replace_result $pos <pos>
SHOW MASTER STATUS;

#
# mdev-7817 ALTER TABLE {ADD|DROP} INDEX IF [NOT] EXISTS does not get written into binlog if nothing to do
#

CREATE TABLE t1(a INT, b INT);
CREATE TABLE IF NOT EXISTS t1(a INT, b INT);
CREATE INDEX IF NOT EXISTS i1 ON t1(a);
CREATE INDEX IF NOT EXISTS i1 ON t1(a);
SHOW CREATE TABLE t1;
DROP INDEX IF EXISTS i1 ON t1;
DROP INDEX IF EXISTS i1 ON t1;
DROP TABLE t1;
DROP TABLE IF EXISTS t1;
--replace_column 1 # 2 # 5 #
--replace_regex /xid=[0-9]+/xid=XX/ /GTID [0-9]+-[0-9]+-[0-9]+/GTID #-#-#/ /Server.ver.*/VER/
SHOW BINLOG EVENTS;
RESET MASTER;

4 changes: 4 additions & 0 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8484,6 +8484,10 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
ER_THD(thd, ER_INSERT_INFO), 0L, 0L,
thd->get_stmt_da()->current_statement_warn_count());
my_ok(thd, 0L, 0L, alter_ctx.tmp_name);

if (write_bin_log(thd, true, thd->query(), thd->query_length()))
DBUG_RETURN(true);

DBUG_RETURN(false);
}

Expand Down

0 comments on commit 90f2c82

Please sign in to comment.