Skip to content

Commit eda8e3d

Browse files
Update 2022-06-22-mysql.md
1 parent 0487b2e commit eda8e3d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

_posts/2022-06-22-mysql.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,10 @@ EXPLAIN 命令的extra一栏中有Using index condition,表明使用了索引
184184
本质原因就是:每次查询时扫描整张表(不走索引),偏移量(offset)越大,mysql就会扫描越多的行,然后再抛弃掉。这样就导致查询性能的下降。
185185

186186
解决方案:
187-
1. 标签记录法,使用 `select * from table where id > 10000 limit 10`
187+
1. 标签记录法,记录上一页最后一条记录的ID或时间戳,作为下一页的查询条件,使用 `select * from table where id > 10000 limit 10`
188188
2. 范围查询,使用 `select * from table where id between 100000 and 100010 order by id desc;`
189-
3. 使用子查询,把条件转移到主键索引树,使用 `select * from table where id >= (select a.id from table a where a.update_time >= xxx limit 100000, 1) limit 10`
190-
4. INNER JOIN 延迟关联,与上述的子查询思路类似,将条件转移到主键索引树
191-
5. 尽量满足索引覆盖
189+
3. 延迟关联(子查询优化),先通过索引获取主键ID,再关联原表获取完整数据,把条件转移到主键索引树,使用 `select * from table where id >= (select a.id from table a where a.update_time >= xxx limit 100000, 1) limit 10`
190+
4. 尽量满足索引覆盖
192191

193192
## 单表数据量大了性能为什么下降
194193

@@ -403,6 +402,8 @@ Binlog 的持久化:
403402
1. 同步调用。在实现增删改的同时,通过调用ES所在服务提供的接口。
404403
2. 异步调用。增删改服务和搜索服务分别通过MQ进行发送和监听消息,有效降低业务的耦合度,但较为依赖MQ的性能。
405404
3. binlog监听。给MySQL开启binlog功能,搜索服务基于canal监听binlog变化,但开启binlog会增加数据库负担、同时实现复杂度较高。
405+
1. Canal
406+
2. Flink CDC
406407

407408
但也有异步调用和binlog监听结合在一起的[例子](https://github.com/Scoefield/syncMySqlToES),用canal作slave节点。
408409

0 commit comments

Comments
 (0)