Skip to content

Commit 90f2c82

Browse files
author
Alexey Botchkov
committed
MDEV-7817 ALTER TABLE {ADD|DROP} INDEX IF [NOT] EXISTS does not get written into binlog if nothing to do.
Just log the ALTER statement even if there's nothing to do.
1 parent 3c47809 commit 90f2c82

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

mysql-test/r/create_drop_binlog.result

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,48 @@ RESET MASTER;
345345
SHOW MASTER STATUS;
346346
File Position Binlog_Do_DB Binlog_Ignore_DB
347347
master-bin.000001 <pos>
348+
CREATE TABLE t1(a INT, b INT);
349+
CREATE TABLE IF NOT EXISTS t1(a INT, b INT);
350+
Warnings:
351+
Note 1050 Table 't1' already exists
352+
CREATE INDEX IF NOT EXISTS i1 ON t1(a);
353+
CREATE INDEX IF NOT EXISTS i1 ON t1(a);
354+
Warnings:
355+
Note 1061 Duplicate key name 'i1'
356+
SHOW CREATE TABLE t1;
357+
Table Create Table
358+
t1 CREATE TABLE `t1` (
359+
`a` int(11) DEFAULT NULL,
360+
`b` int(11) DEFAULT NULL,
361+
KEY `i1` (`a`)
362+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
363+
DROP INDEX IF EXISTS i1 ON t1;
364+
DROP INDEX IF EXISTS i1 ON t1;
365+
Warnings:
366+
Note 1091 Can't DROP 'i1'; check that column/key exists
367+
DROP TABLE t1;
368+
DROP TABLE IF EXISTS t1;
369+
Warnings:
370+
Note 1051 Unknown table 'test.t1'
371+
SHOW BINLOG EVENTS;
372+
Log_name Pos Event_type Server_id End_log_pos Info
373+
# # Format_desc 1 # VER
374+
# # Gtid_list 1 # []
375+
# # Binlog_checkpoint 1 # master-bin.000001
376+
# # Gtid 1 # GTID #-#-#
377+
# # Query 1 # use `test`; CREATE TABLE t1(a INT, b INT)
378+
# # Gtid 1 # GTID #-#-#
379+
# # Query 1 # use `test`; CREATE TABLE IF NOT EXISTS t1(a INT, b INT)
380+
# # Gtid 1 # GTID #-#-#
381+
# # Query 1 # use `test`; CREATE INDEX IF NOT EXISTS i1 ON t1(a)
382+
# # Gtid 1 # GTID #-#-#
383+
# # Query 1 # use `test`; CREATE INDEX IF NOT EXISTS i1 ON t1(a)
384+
# # Gtid 1 # GTID #-#-#
385+
# # Query 1 # use `test`; DROP INDEX IF EXISTS i1 ON t1
386+
# # Gtid 1 # GTID #-#-#
387+
# # Query 1 # use `test`; DROP INDEX IF EXISTS i1 ON t1
388+
# # Gtid 1 # GTID #-#-#
389+
# # Query 1 # use `test`; DROP TABLE `t1` /* generated by server */
390+
# # Gtid 1 # GTID #-#-#
391+
# # Query 1 # use `test`; DROP TABLE IF EXISTS `t1` /* generated by server */
392+
RESET MASTER;

mysql-test/t/create_drop_binlog.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,22 @@ SHOW MASTER STATUS;
175175
RESET MASTER;
176176
--replace_result $pos <pos>
177177
SHOW MASTER STATUS;
178+
179+
#
180+
# mdev-7817 ALTER TABLE {ADD|DROP} INDEX IF [NOT] EXISTS does not get written into binlog if nothing to do
181+
#
182+
183+
CREATE TABLE t1(a INT, b INT);
184+
CREATE TABLE IF NOT EXISTS t1(a INT, b INT);
185+
CREATE INDEX IF NOT EXISTS i1 ON t1(a);
186+
CREATE INDEX IF NOT EXISTS i1 ON t1(a);
187+
SHOW CREATE TABLE t1;
188+
DROP INDEX IF EXISTS i1 ON t1;
189+
DROP INDEX IF EXISTS i1 ON t1;
190+
DROP TABLE t1;
191+
DROP TABLE IF EXISTS t1;
192+
--replace_column 1 # 2 # 5 #
193+
--replace_regex /xid=[0-9]+/xid=XX/ /GTID [0-9]+-[0-9]+-[0-9]+/GTID #-#-#/ /Server.ver.*/VER/
194+
SHOW BINLOG EVENTS;
195+
RESET MASTER;
196+

sql/sql_table.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8484,6 +8484,10 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
84848484
ER_THD(thd, ER_INSERT_INFO), 0L, 0L,
84858485
thd->get_stmt_da()->current_statement_warn_count());
84868486
my_ok(thd, 0L, 0L, alter_ctx.tmp_name);
8487+
8488+
if (write_bin_log(thd, true, thd->query(), thd->query_length()))
8489+
DBUG_RETURN(true);
8490+
84878491
DBUG_RETURN(false);
84888492
}
84898493

0 commit comments

Comments
 (0)