从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事务知识点零记的更多相关文章

  1. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)爆零记

    昨晚一个瓜皮说今晚有cf,听说是晚间场,我瞅了一眼,娃,VK Cup,上分的好机会,看着比赛时间就有点心酸了,0:35,当时一直在纠结要不要打的问题,当时想着应该不难吧,要不打一下吧,要不还是看看题先 ...

  2. HNOI2019 爆零记

    HNOI2019爆零记 day \(-inf\) ~ day \(0\) 开学一周之后才停的课,停课之后就开始每天被包菜.我三月份几乎没有更博,就是因为每天都被虐的自闭了. day \(0\) 本来是 ...

  3. PKUWC 2019&WC 2019爆零记

    PKUWC 2019&WC 2019爆零记 毕竟过了很久了,杂七杂八的东西就不写了,并且除成绩之外的内容不保证其正确性. Day1 T1:看到这道题很舒服啊,枚举top序算合法图的数量,状压D ...

  4. Elementui实战知识点随记

    1. Elementui实战知识点随记 1.1. 表单验证 对于复杂数据,类似于对象里面包含数组,每个数组又包含多个对象,表单验证我查看了网上很多资料都说Elementui不支持,实际上,经过我官网的 ...

  5. 雅礼集训1-9day爆零记

    雅礼集训1-9day爆零记 先膜一下虐爆我的JEFF巨佬 Day0 我也不知道我要去干嘛,就不想搞文化科 (文化太辣鸡了.jpg) 听李总说可以去看(羡慕)各路大佬谈笑风声,我就报一个名吧,没想到还真 ...

  6. NOIp 0916 爆零记

    题目来自神犇chad 上次爆零是说着玩,这次真的爆零了QAQ 好吧貌似是TYVJ的模拟赛打多了..一直按照TYVJ的格式提交的压缩包.. 然后莫名其妙就AK了hhh 来的时候迟到了半小时,昨晚痛苦的补 ...

  7. [日常] NOIWC 2018爆零记

    开个坑慢慢更(逃 (然而没准会坑掉?) day 0 大概 $8:30$ 就滚去雅礼了qwq 过去的时候发现并没有人...进报到处楼门的时候还被强行拍照围观了一波OwO 然后就领了HZ所有人的提包和狗牌 ...

  8. [HNOI2018]爆零记

    Day 0 完全不知道做什么. 打了一个splay板子,还没调出来emmmmm 不想做题目,最后做的一题是[HNOI2016]的超(sha)难(bi)题网络. 当我希望省选能出一下树剖时,旁边的大佬跟 ...

  9. CTS&&APIO2019爆零记

    如果你只好奇测试相关请跳至day 2 day 3 day 6 scoi 2019 之后 ​ 由于实力问题,省选的时候排名在三十多,显然是没有进队.不过可能是受过的打击比较多,所以还没有特别颓废,甚至连 ...

随机推荐

  1. robot_framewok自动化测试--(2)创建第一个项目

    创建第一个robot_framewok项目 通过 RIDE 去学习和使用 Robot Framework 框架,对于初学者来说大大的降低了学习难度.所以后面对 Robot Framework 框架都将 ...

  2. Invalid prop: type check failed for prop "xxx". Expected Number, got String.

    在子组件progress-circle.vue的template中的定义如下: <svg :width="radius" :height="radius" ...

  3. 『学了就忘』Linux基础命令 — 36、查看系统痕迹相关命令

    目录 1.w命令 2.who命令 3.last命令 4.lastlog命令 5.lastb命令 系统中有一些重要的痕迹日志文件,如/var/log/wtmp./var/run/utmp./var/lo ...

  4. HttpClient用法--这一篇全了解(内含例子)

    HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性,它不仅使客户端发送Http请求变得容易,而且也方便开发人员测试接口(基于Http协议的),提高了开发的效率,也 ...

  5. [bzoj5417]你的名字

    先考虑l=1,r=|s|的部分分,需要求出t每一个前缀的不是s子串的最长后缀,记作pp[k],有以下限制:1.pp[pos[k]]<len(pos[k]表示k的某一个结束位置),因为不能被匹配 ...

  6. [bzoj1432]Function

    对于这n个函数,构成了$n(n-1)/2$个交点,对交点离散后,相邻两个交点间函数的编号构成了一个排列,而每一个排列第i个数所构成的段数就是第i层的段数不妨设初始在-oo处这个排列是1,2,--,n, ...

  7. 使用 FairyGUI 0代码实现游戏界面左右切换

    制作原因:项目中需要实现主界面中五个界面左右切换,包含点击切换和滑动切换,并且点击和滑动都需要关联表现,原先项目使用ugui实现该效果,代码量大,容易出问题,不好管控,使用FGUI后不需一行代码即可相 ...

  8. 既生瑜何生亮 access_token VS refresh_token

    中国有句老话, 既生瑜何生亮, 既然有我周瑜在世, 为什么老天还要一个诸葛亮啊? 同样的, 众所周知, 在 OAuth 2.0 授权协议中, 也有两个令牌 token , 分别是 access_tok ...

  9. Redis | 第7章 Redis 服务器《Redis设计与实现》

    目录 前言 1. 命令请求的执行过程 1.1 发送命令请求 1.2 读取命令请求 1.3 命令执行器(1):查找命令实现 1.4 命令执行器(2):执行预备操作 1.5 命令执行器(3):调用命令的实 ...

  10. Codeforces 708E - Student's Camp(前缀和优化 dp)

    Codeforces 题目传送门 & 洛谷题目传送门 神仙 *3100,%%% 首先容易注意到 \(\forall i\in[1,m]\),第 \(i\) 行剩余的砖块一定构成一个区间,设其为 ...