1

我正在使用以下查询:

SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
SELECT * FROM TABLE_NAME ;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ ;

该表有很多写操作和繁重的读操作。为了从读取操作中获得最小的效果,我想使用非锁定读取操作。在 MySql 中,它是通过“READ UNCOMMITTED”完成的(根据我阅读的内容)。

如何测试这段代码是否真的有效?

4

1 回答 1

1

第一个连接:

 MariaDB [(none)]> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> INSERT INTO t2 VALUES(1),(3);
ERROR 1046 (3D000): No database selected
MariaDB [(none)]> use test
Database changed
MariaDB [test]> INSERT INTO t2 VALUES(1),(3);
Query OK, 2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0

不提交此交易

第二次连接

MariaDB [test]> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
Query OK, 0 rows affected (0.00 sec)

MariaDB [test]> SELECT * FROM t2;
+------+
| i    |
+------+
|    1 |
|    3 |
+------+
2 rows in set (0.00 sec)

MariaDB [test]> COMMIT ;

 MariaDB [test]> select * from t2;
Empty set (0.00 sec)
于 2016-03-31T13:41:47.247 回答