Mysql性能优化-第四课
2022-03-17 16:29:30 0 举报
Mysql锁的工作原理、 事务隔离级别、ReadVeiw、For Update
作者其他创作
大纲/内容
使用覆盖索引
硬件/操作系统
(7,10]
7
事务1
网络IO
4
事务2
5. innodb_io_capacity
select * from user where id=3 for update;
InnoDB
1
(4,7]
Redo Log
Buffer Pool
磁盘调度策略
4. thread_cache_size
.........
select * from user
满足两个条件: 包含Grap区域 以及包含Record记录
3. 把修改结果更新到Buffer Pool
操作系统和硬件
2. 将id=1的行name列修改成mic
Client
(1,4]
begin;
next-key Lock索引区间划分
Memory
BinLog
10
索引
不用模糊查询
B+ Tree 索引
(1,4]
避免全表扫描
主动加行锁
单表扫描算法
存储引擎/表结构
select * from user where id=3 lock in share mode;
操作系统内核参数
服务器硬件优化
2. innodb_log_buffer_size
order by 索引
commit;
update user set name=\"mic\" where id=3
外链接消除
共享锁的工作流程
select * from user where id between 1 and 100 for update;
8. 修改redo log状态为commit
(-∞,1]
新行更新到内存
写入新行
物理查询优化
Mysql Server
分库分表
写入redolog
1. max_connections(最大连接数)
update操作被阻塞
减少数据库查询
两表连接算法
3. table_open_cache
多表连接算法
写入binlog
5. 修改好了,可以提交事务
5. innodb_lock_wait_timeout
小表驱动大表
数据库连接池
Server
返回数据行
select * from no_key_table where id=1 for update;
2. back_log(TCP积压请求栈大小)
update user set name='王五' where id=3;
SQL查询优化
等价谓词重写
Lock Tables user Read;
解析器
3. innodb_flush_log_at_trx_commit
阻塞被唤醒,继续执行更新
条件简化
Record Lock
1. update teacher set name='Mic' where id=1;
内存
数据库集群
select * from no_key_table where name='mic11' for update;
子查询优化
InnoDB引擎调优
读写分离
行锁中的不同锁算法
(10,+∞]
InnoDB引擎
数据库挂了
数据页是否在Buffer Pool
6. 写入binlog
磁盘
把name修改为mic
执行引擎
6. innodb_file_per_table
预处理器
获取id=1这一条记录
Mysql部分调优参数
最左前缀匹配
视图重写
(4,7)
增加服务器资源
执行计划
语义优化
SQL与索引
调整Mysql的架构(资源扩展)
排他锁的工作流程
select * from no_key_table where id=1 for update;
B+Tree索引
4. innodb_max_dirty_pages_pct
从磁盘中加载
select * from no_key_table where id=2 for update;
7. commit,提交事务
Mysql调优范围
Mysql整体优化方法
默认会加行锁
由于共享锁和排他锁互斥,所以事务2在对User表加共享锁时,必须要保证:1. 当前没有其他事务持有user表的排他锁2. 当前没有其他事务持有user表中人一行的排他锁
可以正常查询到返回结果
加Next-Key Lock
事务3
获取user表的表锁
update user set name='mic' where id=3;
加间隙锁
逻辑查询优化
Mysql应用程序的配置(资源利用率)
select * from no_key_table where name='mic' for update;
Grap Lock
1. innodb_buffer_pool_size
查询优化器
Mysql并发参数
临键锁
MyISAM
4. 记录redo log,事务状态prepare
无法加读锁,阻塞
(1,4)
收藏
收藏
0 条评论
下一页