Bug #4775 Duplicate key requires rollback of transaction
Submitted: 27 Jul 2004 20:09 Modified: 23 Sep 2004 9:13
Reporter: Paul Weiss Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S2 (Serious)
Version:4.1 bk OS:Linux (RH73)
Assigned to: Magnus Blåudd CPU Architecture:Any

[27 Jul 2004 20:09] Paul Weiss
Description:
After trying to insert a record with a duplicate key you need to restart your transaction before you can do anything else. 

How to repeat:
set @@autocommit = 0;
create table foo (a integer primary key, b integer) engine=ndb;
insert into foo values (3,33), (4,44);
commit;
start transaction;

# the duplicate
insert into foo values (3,333);
ERROR 1022 (23000): Can't write; duplicate key in table 'foo'
# as expected 

# not a duplicate
insert into foo values (10,333);
ERROR 1022 (23000): Can't write; duplicate key in table 'foo'
# huh?

select * from foo;
ERROR 1022 (23000): Can't write; duplicate key in table 'foo'
# who's writing?

rollback;
insert into foo values (10,333);
commit;
[1 Sep 2004 21:38] MySQL Verification Team
INSERT works fine for me with the latest BK 4.0 tree, but SELECT fails:

mysql> insert into foo values (10,333);
Query OK, 1 row affected (0.00 sec)

mysql> select * from foo;
ERROR 1022 (23000): Can't write; duplicate key in table 'foo'
[23 Sep 2004 9:13] Magnus Blåudd
The transaction has already been aborted in NDB.

A fix has been made so that an error message indicating the tranaction status is returned saying "Transaction already aborted".  ROLLBACK should be performed on the transaction.

This funcitonality can be changed when WL#1355 Rollback Savepoint in MySQL Cluster has been implemented.

Tested in mysql-test/t/ndb_insert.test