如何为nolock测试MySql READ UNCOMMITTED用法

时间:2015-04-07 11:06:25

标签: mysql nolock

我使用以下查询:

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

该表具有大量写入操作和繁重的读取操作。为了从读取操作中获得最小的效果,我想使用非锁定读取操作。在MySql中,它完成了" READ UNCOMMITTED" (根据我读到的内容)。

如何测试此代码是否确实有效?

1 个答案:

答案 0 :(得分: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

不提交此TRANSACTION

第二次连接

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)