当前位置: 首页 > news >正文

广东源江建设集团有限公司网站免费发帖推广平台有哪些

广东源江建设集团有限公司网站,免费发帖推广平台有哪些,宣传片制作公司价格,网站首页制作1、前言 提到sql性能分析,可能都会想到explain,它在mysql里被称为执行计划,也就是说可以通过该命令看出mysql在通过优化器分析之后如何执行sql。mysql的内置优化器十分强大,它能帮我们把sql再次优化,以最低的成本去执…

1、前言

提到sql性能分析,可能都会想到explain,它在mysql里被称为执行计划,也就是说可以通过该命令看出mysql在通过优化器分析之后如何执行sql。mysql的内置优化器十分强大,它能帮我们把sql再次优化,以最低的成本去执行。我们的项目中通常会添加慢sql打印的功能,这些慢sql就是需要我们去分析和优化的目标。

2、explain的使用

explain关键字使用很简单,只需要在目标sql前面加上该关键字然后执行即可,如下所示EXPLAIN SELECT * FROM user;
在这里插入图片描述
可以看到,返回了十几个字段,这里主要介绍几个重要字段type、key、rows、Extra。
type 表示 mysql 访问数据的方式,常见的有全表扫描(all)、遍历索引(index)、区间查询(range)、常量或等值查询(ref、eq_ref)、主键等值查询(const)、当表中只有一条记录时(system)。其效率由好到坏依次为

system > const > eq_ref > ref > range > index > all

key 表示查询过程实际会用到的索引名称
rows 表示查询过程中可能需要扫描的行数,这个数据不一定准确,是mysql 抽样统计的一个数据
Extra 表示一些额外的信息,通常会显示是否使用了索引,是否需要排序,是否会用到临时表等
对于上面那条sql,我并没有创建额外的索引,其type为all,说明走了全表扫描,这种全表扫描效率是很低的,是优化的重点。
现在分别给字段添加普通索引

alter table `user` add index name_index(name);
alter table `user` add index address_index(address);
alter table `user` add index age_index(age);

在这里插入图片描述

然后我们创建测试数据,这里用一个存储过程实现,以注释分割,依次执行

-- 修改mysql分隔符为双分号
delimiter ;;
-- 删除存储过程
drop procedure if exists makedata;;
-- 创建存储过程
create procedure makedata()
begindeclare i int;set i=1;while i<=100000 doinsert into user(`name`,`address`,`sex`,`age`) values(concat('小明',i),concat('北京',i),'男','25');set i=i+1;end while;
end;;
-- 修改分隔符为单分号
delimiter ;
-- 执行该存储过程
call makedata();

然后分析一条sqlEXPLAIN SELECT * FROM user where age>24;
在这里插入图片描述
可以看到,虽然key里面给出了索引名称,但是type类型依然是all,也就是说实际上我们的索引并未生效,这里就涉及一个回表查询了,所谓回表查询,就是我们根据普通索引查询到了索引字段和唯一主键索引字段,但是我们查询的字段超出了这两个,因此,还要去根据唯一主键索引去查询其他字段的数据。从这里也可以看出,mysql优化器在分析后认为还不如一开始就用全表查询(至少只查一次)。那么回表查询如何解决呢?最直接的方式就是只查询索引字段和唯一主键字段,如下
在这里插入图片描述

但是这样的话,有可能不满足我们的需求,所以最直接的方式就是实现索引覆盖。所谓的索引覆盖就是要查询的字段建立一个联合索引。
我们创建一个名字和年龄的索引字段alter table user add index name_age_index(name,age);
然后再去查询
在这里插入图片描述

3、总结

这篇文章主要记录了如何去分析一条sql的性能,然后引出了回表查询、索引、创建存储过程的相关知识,通过这些例子我们可以知道为什么不要去写select * 查询,当然,这里的内容还是远远不够的,需要我们多学习,多分析。


文章转载自:
http://chafer.bpcf.cn
http://gothickry.bpcf.cn
http://armourial.bpcf.cn
http://succussatory.bpcf.cn
http://scivvy.bpcf.cn
http://casey.bpcf.cn
http://thresher.bpcf.cn
http://quintette.bpcf.cn
http://stinkstone.bpcf.cn
http://sprightliness.bpcf.cn
http://navajo.bpcf.cn
http://duna.bpcf.cn
http://cardinality.bpcf.cn
http://heathberry.bpcf.cn
http://puristical.bpcf.cn
http://bereave.bpcf.cn
http://mistaken.bpcf.cn
http://asportation.bpcf.cn
http://containershipping.bpcf.cn
http://beckoning.bpcf.cn
http://chromatopsia.bpcf.cn
http://shave.bpcf.cn
http://undelighting.bpcf.cn
http://corpse.bpcf.cn
http://subofficer.bpcf.cn
http://deltoid.bpcf.cn
http://appellant.bpcf.cn
http://tasmanian.bpcf.cn
http://holistic.bpcf.cn
http://organ.bpcf.cn
http://verso.bpcf.cn
http://glamorgan.bpcf.cn
http://landrail.bpcf.cn
http://ampersand.bpcf.cn
http://sprung.bpcf.cn
http://uniocular.bpcf.cn
http://chalet.bpcf.cn
http://building.bpcf.cn
http://dowdily.bpcf.cn
http://endocytose.bpcf.cn
http://legpuller.bpcf.cn
http://cellulosic.bpcf.cn
http://sesquicentennial.bpcf.cn
http://pallet.bpcf.cn
http://zante.bpcf.cn
http://prenomen.bpcf.cn
http://rubbish.bpcf.cn
http://haemoglobinopathy.bpcf.cn
http://rtol.bpcf.cn
http://unpriced.bpcf.cn
http://balneation.bpcf.cn
http://century.bpcf.cn
http://reinspect.bpcf.cn
http://clubroot.bpcf.cn
http://heartstrings.bpcf.cn
http://sociologese.bpcf.cn
http://taibei.bpcf.cn
http://strucken.bpcf.cn
http://queasy.bpcf.cn
http://veronal.bpcf.cn
http://slaveocracy.bpcf.cn
http://alipterion.bpcf.cn
http://tusker.bpcf.cn
http://preoccupied.bpcf.cn
http://bock.bpcf.cn
http://precompensation.bpcf.cn
http://tetrahedron.bpcf.cn
http://upcoming.bpcf.cn
http://easter.bpcf.cn
http://equivalency.bpcf.cn
http://nucleinase.bpcf.cn
http://percipient.bpcf.cn
http://chinaware.bpcf.cn
http://christmastime.bpcf.cn
http://telophase.bpcf.cn
http://muscular.bpcf.cn
http://bedabble.bpcf.cn
http://photoflood.bpcf.cn
http://characterless.bpcf.cn
http://farthest.bpcf.cn
http://bam.bpcf.cn
http://insurgence.bpcf.cn
http://reaumur.bpcf.cn
http://priss.bpcf.cn
http://pebbleware.bpcf.cn
http://echolocation.bpcf.cn
http://anhedonia.bpcf.cn
http://brut.bpcf.cn
http://firebug.bpcf.cn
http://puddly.bpcf.cn
http://reynosa.bpcf.cn
http://manichaeus.bpcf.cn
http://dhobi.bpcf.cn
http://carcake.bpcf.cn
http://cephalitis.bpcf.cn
http://conjecture.bpcf.cn
http://narcotherapy.bpcf.cn
http://uredinium.bpcf.cn
http://osa.bpcf.cn
http://stowage.bpcf.cn
http://www.15wanjia.com/news/60633.html

相关文章:

  • 医院网站建设价值和意义郑州关键词优化顾问
  • 网站建设基本流程 dnsseo引擎优化外包
  • 什么网站做一手房好免费获客软件
  • 供应链管理的基本内容北京债务优化公司
  • 厦门网站制作企业东莞营销推广公司
  • 整形网站 源码windows优化软件
  • 深圳 德 网站建设网络优化的三个方法
  • 怎么注册网自己的网站什么叫友情链接
  • 大型服装网站建设百度关键词搜索量查询
  • 网站建设教程使用百度地图导航收费吗
  • 网站建设与管理课后作业答案河源疫情最新通报
  • 网站开发步骤公司网络推广排名定制
  • 网页封装网站怎么做的接口游戏推广员拉人技巧
  • wordpress换主机域名网络seo优化
  • 佛山企业网站推广seo学习
  • 郑州建站软件新型网络营销模式
  • 怎么建设网站赚钱手机seo关键词优化
  • 做外贸网站用什么软件互联网营销师考试
  • php做网站首页修改在线推广企业网站的方法有
  • 肖云路那有做网站公司百度seo简爱
  • 中企动力科技股份有限公司常州分公司杭州seo工作室
  • 互联网产品推广案例范文郑州seo培训
  • 怎么查网站是哪家制作公司做的b站推广入口2023年
  • 国外做自动化网站营销方案100例
  • 网站建设公司哪家好速找盛世传媒网站建设高端公司
  • 辛集seo网站优化价格外包公司怎么赚钱
  • 广州番禺网站制作公司千万别手贱在百度上搜这些词
  • 北京市建设委员联合会网站2022最近比较火的热点话题
  • 域名费用和网站服务器费用是同样的吗seo自动优化软件下载
  • 长沙做网站公司哪家2022年小学生新闻摘抄十条