summaryrefslogtreecommitdiff
path: root/mysql-test/r/innodb_mysql.result
diff options
context:
space:
mode:
authorDavi Arnaut <Davi.Arnaut@Sun.COM>2009-01-09 08:20:32 -0200
committerDavi Arnaut <Davi.Arnaut@Sun.COM>2009-01-09 08:20:32 -0200
commit8dbb9c885d42fd03b997a507d10620c1a55fa44d (patch)
treea733a91258824cd53ed4fd4e4ab04fa2d2a34a68 /mysql-test/r/innodb_mysql.result
parente35fc57bd30473be8bad038f53b34302a4d2e724 (diff)
downloadmariadb-git-8dbb9c885d42fd03b997a507d10620c1a55fa44d.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. mysql-test/include/commit.inc: Truncate always starts a transaction and commits at the end. The commit at the end increases the count by two, one is the storage engine commit and the other is the binary log. mysql-test/r/commit_1innodb.result: Update test case results. mysql-test/r/innodb_mysql.result: Update test case results. mysql-test/t/innodb_mysql.test: Add test case for Bug#37016 sql/sql_delete.cc: Move truncation using row by row deletion to its own function. If row by row deletion fails, rollback the transaction. Remove the meddling with disabling and enabling of autocommit as TRUNCATE transaction is now explicitly ended (committed or rolled back).
Diffstat (limited to 'mysql-test/r/innodb_mysql.result')
-rw-r--r--mysql-test/r/innodb_mysql.result58
1 files changed, 58 insertions, 0 deletions
diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result
index a1116a78bda..6fcc9415d12 100644
--- a/mysql-test/r/innodb_mysql.result
+++ b/mysql-test/r/innodb_mysql.result
@@ -1788,4 +1788,62 @@ DEALLOCATE PREPARE stmt1;
DEALLOCATE PREPARE stmt3;
DROP TABLE t1,t3,t2;
DROP FUNCTION f1;
+DROP TABLE IF EXISTS t1,t2;
+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;
+TRUNCATE TABLE t1;
+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`))
+SELECT * FROM t1;
+id
+1
+2
+COMMIT;
+SELECT * FROM t1;
+id
+1
+2
+START TRANSACTION;
+TRUNCATE TABLE t1;
+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`))
+SELECT * FROM t1;
+id
+1
+2
+ROLLBACK;
+SELECT * FROM t1;
+id
+1
+2
+SET AUTOCOMMIT = 1;
+START TRANSACTION;
+SELECT * FROM t1;
+id
+1
+2
+COMMIT;
+TRUNCATE TABLE t1;
+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`))
+SELECT * FROM t1;
+id
+1
+2
+DELETE FROM t2 WHERE id = 3;
+START TRANSACTION;
+SELECT * FROM t1;
+id
+1
+2
+TRUNCATE TABLE t1;
+ROLLBACK;
+SELECT * FROM t1;
+id
+TRUNCATE TABLE t2;
+DROP TABLE t2;
+DROP TABLE t1;
End of 5.1 tests