mariadb/mysql-test/suite/rpl/include
Monty 603077642e MDEV-36099 Ensure that creation and usage of temporary tables in replication is predictable
The purpose of this commit is to ensure that creation and changes of
temporary tables are properly and predicable logged to the binary
log.  It also fixes some bugs where ROW logging was used in MIXED mode,
when STATEMENT would be a better (and expected) choice.

In this comment STATEMENT stands for logging to binary log in
STATEMENT format, MIXED stands for MIXED binlog format and ROW for ROW
binlog format.

New rules for logging of temporary tables
- CREATE of temporary tables are now by default binlogged only if
  STATEMENT binlog format is used. If it is binlogged, 1 is stored in
  TABLE_SHARE->table_creation_was_logged. The user can change this
  behavior by setting create_temporary_table_binlog_formats to
  MIXED,STATEMENT in which case the create is logged in statement
  format also in MIXED mode (as before).
- Changes to temporary tables are only binlogged if and only if
  the CREATE was logged. The logging happens under STATEMENT or MIXED.
  If binlog_format=ROW, temporary table changes are not binlogged. A
  temporary table that are changed under ROW are marked as 'not up to
  date in binlog' and no future row changes are logged.  Any usage of
  this temporary table will force row logging of other tables in any
  future statements using the temporary table to be row logged.
- DROP TEMPORARY is binlogged only of the CREATE was binlogged.

Changes done:
- Row logging is forced for any statement using temporary tables that
  are not up to date in the binary log.
  (Before the row logging was forced if the user has a temporary table)
- If there is any changes to the temporary table that is not binlogged,
  the table is marked as not up to date.
- TABLE_SHARE->table_creation_was_logged has a new definition for
  temporary tables:
  0  Table creating was not logged to binary log
  1  Table creating was logged to binary log and table is up to date.
  2  Table creating was logged to binary log but some changes where
     not logged to binary log.
  Table is not up to date in binary log is defined as value 0 or 2.
- If a multi-table-update or multi-table-delete fails then
  all updated temporary tables are marked as not up to date.
- Enforce row logging if the query is using temporary tables
  that are not up to date.
  Before row logging was enforced if the user had any
  temporary tables.
- When dropping temporary tables use IF EXISTS. This ensures
  that slave will not stop if it had crashed and lost the
  temporary tables.
- Remove comment and version from DROP /*!4000 TEMPORARY.. generated when
  a connection closes that has open temporary tables. Added 'generated by
  server' at the end of the DROP.

Bugs fixed:
- When using temporary tables with commands that forced row based,
  like INSERT INTO temporary_table VALUES (UUID()), this was never
  logged which causes the temporary table to be inconsistent on
  master and slave.
- Used binlog format is now clearly defined. It is now only depending
  on the current binlog_format and the tables used.
  Before it was depending on the user had ANY temporary tables and
  the state of 'current_stmt_binlog_format' set by previous queries.
  This also caused temporary tables to be logged to binary log in
  some cases.
- CREATE TABLE t1 LIKE not_logged_temporary_table caused replication
  to stop.
- Rename of not binlogged temporary tables where binlogged to binary log
  which caused replication to stop.

Changes in behavior:

- By default create_temporary_table_binlog_formats=STATEMENT, which
  means that CREATE TEMPORARY is not logged to binary log under MIXED
  binary logging. This can be changed by setting
  create_temporary_table_binlog_formats to MIXED,STATEMENT.
- Using temporary tables that was not logged to the binary log will
  cause any query using them for updating other tables to be logged in
  ROW format. Before all queries was logged in ROW format if the user had
  any temporary tables, even if they were not used by the query.
- Generated DROP TEMPORARY TABLE is now always using IF EXISTS and
  has a "generated by server" comment in the binary log.

The consequences of the above is that manipulations of a lot of rows
through temporary tables will by default be be slower in mixed mode.

For example:
  BEGIN;
  CREATE TEMPORARY TABLE tmp AS SELECT a, b, c FROM
  large_table1 JOIN large_table2 ON ...;
  INSERT INTO other_table SELECT b, c FROM tmp WHERE a <100;
  DROP TEMPORARY TABLE tmp;
  COMMIT;

By default this will create a huge entry in the binary log, compared
to just a few hundred bytes in statement mode. However the change in
this commit will make usage of temporary tables more reliable and
predicable and is thus worth it. Using statement mode or
create_temporary_table_binlog_formats can be used to avoid this issue.
2025-03-18 18:27:27 +01:00
..
check_type.inc MDEV-31005: Make working cursor-protocol 2024-09-18 18:39:26 +07:00
create_or_drop_sync_func.inc MDEV-30323 Some DDLs like ANALYZE can complete on parallel slave out of order 2023-01-24 20:18:03 +02:00
create_recursive_construct.inc Merge branch '10.2' into 10.3 2019-03-17 13:06:41 +01:00
delayed_slave_wait_on_query.inc Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
hrtime.inc MDEV-3929 Add system variable explicit_defaults_for_timestamp for compatibility with MySQL 2015-09-22 14:01:54 +04:00
mdev-31448_conservative.inc Merge branch '10.5' into 10.6 2023-12-17 11:20:43 +01:00
mdev-31448_optimistic.inc Merge branch '10.5' into 10.6 2023-12-17 11:20:43 +01:00
multisource.inc MDEV-31857 enable --ssl-verify-server-cert by default in the internal client 2024-02-04 22:19:19 +01:00
mysqlbinlog_slave_consistency.inc Merge branch '10.6' into 10.11 2023-12-18 11:19:04 +01:00
rpl_auto_increment.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_auto_increment_insert_view.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_auto_increment_invoke_trigger.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_autoinc_func_invokes_trigger.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_binlog_max_cache_size.inc MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
rpl_blackhole.test Merge branch '10.2' into 10.3 2019-06-14 07:36:47 +02:00
rpl_blackhole_basic.test Merge branch '10.2' into 10.3 2019-06-14 07:36:47 +02:00
rpl_change_master_demote.inc Merge branch '11.3' into 11.4 2024-02-15 13:53:21 +01:00
rpl_charset.inc MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
rpl_check_table_consistency.inc MDEV-20119: Implement the --do-domain-ids, --ignore-domain-ids, and --ignore-server-ids options for mysqlbinlog 2022-04-19 11:09:24 -06:00
rpl_commit_after_flush.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_conflicts.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_ddl.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_deadlock.test MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based replication is used by default if master supports it 2022-07-26 13:31:27 -06:00
rpl_delete_no_where.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_drop_create_temp_table.inc MDEV-36099 Ensure that creation and usage of temporary tables in replication is predictable 2025-03-18 18:27:27 +01:00
rpl_drop_create_temp_table.test Merge branch '10.2' into 10.3 2021-11-05 19:58:32 +01:00
rpl_EE_err.test Changed FLUSH TABLES to not change share version 2018-12-09 22:12:26 +02:00
rpl_extra_col_master.inc MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
rpl_extra_col_slave.test MDEV-29021 mark fields that have explicit values 2023-08-15 10:16:12 +02:00
rpl_failed_optimize.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_flsh_tbls.test MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based replication is used by default if master supports it 2022-07-26 13:31:27 -06:00
rpl_get_master_version_and_clock.test MDEV-32104 remove deprecated features 2023-09-30 14:43:12 +02:00
rpl_gtid_index.inc MDEV-4991: GTID binlog indexing 2024-01-27 12:09:54 +01:00
rpl_gtid_until_before_after_gtids.test MDEV-27247: Add keywords "SQL_BEFORE_GTIDS" and "SQL_AFTER_GTIDS" for START SLAVE UNTIL 2023-10-23 06:40:05 -06:00
rpl_implicit_commit_binlog.test Merge branch '10.2' into 10.3 2018-05-11 13:15:10 +02:00
rpl_innodb.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_insert_delayed.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_insert_id.test MDEV-31003: Second execution for ps-protocol 2023-07-26 17:15:00 +07:00
rpl_insert_id_pk.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_insert_ignore.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_loaddata.test MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based replication is used by default if master supports it 2022-07-26 13:31:27 -06:00
rpl_loadfile.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_log.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_lower_case_table_names.test Merge 10.2 into 10.3 2018-11-06 09:40:39 +02:00
rpl_max_relay_size.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_mixed_check_db.inc MDEV-6720 - enable connection log in mysqltest by default 2016-03-31 10:11:16 +04:00
rpl_mixed_check_event.inc MDEV-6720 - enable connection log in mysqltest by default 2016-03-31 10:11:16 +04:00
rpl_mixed_check_select.inc MDEV-6720 - enable connection log in mysqltest by default 2016-03-31 10:11:16 +04:00
rpl_mixed_check_table.inc MDEV-6720 - enable connection log in mysqltest by default 2016-03-31 10:11:16 +04:00
rpl_mixed_check_user.inc MDEV-16238 root/localhost authn prioritizes authentication_string over Password 2018-06-21 10:15:27 +02:00
rpl_mixed_check_view.inc MDEV-6720 - enable connection log in mysqltest by default 2016-03-31 10:11:16 +04:00
rpl_mixed_clear_tables.inc copy from test-extra-5.1 to main tree 2007-02-06 13:35:54 +01:00
rpl_mixed_ddl.inc MDEV-6720 - enable connection log in mysqltest by default 2016-03-31 10:11:16 +04:00
rpl_mixed_dml.inc UUID() function should return UUID, not VARCHAR(36) 2021-10-29 18:29:02 +02:00
rpl_mixed_show_binlog_format.inc copy from test-extra-5.1 to main tree 2007-02-06 13:35:54 +01:00
rpl_mixing_engines.inc MDEV-36099 Ensure that creation and usage of temporary tables in replication is predictable 2025-03-18 18:27:27 +01:00
rpl_mixing_engines.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_multi_query.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_multi_update.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_multi_update2.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_multi_update3.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_not_null.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_parallel_29322.inc Merge branch '10.6' into 10.11 2023-12-18 11:19:04 +01:00
rpl_parallel_incorrect_relay_pos.inc MDEV-18648: slave_parallel_mode= optimistic default in 10.5 2019-12-23 17:48:01 +05:30
rpl_partition.inc MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION 2024-12-05 08:17:35 +01:00
rpl_partition.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_record_compare.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_relayrotate.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_reset_slave.test MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based replication is used by default if master supports it 2022-07-26 13:31:27 -06:00
rpl_reset_slave_all_check.inc MDEV-25284: Assertion `info->type == READ_CACHE || info->type == WRITE_CACHE' failed 2021-10-18 10:43:51 -06:00
rpl_row_annotate.test Changed FLUSH TABLES to not change share version 2018-12-09 22:12:26 +02:00
rpl_row_basic.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_row_blob.test MDEV-30985 Replica stops with error on ALTER ONLINE with Geometry Types 2023-08-15 10:16:13 +02:00
rpl_row_delayed_ins.test Changed FLUSH TABLES to not change share version 2018-12-09 22:12:26 +02:00
rpl_row_func003.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_row_img.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_row_img_blobs.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_row_img_sequence.inc MDEV-31003: Second execution for ps-protocol 2023-07-26 17:15:00 +07:00
rpl_row_sp002.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_row_sp003.test MDEV-31003: Second execution for ps-protocol 2023-07-26 17:15:00 +07:00
rpl_row_sp006.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_row_sp007.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_row_tabledefs.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_row_UUID.test MDEV-31003: Second execution for ps-protocol 2023-07-26 17:15:00 +07:00
rpl_set_null.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_set_statement.inc MDEV-6720 - enable connection log in mysqltest by default 2016-03-31 10:11:16 +04:00
rpl_show_binlog_events.inc Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_show_log_events_with_varying_options.inc Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_show_relaylog_events.inc Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_shutdown_wait_slaves.inc MDEV-32168: slave_error_param condition is never checked from the wait_for_slave_param.inc 2023-11-17 19:44:11 +01:00
rpl_slave_max_statement_time.inc MDEV-27161: Add option for SQL thread to limit maximum execution time per query replicated 2022-08-03 20:25:43 +03:00
rpl_start_stop_slave.test Merge branch '10.6' into 10.11 2023-12-18 11:19:04 +01:00
rpl_stm_create_if_not_exists.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_stm_EE_err2.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_stop_middle_group.test MDEV-31005: Make working cursor-protocol 2024-09-18 18:39:26 +07:00
rpl_stop_slave.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_sv_relay_space.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_test_framework.inc Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_tmp_table_and_DDL.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_trig004.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_truncate.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_truncate_helper.test Move mysql-test-run/extra/rpl_tests to suite/rpl/include 2018-03-29 13:59:44 +03:00
rpl_xa_empty_transaction.inc MDEV-25616 XA PREPARE event group is not binlogged when.. 2022-10-25 12:56:33 +03:00
rpl_xa_empty_transaction_test_case.inc MDEV-25616 XA PREPARE event group is not binlogged when.. 2022-10-25 12:56:33 +03:00
rpl_xa_mixed_engines.inc MDEV-742 XA PREPAREd transaction survive disconnect/server restart 2020-03-14 22:45:48 +02:00
sql_multisource.inc MDEV-20119: Implement the --do-domain-ids, --ignore-domain-ids, and --ignore-server-ids options for mysqlbinlog 2022-04-19 11:09:24 -06:00
sql_out_of_order_gtid.inc MDEV-20119: Implement the --do-domain-ids, --ignore-domain-ids, and --ignore-server-ids options for mysqlbinlog 2022-04-19 11:09:24 -06:00
start_alter_basic.inc MDEV-11675 Lag Free Alter On Slave 2022-01-27 21:25:07 +02:00
start_alter_concurrent.inc MDEV-11675 Lag Free Alter On Slave 2022-01-27 21:25:07 +02:00
start_alter_include.inc MDEV-11675 Lag Free Alter On Slave 2022-01-27 21:25:07 +02:00
start_alter_options.inc MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
sync_with_master_sql_delay_debug_sync.inc MDEV-33500 (part 2): rpl.rpl_parallel_sbm can still fail 2024-09-17 06:29:20 -06:00
type_conversions.test Merge 10.2 into 10.3 2018-10-17 19:37:05 +03:00