mariadb/mysql-test/suite/binlog/t/binlog_implicit_commit.test
Mats Kindahl 124e830125 Bug #37221: SET AUTOCOMMIT=1 does not commit binary log
When setting AUTOCOMMIT=1 after starting a transaction, the binary log
did not commit the outstanding transaction. The reason was that the binary
log commit function saw the values of the new settings, deciding that there
were nothing to commit.

Fixed the problem by moving the implicit commit to before the thread option
flags were changed, so that the binary log sees the old values of the flags
instead of the values they will take after the statement.


mysql-test/extra/binlog_tests/implicit.test:
  New test file to check implicit commits both inside and outside transactions.
mysql-test/suite/binlog/t/binlog_implicit_commit.test:
  Test for implicit commit of SET AUTOCOMMIT and LOCK/UNLOCK TABLES.
sql/set_var.cc:
  Adding code to commit pending transaction before changing option flags.
2009-09-23 13:20:48 +02:00

63 lines
1.7 KiB
Text

# The purpose of this test is to test that setting autocommit does a
# commit of outstanding transactions and nothing is left pending in
# the transaction cache.
source include/have_log_bin.inc;
source include/have_innodb.inc;
# We need a transactional engine, so let's use InnoDB
CREATE TABLE t1 (id INT) ENGINE = InnoDB;
# Testing SET AUTOCOMMIT
SET BINLOG_FORMAT = STATEMENT;
let $cleanup = COMMIT;
let $prepare = SET AUTOCOMMIT = 0;
let $statement = SET AUTOCOMMIT = 1;
source extra/binlog_tests/implicit.test;
let $prepare = SET AUTOCOMMIT = 1;
let $statement = SET AUTOCOMMIT = 1;
source extra/binlog_tests/implicit.test;
let $prepare = SET AUTOCOMMIT = 0;
let $statement = SET AUTOCOMMIT = 0;
source extra/binlog_tests/implicit.test;
let $prepare = SET AUTOCOMMIT = 1;
let $statement = SET AUTOCOMMIT = 0;
source extra/binlog_tests/implicit.test;
SET BINLOG_FORMAT = ROW;
let $prepare = SET AUTOCOMMIT = 0;
let $statement = SET AUTOCOMMIT = 1;
source extra/binlog_tests/implicit.test;
let $prepare = SET AUTOCOMMIT = 1;
let $statement = SET AUTOCOMMIT = 1;
source extra/binlog_tests/implicit.test;
let $prepare = SET AUTOCOMMIT = 0;
let $statement = SET AUTOCOMMIT = 0;
source extra/binlog_tests/implicit.test;
let $prepare = SET AUTOCOMMIT = 1;
let $statement = SET AUTOCOMMIT = 0;
source extra/binlog_tests/implicit.test;
RESET MASTER;
SET AUTOCOMMIT = 0;
INSERT INTO t1 VALUES (1);
source include/show_binlog_events.inc;
LOCK TABLES t1 WRITE;
source include/show_binlog_events.inc;
INSERT INTO t1 VALUES (2);
source include/show_binlog_events.inc;
UNLOCK TABLES;
source include/show_binlog_events.inc;
COMMIT;
source include/show_binlog_events.inc;
# Cleaning up
DROP TABLE t1;