小编Dea*_*ter的帖子

MySQL间隙锁定推理

我遇到了僵局,并试图找出其背后的原因。

问题可以简化为:

表:

create table testdl (id int auto_increment, c int, primary key (id), key idx_c (c));

隔离级别可重复读取

(Tx1): begin; delete from testdl where c = 1000; -- nothing is deleted coz the table is empty

(Tx2): begin; insert into testdl (c) values (?);

无论Tx2中的值是多少,它都会挂起。因此,从根本上说,当delete from testdl where c = 1000找不到匹配项时,Tx1保持整个范围的间隙(-∞,+∞),对吗?

所以我的问题是:这是设计使然吗?这是什么意思呢?

更新:

假设我们已经有以下记录testdl

+----+------+
| id | c    |
+----+------+
|  1 | 1000 |
+----+------+
Run Code Online (Sandbox Code Playgroud)

情况1:

(Tx1): select * from testdl where c = …

mysql database-deadlocks

6
推荐指数
1
解决办法
652
查看次数

Java中的一个神秘字符串

说我有jar文件jarAjarB.

class AjarA:

class A {
  public static final String SQL = "select `col1`, `col2`, ... `col50` from `table`";
}
Run Code Online (Sandbox Code Playgroud)

class BjarB:

class B {
    public void loadData() {
        String sql = "some other sql";
        ...
        A a = null;
        sql = a.SQL + " where something = something"; //This actually works, I never thought about it before I saw this code. 
        executeSQL(sql); //jdbc stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在类路径中运行(以及稍后调试)jarB时 …

java

3
推荐指数
1
解决办法
141
查看次数

标签 统计

database-deadlocks ×1

java ×1

mysql ×1