the rolled-back/discarded transaction gets a "Query OK" msg in Snapshot Isolation level
Please answer these questions before submitting your issue. Thanks!
- What did you do? If possible, provide a recipe for reproducing the error.
SESSION 1
MySQL [gin]> set autocommit=0;
MySQL [gin]> select * from tab1;
+---+------+
| a | b |
+---+------+
| 1 | ok |
| 2 | ok |
+---+------+
2 rows in set (0.00 sec)
SESSION 2
MySQL [gin]> set autocommit=0;
MySQL [gin]> select * from tab1;
+---+------+
| a | b |
+---+------+
| 1 | ok |
| 2 | ok |
+---+------+
2 rows in set (0.00 sec)
SESSION 1
MySQL [gin]> update tab1 set b = 'not ok' where a = 1;
Query OK, 1 row affected (0.01 sec)
MySQL [gin]> update tab1 set b = 'not ok' where a = 2;
Query OK, 1 row affected (0.01 sec)
MySQL [gin]> select * from tab1;
+---+--------+
| a | b |
+---+--------+
| 1 | not ok |
| 2 | not ok |
+---+--------+
2 rows in set (0.00 sec)
MySQL [gin]> commit;
Query OK, 0 rows affected (0.05 sec)
MySQL [gin]> select * from tab1;
+---+--------+
| a | b |
+---+--------+
| 1 | not ok |
| 2 | not ok |
+---+--------+
2 rows in set (0.01 sec)
SESSION 2
MySQL [gin]> delete from tab1 where b='ok'; <------correction
Query OK, 2 rows affected (0.01 sec)
MySQL [gin]> select * from tab1;
Empty set (0.00 sec)
MySQL [gin]> commit;
Query OK, 0 rows affected (0.00 sec) <-------- here SESSION 2's first transaction was discarded, but user got an OK msg.
MySQL [gin]> select * from tab1;
+---+--------+
| a | b |
+---+--------+
| 1 | not ok |
| 2 | not ok |
+---+--------+
2 rows in set (0.01 sec)
an error msg is needed.
- What version of TiDB are you using (
tidb-server -V)? Git Commit Hash: 365e4ab Git Commit Branch: master UTC Build Time: 2017-08-16 01:24:27
create table tab1 (a int, b varchar(30), primary key (a));
insert into tab1 values (1, 'ok'), (2, 'ok');
@tshqin I do not get your point. What's mean by "here SESSION 2's first transaction was discarded". @disksing PTAL
I opened 2 sessions, and disabled auto commit of both sessions, above operations are in time order, as the autocommit is disabled, so session2's first transaction contains: select * from tab1; delete from tab1; select * from tab1; session1 has committed its update operation the earliest, session2 has committed later so its transaction was rolled-back/discarded by TiDB‘s optimistic locking.
Hi @tshqin , I'm not able to reproduce the issue. Do you run tidb with tikv-server and pd-server? If so, please also provide the versions of them.
my fault, in the last step, there's a correction, pls use "delete from tab1 where b='ok';" instead, you'll see.