my38_MySQL事务知识点零记
从innodb中查看事务信息
show engine innodb status\G;
------------
TRANSACTIONS
------------
Trx id counter 3153146
Purge done for trx's n:o < 3143722 undo n:o < 0 state: running but idle
History list length 31
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421182442263040, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421182442260304, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 3153145, ACTIVE (PREPARED) 0 sec
mysql tables in use 1, locked 1
1 lock struct(s), heap size 1136, 0 row lock(s), undo log entries 1
MySQL thread id 936, OS thread handle 139706768389888, query id 9470005 localhost 127.0.0.1 root query end
insert into test(tid,tname,tvalue) values(i,'aaabbb',concat('有张有驰有分寸',i))
---TRANSACTION 3142243, ACTIVE 3 sec fetching rows
mysql tables in use 1, locked 1
2405 lock struct(s), heap size 286928, 544898 row lock(s), undo log entries 542495
MySQL thread id 941, OS thread handle 139706768119552, query id 9437308 localhost 127.0.0.1 root updating
delete from test where tid < 717337
MySQL thread对应 show full processlist的ID,即MySQL线程ID,常说的应用到MySQL的连接,一个连接可以运行多个事务;
比如thread id 936里面依次N个insert语句,每个语句都是一个事务,他们由root用户执行,当前的状态是query end
每个insert 语句占用一个lock struct,有一个undo log entry
下面的事务是delete语句
mysql> delete from test where tid < 717337 ;
Query OK, 1697989 rows affected (12.68 sec)
它对应的MySQL线程为941,由root用户执行,状态为updating;占用2405个lock struct,有54万个行锁,54万个undo log entries,实际删除数据169万行;
tid上没有索引,应该锁全表,那么不是应该全表有多少行记录就会有多少个行锁吗?为什么删除的数据量有169万,但行锁却只有54万?
现在再重试一下
mysql> select count(*) from test where tid < 2000000;
+----------+
| count(*) |
+----------+
| 1282663 |
+----------+
1 row in set (1.03 sec) mysql> delete from test where tid < 2000000;
Query OK, 1282663 rows affected (11.56 sec)
mysql> select * from information_schema.innodb_trx order by trx_started desc limit 5\G;
*************************** 1. row ***************************
trx_id: 5985123
trx_state: RUNNING
trx_started: 2019-07-05 10:57:35
trx_requested_lock_id: NULL
trx_wait_started: NULL
trx_weight: 2
trx_mysql_thread_id: 936
trx_query: insert into test(tid,tname,tvalue) values(i,'aaabbb',concat('有张有驰有分寸',i))
trx_operation_state: NULL
trx_tables_in_use: 1
trx_tables_locked: 1
trx_lock_structs: 1
trx_lock_memory_bytes: 1136
trx_rows_locked: 0
trx_rows_modified: 1
trx_concurrency_tickets: 0
trx_isolation_level: REPEATABLE READ
trx_unique_checks: 1
trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
trx_adaptive_hash_latched: 0
trx_adaptive_hash_timeout: 0
trx_is_read_only: 0
trx_autocommit_non_locking: 0
*************************** 2. row ***************************
trx_id: 5979390
trx_state: RUNNING
trx_started: 2019-07-05 10:57:33
trx_requested_lock_id: NULL
trx_wait_started: NULL
trx_weight: 287724
trx_mysql_thread_id: 944
trx_query: delete from test where tid < 5000000
trx_operation_state: fetching rows
trx_tables_in_use: 1
trx_tables_locked: 1
trx_lock_structs: 1293
trx_lock_memory_bytes: 155856
trx_rows_locked: 287722
trx_rows_modified: 286431
trx_concurrency_tickets: 0
trx_isolation_level: REPEATABLE READ
trx_unique_checks: 1
trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
trx_adaptive_hash_latched: 0
trx_adaptive_hash_timeout: 0
trx_is_read_only: 0
trx_autocommit_non_locking: 0
2 rows in set (0.00 sec)
------------
TRANSACTIONS
------------
Trx id counter 5990951
Purge done for trx's n:o < 5981847 undo n:o < 0 state: running but idle
History list length 5
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421182442263040, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421182442260304, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 5990950, ACTIVE (PREPARED) 0 sec
mysql tables in use 1, locked 1
1 lock struct(s), heap size 1136, 0 row lock(s), undo log entries 1
MySQL thread id 936, OS thread handle 139706768389888, query id 17983264 localhost 127.0.0.1 root query end
insert into test(tid,tname,tvalue) values(i,'aaabbb',concat('有张有驰有分寸',i))
---TRANSACTION 5979390, ACTIVE 4 sec fetching rows
mysql tables in use 1, locked 1
2820 lock struct(s), heap size 319696, 628384 row lock(s), undo log entries 625566
MySQL thread id 944, OS thread handle 139706900186880, query id 17948592 localhost 127.0.0.1 root updating
delete from test where tid < 5000000
--------
实际上删除128万行记录,通过information_schema.innodb_trx查看只有28万个行锁,通过innodb status查看有62万个行锁
最后一行记录当前innodb每秒处理多少个行记录
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=15950, Main thread ID=139706813634304, state: sleeping
Number of rows inserted 6040828, updated 104, deleted 3680663, read 24882106
3107.91 inserts/s, 0.00 updates/s, 18899.79 deletes/s, 66695.26 reads/s
my38_MySQL事务知识点零记的更多相关文章
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)爆零记
昨晚一个瓜皮说今晚有cf,听说是晚间场,我瞅了一眼,娃,VK Cup,上分的好机会,看着比赛时间就有点心酸了,0:35,当时一直在纠结要不要打的问题,当时想着应该不难吧,要不打一下吧,要不还是看看题先 ...
- HNOI2019 爆零记
HNOI2019爆零记 day \(-inf\) ~ day \(0\) 开学一周之后才停的课,停课之后就开始每天被包菜.我三月份几乎没有更博,就是因为每天都被虐的自闭了. day \(0\) 本来是 ...
- PKUWC 2019&WC 2019爆零记
PKUWC 2019&WC 2019爆零记 毕竟过了很久了,杂七杂八的东西就不写了,并且除成绩之外的内容不保证其正确性. Day1 T1:看到这道题很舒服啊,枚举top序算合法图的数量,状压D ...
- Elementui实战知识点随记
1. Elementui实战知识点随记 1.1. 表单验证 对于复杂数据,类似于对象里面包含数组,每个数组又包含多个对象,表单验证我查看了网上很多资料都说Elementui不支持,实际上,经过我官网的 ...
- 雅礼集训1-9day爆零记
雅礼集训1-9day爆零记 先膜一下虐爆我的JEFF巨佬 Day0 我也不知道我要去干嘛,就不想搞文化科 (文化太辣鸡了.jpg) 听李总说可以去看(羡慕)各路大佬谈笑风声,我就报一个名吧,没想到还真 ...
- NOIp 0916 爆零记
题目来自神犇chad 上次爆零是说着玩,这次真的爆零了QAQ 好吧貌似是TYVJ的模拟赛打多了..一直按照TYVJ的格式提交的压缩包.. 然后莫名其妙就AK了hhh 来的时候迟到了半小时,昨晚痛苦的补 ...
- [日常] NOIWC 2018爆零记
开个坑慢慢更(逃 (然而没准会坑掉?) day 0 大概 $8:30$ 就滚去雅礼了qwq 过去的时候发现并没有人...进报到处楼门的时候还被强行拍照围观了一波OwO 然后就领了HZ所有人的提包和狗牌 ...
- [HNOI2018]爆零记
Day 0 完全不知道做什么. 打了一个splay板子,还没调出来emmmmm 不想做题目,最后做的一题是[HNOI2016]的超(sha)难(bi)题网络. 当我希望省选能出一下树剖时,旁边的大佬跟 ...
- CTS&&APIO2019爆零记
如果你只好奇测试相关请跳至day 2 day 3 day 6 scoi 2019 之后 由于实力问题,省选的时候排名在三十多,显然是没有进队.不过可能是受过的打击比较多,所以还没有特别颓废,甚至连 ...
随机推荐
- Flask WTForm disable choice field
Flask disable choice field ChoiceField = { render_kw={'disabled':''} } form.my_field.render_kw = {'d ...
- [第二章]c++学习笔记6(复制构造函数在各个编译器中的表现)
visual studio结果 dev c++结果 两者的输出有所不同 原因:dev c++编译对这个过程进行了优化,因为直接return对象给a,为节省时间所以不生成临时对象,所以结果为10. 注: ...
- 分布式配置系统Apollo如何实时更新配置的?
引言 记得我们那时候刚开始学习Java的时候都只是一个单体项目,项目里面的配置基本都是写在项目里面的properties文件中,比如数据库配置啥的,各种逻辑开关,一旦这些配置修改了,还需要重启项目这修 ...
- 重新整理 .net core 实践篇——— 权限源码阅读四十五]
前言 简单介绍一下权限源码阅读一下. 正文 一直有人对授权这个事情上争论不休,有的人认为在输入账户密码给后台这个时候进行了授权,因为认为发送了一个身份令牌,令牌里面可能有些用户角色信息,认为这就是授权 ...
- [loj6033]棋盘游戏
将棋盘黑白染色,即构成一张二分图 将状态用一张二分图$G$和一个点$x\in V$描述(分别为仍未被经过的点的导出子图和当前棋子所在位置),并称将要移动棋子的一方为先手 结论:先手必胜当且仅当$x$一 ...
- [bzoj5343]混合果汁
二分枚举答案,问题转化为计算至少取到一定体积,价格最少是多少,显然是贪心取最小,用线段树维护,然后因为要判断答案,所以可持久化一下即可. 1 #include<bits/stdc++.h> ...
- [bzoj1927]星际竞速
考虑没有爆发,那么相当于是带权最小不可交路径覆盖,由于只能从编号小的到编号大的,因此一定是DAG,而DAG的最小路径覆盖可以拆点并跑最大流,那么带权的只需要跑费用流即可(S向i连(1,0)的边,i'向 ...
- 青龙+Nvjdc短信登陆对接Xdd-plus推送+Ninja CK登陆教程(11.23更新)
一.准备工作 1.shh工具(powshell.gitbash等等) 2.购买一台云服务器(阿里云.腾讯云都可以) 3.安装宝塔面板 宝塔Linux面板安装教程 - 2021年8月18日更新 - 7. ...
- 7.1 k8s使用configmapg 给pod内的程序提供配置文件
ConfigMap 是一种 API 对象,用来将非机密性的数据保存到键值对中.使用时, Pods 可以将其用作环境变量.命令行参数或者存储卷中的配置文件. 以下以nginx镜像提供配置文件为例镜像演示 ...
- 联盛德 HLK-W806 (二): Win10下的开发环境配置, 编译和烧录说明
目录 联盛德 HLK-W806 (一): Ubuntu20.04下的开发环境配置, 编译和烧录说明 联盛德 HLK-W806 (二): Win10下的开发环境配置, 编译和烧录说明 联盛德 HLK-W ...