mysql+查询慢+插入快,MySQL:RR模式下insert也可能导致查询慢

RR隔离级别,简单记录如下

1、session 1开启read view

mysql> use test;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> create table testin(id int);

Query OK, 0 rows affected (0.11 sec)

mysql> begin;

Query OK, 0 rows affected (0.00 sec)

mysql> select * from testin;

Empty set (0.01 sec)

2、session 2 不断插入数据

mysql> insert into testin select * from testin;

Query OK, 65536 rows affected (14.11 sec)

Records: 65536 Duplicates: 0 Warnings: 0

mysql> select count(*) from testin;

+----------+

| count(*) |

+----------+

| 131072 |

+----------+

1 row in set (6.82 sec)

mysql> insert into testin select * from testin;

Query OK, 131072 rows affected (27.86 sec)

Records: 131072 Duplicates: 0 Warnings: 0

mysql> select count(*) from testin;

+----------+

| count(*) |

+----------+

| 262144 |

+----------+

1 row in set (13.46 sec)

mysql> insert into testin select * from testin;

Query OK, 262144 rows affected (55.49 sec)

Records: 262144 Duplicates: 0 Warnings: 0

3、session 1查询时间不断递增

mysql> select count(*) from testin;

+----------+

| count(*) |

+----------+

| 0 |

+----------+

1 row in set (0.40 sec)

mysql> select count(*) from testin;

+----------+

| count(*) |

+----------+

| 0 |

+----------+

1 row in set (0.41 sec)

mysql> select count(*) from testin;

+----------+

| count(*) |

+----------+

| 0 |

+----------+

1 row in set (0.40 sec)

mysql> select *from testin;

Empty set (0.41 sec)

mysql> select *from testin;

Empty set (0.98 sec)

mysql> select *from testin;

Empty set (2.72 sec)

mysql> select *from testin;

Empty set (2.97 sec)

应该是在read view的作用下做了很多跳过处理,当然RC 会直观的观察到数据的变化,但是RR则会在可见性的判断下跳过这些行。

慢查询由于innodb层mysql层没有交互因此看不到扫描了行。但是实际上是做了行扫描的。

# Time: 2020-12-16T21:23:34.622196-05:00

# User@Host: root[root] @ localhost [] Id: 7

# Schema: test Last_errno: 0 Killed: 0

# Query_time: 2.966895 Lock_time: 0.000124 Rows_sent: 0 Rows_examined: 0 Rows_affected: 0

# Bytes_sent: 62

SET timestamp=1608171814;

select *from testin;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值