mirror of
https://github.com/MariaDB/server.git
synced 2025-11-28 17:36:30 +03:00
MDEV-21605 Clean up and speed up interfaces for binary row logging MDEV-21617 Bug fix for previous version of this code The intention is to have as few 'if' as possible in ha_write() and related functions. This is done by pre-calculating once per statement the row_logging state for all tables. Benefits are simpler and faster code both when binary logging is disabled and when it's enabled. Changes: - Added handler->row_logging to make it easy to check it table should be row logged. This also made it easier to disabling row logging for system, internal and temporary tables. - The tables row_logging capabilities are checked once per "statements that updates tables" in THD::binlog_prepare_for_row_logging() which is called when needed from THD::decide_logging_format(). - Removed most usage of tmp_disable_binlog(), reenable_binlog() and temporary saving and setting of thd->variables.option_bits. - Moved checks that can't change during a statement from check_table_binlog_row_based() to check_table_binlog_row_based_internal() - Removed flag row_already_logged (used by sequence engine) - Moved binlog_log_row() to a handler:: - Moved write_locked_table_maps() to THD::binlog_write_table_maps() as most other related binlog functions are in THD. - Removed binlog_write_table_map() and binlog_log_row_internal() as they are now obsolete as 'has_transactions()' is pre-calculated in prepare_for_row_logging(). - Remove 'is_transactional' argument from binlog_write_table_map() as this can now be read from handler. - Changed order of 'if's in handler::external_lock() and wsrep_mysqld.h to first evaluate fast and likely cases before more complex ones. - Added error checking in ha_write_row() and related functions if binlog_log_row() failed. - Don't clear check_table_binlog_row_based_result in clear_cached_table_binlog_row_based_flag() as it's not needed. - THD::clear_binlog_table_maps() has been replaced with THD::reset_binlog_for_next_statement() - Added 'MYSQL_OPEN_IGNORE_LOGGING_FORMAT' flag to open_and_lock_tables() to avoid calculating of binary log format for internal opens. This flag is also used to avoid reading statistics tables for internal tables. - Added OPTION_BINLOG_LOG_OFF as a simple way to turn of binlog temporary for create (instead of using THD::sql_log_bin_off. - Removed flag THD::sql_log_bin_off (not needed anymore) - Speed up THD::decide_logging_format() by remembering if blackhole engine is used and avoid a loop over all tables if it's not used (the common case). - THD::decide_logging_format() is not called anymore if no tables are used for the statement. This will speed up pure stored procedure code with about 5%+ according to some simple tests. - We now get annotated events on slave if a CREATE ... SELECT statement is transformed on the slave from statement to row logging. - In the original code, the master could come into a state where row logging is enforced for all future events if statement could be used. This is now partly fixed. Other changes: - Ensure that all tables used by a statement has query_id set. - Had to restore the row_logging flag for not used tables in THD::binlog_write_table_maps (not normal scenario) - Removed injector::transaction::use_table(server_id_type sid, table tbl) as it's not used. - Cleaned up set_slave_thread_options() - Some more DBUG_ENTER/DBUG_RETURN, code comments and minor indentation changes. - Ensure we only call THD::decide_logging_format_low() once in mysql_insert() (inefficiency). - Don't annotate INSERT DELAYED - Removed zeroing pos_in_table_list in THD::open_temporary_table() as it's already 0
228 lines
5.7 KiB
PHP
228 lines
5.7 KiB
PHP
# Test CREATE OR REPLACE TABLE in replication
|
|
--source include/have_innodb.inc
|
|
|
|
--let $rpl_topology=1->2
|
|
--source include/rpl_init.inc
|
|
|
|
# Create help tables
|
|
create table t2 (a int) engine=myisam;
|
|
insert into t2 values (0),(1),(2),(2);
|
|
create temporary table t3 (a_in_temporary int) engine=myisam;
|
|
|
|
--echo #
|
|
--echo # Check how create table and create or replace table are logged
|
|
--echo #
|
|
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
create table t1 (to_be_deleted int);
|
|
|
|
connection server_1;
|
|
CREATE TABLE t1 AS SELECT 1 AS f1;
|
|
CREATE OR REPLACE TABLE t1 AS SELECT 2 AS f1;
|
|
CREATE OR REPLACE table t1 like t2;
|
|
CREATE OR REPLACE table t1 like t3;
|
|
drop table t1;
|
|
|
|
--echo binlog from server 1
|
|
--source include/show_binlog_events.inc
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
--echo binlog from server 2
|
|
--source include/show_binlog_events.inc
|
|
|
|
connection server_1;
|
|
|
|
--echo #
|
|
--echo # Ensure that also failed create_or_replace are logged
|
|
--echo #
|
|
|
|
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
|
|
|
|
create table t1 (a int);
|
|
--error ER_TABLE_MUST_HAVE_COLUMNS
|
|
create or replace table t1;
|
|
drop table if exists t1;
|
|
# The following is not logged as t1 does not exists;
|
|
--error ER_DUP_ENTRY
|
|
create or replace table t1 (a int primary key) select a from t2;
|
|
|
|
create table t1 (a int);
|
|
# This should as a delete as we will delete t1
|
|
--error ER_DUP_ENTRY
|
|
create or replace table t1 (a int primary key) select a from t2;
|
|
|
|
# Same with temporary table
|
|
create temporary table t9 (a int);
|
|
|
|
--error ER_DUP_ENTRY
|
|
create or replace temporary table t9 (a int primary key) select a from t2;
|
|
|
|
--echo binlog from server 1
|
|
--source include/show_binlog_events.inc
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
show tables;
|
|
connection server_1;
|
|
|
|
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
|
|
create table t1 (a int);
|
|
--error ER_DUP_FIELDNAME
|
|
create or replace table t1 (a int, a int) select * from t2;
|
|
--source include/show_binlog_events.inc
|
|
|
|
drop table if exists t1,t2;
|
|
drop temporary table if exists t9;
|
|
|
|
--echo #
|
|
--echo # Ensure that CREATE are run as CREATE OR REPLACE on slave
|
|
--echo #
|
|
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
create table t1 (server_2_to_be_delete int);
|
|
connection server_1;
|
|
create table t1 (new_table int);
|
|
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
|
|
show create table t1;
|
|
connection server_1;
|
|
drop table t1;
|
|
|
|
--echo #
|
|
--echo # Check how CREATE is logged on slave in case of conflicts
|
|
--echo #
|
|
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
|
|
create table t1 (server_2_to_be_delete int);
|
|
create table t2 (server_2_to_be_delete int);
|
|
create table t4 (server_2_to_be_delete int);
|
|
set @org_binlog_format=@@binlog_format;
|
|
set @@global.binlog_format="ROW";
|
|
stop slave;
|
|
--source include/wait_for_slave_to_stop.inc
|
|
start slave;
|
|
--source include/wait_for_slave_to_start.inc
|
|
connection server_1;
|
|
create temporary table t9 (a int);
|
|
insert into t9 values(1);
|
|
create table t1 (new_table int);
|
|
create table t2 select * from t9;
|
|
create table t4 like t9;
|
|
create table t5 select * from t9;
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
--echo binlog from server 2
|
|
--source include/show_binlog_events.inc
|
|
set @@global.binlog_format=@org_binlog_format;
|
|
stop slave;
|
|
--source include/wait_for_slave_to_stop.inc
|
|
start slave;
|
|
--source include/wait_for_slave_to_start.inc
|
|
connection server_1;
|
|
drop table t1,t2,t4,t5,t9;
|
|
|
|
--echo #
|
|
--echo # Ensure that DROP TABLE is run as DROP IF NOT EXISTS
|
|
--echo #
|
|
|
|
create table t1 (server_1_ver_1 int);
|
|
create table t4 (server_1_ver_2 int);
|
|
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
|
|
|
|
# Drop the table on the slave
|
|
drop table t1;
|
|
connection server_1;
|
|
drop table t1,t4;
|
|
create table t1 (server_2_ver_2 int);
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
show create table t1;
|
|
--echo binlog from server 2
|
|
--source include/show_binlog_events.inc
|
|
connection server_1;
|
|
drop table t1;
|
|
|
|
--echo #
|
|
--echo # Ensure that CREATE ... SELECT is recorded as one GTID on the slave
|
|
--echo #
|
|
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
|
|
connection server_1;
|
|
|
|
create table t1 (a int);
|
|
insert into t1 values (0),(1),(2);
|
|
create table t2 engine=myisam select * from t1;
|
|
create or replace table t2 engine=innodb select * from t1;
|
|
save_master_pos;
|
|
connection server_2;
|
|
sync_with_master;
|
|
--echo binlog from server 2
|
|
--source include/show_binlog_events.inc
|
|
connection server_1;
|
|
drop table t1;
|
|
|
|
--echo #
|
|
--echo # Check logging of drop temporary table
|
|
--echo #
|
|
|
|
drop temporary table t3;
|
|
|
|
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
|
|
|
|
set @org_binlog_format=@@binlog_format;
|
|
set binlog_format="STATEMENT";
|
|
create temporary table t5 (a int);
|
|
drop temporary table t5;
|
|
set binlog_format="ROW";
|
|
create temporary table t6 (a int);
|
|
drop temporary table t6;
|
|
set binlog_format="STATEMENT";
|
|
create temporary table t7 (a int);
|
|
set binlog_format="ROW";
|
|
drop temporary table t7;
|
|
create temporary table t8 (a int);
|
|
--error ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR
|
|
set binlog_format="STATEMENT";
|
|
drop temporary table t8;
|
|
set @@binlog_format=@org_binlog_format;
|
|
|
|
# MDEV-20091:
|
|
# 1. No DROP should be logged for non-existing tmp table, nor
|
|
# 2. at the connection close when its creation has not been logged.
|
|
set @@session.binlog_format=default;
|
|
drop temporary table if exists t9;
|
|
|
|
--connect(con1,localhost,root,,)
|
|
set session binlog_format=default;
|
|
create temporary table t9 (i int);
|
|
--echo *** Must be no DROP logged for t9 when there was no CREATE, at disconnect too ***
|
|
--disconnect con1
|
|
|
|
--connection server_1
|
|
--source include/show_binlog_events.inc
|
|
|
|
# Clean up
|
|
drop table t2;
|
|
|
|
--source include/rpl_end.inc
|