diff options
author | Davi Arnaut <Davi.Arnaut@Sun.COM> | 2009-01-09 08:20:32 -0200 |
---|---|---|
committer | Davi Arnaut <Davi.Arnaut@Sun.COM> | 2009-01-09 08:20:32 -0200 |
commit | 577e390eceb06a6c35198d0026c11b47a3d33232 (patch) | |
tree | a733a91258824cd53ed4fd4e4ab04fa2d2a34a68 /mysql-test/t/innodb_mysql.test | |
parent | 2ce96d24eccd183c04adfadbb073e560767959f1 (diff) | |
download | mariadb-git-577e390eceb06a6c35198d0026c11b47a3d33232.tar.gz |
Bug#37016: TRUNCATE TABLE removes some rows but not all
The special TRUNCATE TABLE (DDL) transaction wasn't being properly
rolled back if a error occurred during row by row deletion. The
error can be caused by a foreign key restriction imposed by InnoDB
SE and would cause the server to erroneously issue a implicit
commit.
The solution is to rollback the transaction if a truncation via row
by row deletion fails, otherwise commit. All effects of a TRUNCATE
ABLE operation are rolled back if a row by row deletion fails.
Diffstat (limited to 'mysql-test/t/innodb_mysql.test')
-rw-r--r-- | mysql-test/t/innodb_mysql.test | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test index 5a2e115a98d..21ee440f10b 100644 --- a/mysql-test/t/innodb_mysql.test +++ b/mysql-test/t/innodb_mysql.test @@ -132,4 +132,56 @@ DEALLOCATE PREPARE stmt3; DROP TABLE t1,t3,t2; DROP FUNCTION f1; +# +# Bug#37016: TRUNCATE TABLE removes some rows but not all +# + +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB; +CREATE TABLE t2 (id INT PRIMARY KEY, + t1_id INT, INDEX par_ind (t1_id), + FOREIGN KEY (t1_id) REFERENCES t1(id)) ENGINE=INNODB; +INSERT INTO t1 VALUES (1),(2); +INSERT INTO t2 VALUES (3,2); + +SET AUTOCOMMIT = 0; + +START TRANSACTION; +--error ER_ROW_IS_REFERENCED_2 +TRUNCATE TABLE t1; +SELECT * FROM t1; +COMMIT; +SELECT * FROM t1; + +START TRANSACTION; +--error ER_ROW_IS_REFERENCED_2 +TRUNCATE TABLE t1; +SELECT * FROM t1; +ROLLBACK; +SELECT * FROM t1; + +SET AUTOCOMMIT = 1; + +START TRANSACTION; +SELECT * FROM t1; +COMMIT; + +--error ER_ROW_IS_REFERENCED_2 +TRUNCATE TABLE t1; +SELECT * FROM t1; +DELETE FROM t2 WHERE id = 3; + +START TRANSACTION; +SELECT * FROM t1; +TRUNCATE TABLE t1; +ROLLBACK; +SELECT * FROM t1; +TRUNCATE TABLE t2; + +DROP TABLE t2; +DROP TABLE t1; + --echo End of 5.1 tests |