什么是延迟索引?使用索引查询出来数据,之后把查询结果和同一张表中数据进行连接查询,进而提高查询速度!

分页是一个很常见功能,select   **  from tableName limit  ($page -  1 )  * $n ,$n

通过一个存储过程进行测试:

create table smth1 (

id int auto_increment ,

ver int(11) default null,

content varchar(1000) not null,

intro varchar(1000) not null,

primary key(id),

key idver(id,ver)

)engine = innodb default charset = utf8;

create procedure smthTest1()

begin

declare num int default 100001;

while num < 1000000 do

set num := num +1;

insert into smth1 values (num ,num,'我是步迎飞','我是谁');

end while ;

end;

查询:

mysql> show profiles;

+----------+------------+----------------------------------------------+

| Query_ID | Duration | Query |

+----------+------------+----------------------------------------------+

| 1 | 0.002006 | select id ,content from smth1 limit 1000,10 |

| 2 | 0.030106 | select id ,content from smth1 limit 5000,10 |

| 3 | 0.042428 | select id ,content from smth1 limit 9000,10 |

| 4 | 0.01297225 | select id ,content from smth1 limit 10000,10 |

| 5 | 0.13077625 | select id ,content from smth1 limit 20000,10 |

可见随着查询$page 变大,时间会越来越大!

怎样避免这种情况?

一般我们数据库里面数据都不会直接删除,数据时很宝贵的,不舍得删除,另一方便能提高查询数据

先利用索引查询出来数据,再进行联合查询不就行了

select C.id,C.content from smth1 C inner join

(

select id from smth1 where id > 1000 limit 10

) as t on C.id = t.id ;

select C.id,C.content from smth1 C inner join

(

select id from smth1 where id > 5000 limit 10

) as t on C.id = t.id ;

select C.id,C.content from smth1 C inner join

(

select id from smth1 where id > 9000 limit 10

) as t on C.id = t.id ;

select C.id,C.content from smth1 C inner join

(

select id from smth1 where id > 10000 limit 10

) as t on C.id = t.id ;

select C.id,C.content from smth1 C inner join

(

select id from smth1 where id > 20000 limit 10

) as t on C.id = t.id ;

进行效率分析,没有一个大于1s的

11 | 0.04538625 | select C.id,C.content from smth1 C inner join

(

select id from smth1 where id > 5000 limit 10

) as t on C.id = t.id |

| 12 | 0.023278 | select C.id,C.content from smth1 C inner join

(

select id from smth1 where id > 9000 limit 10

) as t on C.id = t.id |

| 13 | 0.02320425 | select C.id,C.content from smth1 C inner join

(

select id from smth1 where id > 10000 limit 10

) as t on C.id = t.id |

| 14 | 0.001938 | select C.id,C.content from smth1 C inner join

(

select id from smth1 where id > 20000 limit 10

) as t on C.id = t.id |

c mysql 延时_Mysql 优化之延迟索引和分页优化相关推荐

  1. mysql延时优化教程_Mysql优化之延迟索引和分页优化_MySQL

    什么是延迟索引?使用索引查询出来数据,之后把查询结果和同一张表中数据进行连接查询,进而提高查询速度! 分页是一个很常见功能,select ** from tableName limit ($page ...

  2. mysql 学习笔记--存储引擎、索引、sq优化

    全面的 mysql学习笔记–通用语法.函数.数据类型.约束.多表查询.事务 全面的 mysql学习笔记–存储引擎.索引.sql优化 全面的mysql学习笔记–视图/存储过程/触发器.锁.InnoDB引 ...

  3. 【搬家】【数据库】【优化】SQL 优化学习小结——索引和语句优化

    本文最早于 2013年10月17日于本人个人博客(http://mooowooo.tk)发表,现博客搬家至此,转载请注明出处. SQL 语句的优化对于每个与数据库打交道的程序员来说都是必不可少的一课, ...

  4. mysql存储引擎 索引优化_MySQL存储引擎,索引及基本优化策略

    存储引擎 与Oracle, SQL Server这些数据库不同,MySQL提供了多种存储引擎.什么是存储引擎?存储引擎其实就是一套对于数据如何存储,查询,更新,建立索引等接口的实现.不同存储引擎特性有 ...

  5. 面试题: mysql 数据库已看 sql安全性 索引 引擎 sql优化

    总结的一些MySQL数据库面试题 2016年06月16日 11:41:18 阅读数:4950 一.sql语句应该考虑哪些安全性? (1)防止sql注入,对特殊字符进行转义,过滤或者使用预编译的sql语 ...

  6. mysql 辅助索引_MySQL InnoDB B+tree索引

    假设我们知道 InnoDB 数据页的结构,知道了各个数据页可以组成一个双向链表,而每个数据页中的记录会按照主键值从小到大的顺序组成一个单向链表,每个数据页都会为存储在它里边儿的记录生成一个页目录,在通 ...

  7. 【mysql优化 2】索引条件下推优化

    原文地址:Index Condition Pushdown Optimization 索引条件下推(ICP:index condition pushdown)是mysql中一个常用的优化,尤其是当my ...

  8. mysql 更新索引_MySQL索引优化

    MySQL支持的索引类型 B-tree索引的特点 1.B-tree索引以B+树的结构存储数据 2.B-tree索引能够加快数据的查询速度 3.B-tree索引更适合进行行范围查找 B-tree结构图 ...

  9. mysql主从复制延时性问题_MySQL主从同步延迟原因及解决办法

    MySQL主从延迟原因以及解决方案:谈到MySQL数据库主从同步延迟原理,得从mysql的数据库主从复制原理说起,mysql的主从复制都是单线程的操作(mysql5.6版本之前),主库对所有DDL和D ...

最新文章

  1. 刻意练习:LeetCode实战 -- Task10. 两数相加
  2. 使用显式Intent向下一个活动传递数据
  3. 怎么把一台华为路由器配置为FTP服务器?
  4. BCB6.0里没有TCppWebBrowser
  5. Service 深度解析
  6. java笔记之连接数据库
  7. 告别2019,写给2020:干好技术,要把握好时光里的每一步
  8. 数字图像处理-0.绪论
  9. 永久把linux系统chrome的user agent 改成win10系统的
  10. android os 偷跑,不测不知道,原来我们的流量每天都在被“偷”走!
  11. web项目调用qq临时会话功能实现方法
  12. 自定义拍照时 拍照界面_拍照时图片比例怎么选?比构图还要提前一步的摄影攻略要做好...
  13. 华为鸿蒙新机是哪款,华为新机来了!预装鸿蒙 OS,搭载麒麟 9000!
  14. 【金融项目】尚融宝项目(十五)
  15. C语言小记:结构体及其在内存中的储存形式
  16. 2021肇庆各中学高考成绩查询,广东肇庆4所高中,2020高考创佳绩,肇庆中学领跑,其他3所你可知...
  17. C语言02基础深入理解(二)
  18. qDebug()用法
  19. 深度学习-海康机器人visionmaster图像检索
  20. 林大计算机学子第一篇博客

热门文章

  1. 23、Power Query-XML与JSON数据获取
  2. 不知事务码MB1A / MB1B / MB1C之间有什么区别吗?
  3. LIST-PROCESSING命令的使用
  4. 英语四级计算机准考证查询,四级成绩查询_四级查分:什么?准考证不见了?!!!_沪江英语...
  5. 普宁二中高考2021成绩查询,普宁二中2019高考喜报成绩、本科重本上线人数情况...
  6. 爬虫 无访问权限“_Windows10电脑系统共享打印机无访问权限解决方法
  7. mysql过程异常处理_mysql数据库存储过程异常处理
  8. Python中sorted函数的用法
  9. python3输入的input()坑
  10. 在html中2em是多少px,在css设置单位px、em、rem哪个更好?