Commit ff36e9fc authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-485.

RBR should be turned off when statistical tables are modified 
in the result of the execution of a DDL statement.
Revised the fix for bug mdev-463. Ensured suppression of RBR
for the modifications of the statistical tables triggered
by the execution of any analyze operation.
parent 8c131f12
......@@ -8,3 +8,18 @@ Table Op Msg_type Msg_text
test.t1 analyze status OK
DROP TABLE t1;
SET GLOBAL use_stat_tables = DEFAULT;
SET use_stat_tables = PREFERABLY;
CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2;
ALTER TABLE t1 ANALYZE PARTITION p1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
SHOW BINLOG EVENTS;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 4 Format_desc 1 245 Server ver: 5.5.27-MariaDB-debug-log, Binlog ver: 4
master-bin.000001 245 Query 1 345 use `test`; CREATE TABLE t1 (i INT) ENGINE=InnoDB
master-bin.000001 345 Query 1 424 use `test`; ANALYZE TABLE t1
master-bin.000001 424 Query 1 528 use `test`; DROP TABLE `t1` /* generated by server */
master-bin.000001 528 Query 1 664 use `test`; CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2
master-bin.000001 664 Query 1 762 use `test`; ALTER TABLE t1 ANALYZE PARTITION p1
SET use_stat_tables = DEFAULT;
DROP TABLE t1;
include/master-slave.inc
[connection master]
#
# Bug mdev-485: unexpected failure with replication of DROP/ALTER table
# when RBR is on
#
CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
DROP INDEX idx1 ON t1;
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
ALTER TABLE t1 DROP COLUMN b;
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
ALTER TABLE t1 RENAME to s;
DROP TABLE s;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
ALTER TABLE t1 CHANGE COLUMN b c int ;
DROP TABLE t1;
include/rpl_end.inc
--source include/have_binlog_format_row.inc
--source include/have_innodb.inc
--source include/have_partition.inc
--echo #
--echo # Bug mdev-463: assertion failure when running ANALYZE with RBR on
......@@ -16,3 +17,14 @@ DROP TABLE t1;
SET GLOBAL use_stat_tables = DEFAULT;
--disconnect con1
--connection default
SET use_stat_tables = PREFERABLY;
CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2;
ALTER TABLE t1 ANALYZE PARTITION p1;
SHOW BINLOG EVENTS;
SET use_stat_tables = DEFAULT;
DROP TABLE t1;
--source include/have_stat_tables.inc
--source include/master-slave.inc
--source include/have_binlog_format_row.inc
--echo #
--echo # Bug mdev-485: unexpected failure with replication of DROP/ALTER table
--echo # when RBR is on
--echo #
CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
DROP TABLE t1;
--sync_slave_with_master
--connection master
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
DROP INDEX idx1 ON t1;
--sync_slave_with_master
--connection master
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
ALTER TABLE t1 DROP COLUMN b;
--sync_slave_with_master
--connection master
DROP TABLE t1;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
ALTER TABLE t1 RENAME to s;
--sync_slave_with_master
--connection master
DROP TABLE s;
CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM;
INSERT INTO t1 VALUES (2,20), (1,20), (3,30);
ANALYZE TABLE t1;
ALTER TABLE t1 CHANGE COLUMN b c int ;
--sync_slave_with_master
--connection master
DROP TABLE t1;
--source include/rpl_end.inc
......@@ -323,7 +323,6 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
int result_code;
int compl_result_code;
bool need_repair_or_alter= 0;
bool save_binlog_row_based= 0;
DBUG_ENTER("mysql_admin_table");
DBUG_PRINT("enter", ("extra_open_options: %u", extra_open_options));
......@@ -418,11 +417,6 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
*/
open_error= open_and_lock_tables(thd, table, TRUE, 0);
if (lex->sql_command == SQLCOM_ANALYZE)
{
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
thd->clear_current_stmt_binlog_format_row();
}
}
thd->prepare_derived_at_open= FALSE;
......@@ -962,8 +956,6 @@ send_result_message:
trans_commit_stmt(thd);
trans_commit_implicit(thd);
close_thread_tables(thd);
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
thd->mdl_context.release_transactional_locks();
/*
......@@ -996,8 +988,6 @@ err:
trans_rollback_stmt(thd);
trans_rollback(thd);
close_thread_tables(thd); // Shouldn't be needed
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
thd->mdl_context.release_transactional_locks();
if (table)
table->table=0;
......
......@@ -2171,6 +2171,7 @@ int update_statistics_for_table(THD *thd, TABLE *table)
Open_tables_backup open_tables_backup;
uint i;
int err;
bool save_binlog_row_based;
int rc= 0;
TABLE *stat_table;
......@@ -2187,6 +2188,9 @@ int update_statistics_for_table(THD *thd, TABLE *table)
DBUG_RETURN(rc);
}
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
thd->clear_current_stmt_binlog_format_row();
/* Update the statistical table table_stat */
stat_table= tables[TABLE_STAT].table;
Table_stat table_stat(stat_table, table);
......@@ -2231,6 +2235,9 @@ int update_statistics_for_table(THD *thd, TABLE *table)
}
}
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
close_system_tables(thd, &open_tables_backup);
DBUG_RETURN(rc);
......@@ -2510,6 +2517,7 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables)
int delete_statistics_for_table(THD *thd, LEX_STRING *db, LEX_STRING *tab)
{
int err;
bool save_binlog_row_based;
TABLE *stat_table;
TABLE_LIST tables[STATISTICS_TABLES];
Open_tables_backup open_tables_backup;
......@@ -2528,6 +2536,9 @@ int delete_statistics_for_table(THD *thd, LEX_STRING *db, LEX_STRING *tab)
DBUG_RETURN(rc);
}
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
thd->clear_current_stmt_binlog_format_row();
/* Delete statistics on table from the statistical table index_stat */
stat_table= tables[INDEX_STAT].table;
Index_stat index_stat(stat_table, db, tab);
......@@ -2561,6 +2572,9 @@ int delete_statistics_for_table(THD *thd, LEX_STRING *db, LEX_STRING *tab)
rc= 1;
}
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
close_system_tables(thd, &open_tables_backup);
DBUG_RETURN(rc);
......@@ -2595,6 +2609,7 @@ int delete_statistics_for_table(THD *thd, LEX_STRING *db, LEX_STRING *tab)
int delete_statistics_for_column(THD *thd, TABLE *tab, Field *col)
{
int err;
bool save_binlog_row_based;
TABLE *stat_table;
TABLE_LIST tables;
Open_tables_backup open_tables_backup;
......@@ -2613,6 +2628,9 @@ int delete_statistics_for_column(THD *thd, TABLE *tab, Field *col)
DBUG_RETURN(rc);
}
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
thd->clear_current_stmt_binlog_format_row();
stat_table= tables.table;
Column_stat column_stat(stat_table, tab);
column_stat.set_key_fields(col);
......@@ -2623,6 +2641,9 @@ int delete_statistics_for_column(THD *thd, TABLE *tab, Field *col)
rc= 1;
}
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
close_system_tables(thd, &open_tables_backup);
DBUG_RETURN(rc);
......@@ -2657,6 +2678,7 @@ int delete_statistics_for_column(THD *thd, TABLE *tab, Field *col)
int delete_statistics_for_index(THD *thd, TABLE *tab, KEY *key_info)
{
int err;
bool save_binlog_row_based;
TABLE *stat_table;
TABLE_LIST tables;
Open_tables_backup open_tables_backup;
......@@ -2675,6 +2697,9 @@ int delete_statistics_for_index(THD *thd, TABLE *tab, KEY *key_info)
DBUG_RETURN(rc);
}
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
thd->clear_current_stmt_binlog_format_row();
stat_table= tables.table;
Index_stat index_stat(stat_table, tab);
index_stat.set_index_prefix_key_fields(key_info);
......@@ -2685,6 +2710,9 @@ int delete_statistics_for_index(THD *thd, TABLE *tab, KEY *key_info)
rc= 1;
}
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
close_system_tables(thd, &open_tables_backup);
DBUG_RETURN(rc);
......@@ -2722,6 +2750,7 @@ int rename_table_in_stat_tables(THD *thd, LEX_STRING *db, LEX_STRING *tab,
LEX_STRING *new_db, LEX_STRING *new_tab)
{
int err;
bool save_binlog_row_based;
TABLE *stat_table;
TABLE_LIST tables[STATISTICS_TABLES];
Open_tables_backup open_tables_backup;
......@@ -2740,6 +2769,9 @@ int rename_table_in_stat_tables(THD *thd, LEX_STRING *db, LEX_STRING *tab,
DBUG_RETURN(rc);
}
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
thd->clear_current_stmt_binlog_format_row();
/* Rename table in the statistical table index_stat */
stat_table= tables[INDEX_STAT].table;
Index_stat index_stat(stat_table, db, tab);
......@@ -2775,6 +2807,9 @@ int rename_table_in_stat_tables(THD *thd, LEX_STRING *db, LEX_STRING *tab,
rc= 1;
}
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
close_system_tables(thd, &open_tables_backup);
DBUG_RETURN(rc);
......@@ -2812,6 +2847,7 @@ int rename_column_in_stat_tables(THD *thd, TABLE *tab, Field *col,
const char *new_name)
{
int err;
bool save_binlog_row_based;
TABLE *stat_table;
TABLE_LIST tables;
Open_tables_backup open_tables_backup;
......@@ -2830,6 +2866,9 @@ int rename_column_in_stat_tables(THD *thd, TABLE *tab, Field *col,
DBUG_RETURN(rc);
}
if ((save_binlog_row_based= thd->is_current_stmt_binlog_format_row()))
thd->clear_current_stmt_binlog_format_row();
/* Rename column in the statistical table table_stat */
stat_table= tables.table;
Column_stat column_stat(stat_table, tab);
......@@ -2840,6 +2879,10 @@ int rename_column_in_stat_tables(THD *thd, TABLE *tab, Field *col,
if (err & !rc)
rc= 1;
}
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
close_system_tables(thd, &open_tables_backup);
DBUG_RETURN(rc);
......
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