stoneatom / stonedb

StoneDB is an Open-Source MySQL HTAP and MySQL-Native DataBase for OLTP, Real-Time Analytics, a counterpart of MySQLHeatWave. (https://stonedb.io)
https://stonedb.io/
GNU General Public License v2.0
865 stars 141 forks source link

feature: Tianmu not supports transaction, why set Autocommit=0 affects the result #692

Open davidshiz opened 2 years ago

davidshiz commented 2 years ago

Describe the solution you'd like Tianmu DDL should not be affected by the Autocommit;

Additional context

DELETE & UPDATE have similar problems. as follows

mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit    | OFF   |
+---------------+-------+
1 row in set (0.00 sec)

mysql> select * from t1;
+---+---+
| a | b |
+---+---+
| 1 | 1 |
| 1 | 3 |
+---+---+
2 rows in set (0.00 sec)

mysql> delete from t1 where b = 3;
Query OK, 1 row affected (0.00 sec)

mysql> delete from t1 where b = 3;
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+---+---+
| a | b |
+---+---+
| 1 | 1 |
| 1 | 3 |
+---+---+
2 rows in set (0.01 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t1;
+---+---+
| a | b |
+---+---+
| 1 | 1 |
| 1 | 3 |
+---+---+
2 rows in set (0.00 sec)
davidshiz commented 1 year ago

when set autocommit =0,the row data in the table cannot be deleted, as follows:

mysql> set autocommit=0;
Query OK, 0 rows affected (0.01 sec)

mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit    | OFF   |
+---------------+-------+
1 row in set (0.01 sec)

mysql> CREATE TABLE `test` (`id` int(11) DEFAULT NULL);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into test values (1),(2),(3);
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from test;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

mysql> delete from test where id = 1;
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> select * from test;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

However, when set autocommit = 1, the data can be deleted successfully. as follows:

mysql> set autocommit =1;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from test;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

mysql> delete from test where id = 1;
Query OK, 1 row affected (0.01 sec)

mysql> select * from test;
+------+
| id   |
+------+
|    2 |
|    3 |
+------+
2 rows in set (0.01 sec)

So, this parameter autocommit should not affect the result set.