mysql 大数据 分页 优化
2017-07-24 00:00
169 查看
1. 不用多扫描数据
Paging without discarding records
尽量避免物理删除.select id, name, address, phone
FROM customers
WHERE id > 990
ORDER BY id LIMIT 10;
(保存最后一个|上一页的id)
前提:根据ID分页.
用户名分页:
SELECT id, username FROM customers WHERE username > ‘shull@iheavy.com’ ORDER BY username LIMIT 10;
2. 延迟关联
Try using a Deferred Join
用户分页.每页十人.
分第100th 页时, LIMIT 10,起始点是 OFFSET 990.
服务器需要先去扫描这990条记录,
SELECT id, name, address, phone FROM customers ORDER BY name LIMIT 10 OFFSET 990;
解决方案:延迟关联
deferred join.
The inside piece just uses the primary key. An explain plan shows us “using index” which we love!
只去取主键id
SELECT id FROM customers ORDER BY name LIMIT 10 OFFSET 990;
Now combine this using an INNER JOIN to get the ten rows and data you want:
SELECT id, name, address, phone FROM customers INNER JOIN ( SELECT id FROM customers ORDER BY name LIMIT 10 OFFSET 990) AS my_results USING(id);
That’s pretty cool!
3.保存页面|
Maintain a Page or Place column
Another way to trick the optimizer from retrieving rows it doesn’t need is to maintain a column for the page, place or position.Yes you need to update that column whenever you (a) INSERT a row (b) DELETE a row ( c) move a row with UPDATE.
This could get messy with page, but a straight place or position might work easier.
保存页面数据
SELECT id, name, address, phone FROM customers WHERE page = 100 ORDER BY name;
Hiring? MySQL DBA Interview Guide for Candidates & Managers.
Or with place column something like this:
保存页面列数
SELECT id, name, address, phone FROM customers WHERE place BETWEEN 990 AND 999 ORDER BY name;
相关文章推荐
- MySQL单表百万数据记录分页性能优化,转载
- 如何优化Mysql千万级快速分页,limit优化快速分页,MySQL处理千万级数据查询的优化方案!(zz)
- 解决Mysql数据量大的时候 分页优化(使用limit)的问题
- MySQL limit 分页查询优化(数据量非常大的情况)
- MySQL单表百万数据记录分页性能优化
- MySQL单表百万数据记录分页性能优化
- 如何优化Mysql千万级快速分页,limit优化快速分页,MySQL处理千万级数据查询的优化方案!(zz)
- mysql 大数据分页查询优化
- MySQL单表百万数据记录分页性能优化
- MySQL单表百万数据记录分页性能优化
- MySQL单表百万数据记录分页性能优化
- MySQL单表百万数据记录分页性能优化技巧
- mysql千万级数据分页查询性能优化
- mysql优化----大数据下的分页,延迟关联,索引与排序的关系,重复索引与冗余索引,索引碎片与维护
- MySQL单表百万数据记录分页性能优化
- MySQL单表百万数据记录分页性能优化
- mysql分页大数据性能优化
- Mysql单表百万数据记录分页性能优化
- MySQL 单表百万数据记录分页性能优化
- Mysql 千万级数据分页优化