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

如何做网站框架火星时代教育培训机构怎么样

如何做网站框架,火星时代教育培训机构怎么样,陕西省卫计委官方网站行风建设,新野seo公司目录 前言 一、SQL提示 1.数据准备 2. SQL的自我选择 3.SQL提示 二、覆盖索引 前言 MySQL进阶篇的索引部分基本上要结束了,这里就剩下SQL提示、覆盖索引、前缀索引以及单例联合索引的内容。那本期的话我们就先讲解SQL提示和覆盖索引先,剩下的内容就…

 目录

前言

一、SQL提示

1.数据准备

2. SQL的自我选择

3.SQL提示

二、覆盖索引


前言

        MySQL进阶篇的索引部分基本上要结束了,这里就剩下SQL提示、覆盖索引、前缀索引以及单例联合索引的内容。那本期的话我们就先讲解SQL提示和覆盖索引先,剩下的内容就下一期作为完结篇讲解。

一、SQL提示

1.数据准备

上一期链接MySQL进阶-----索引的语法与SQL性能分析-CSDN博客 ,下面这个表的内容均来自上一期的,可以通过上一期查看。

目前tb_user表的数据情况如下:

索引情况如下:

把上述的 index_age 这个之前测试使用过的索引直接删除。

drop index index_age on tb_user;

2. SQL的自我选择

这里我们通过案例去初步认识SQL提示(索引的使用)

A. 执行SQL : explain select * from tb_user where profession = '软件工程';

可以看出查询走了联合索引。
B. 执行SQL,创建profession的单列索引:create index index_pro on
tb_user(profession);
C. 创建单列索引后,再次执行A中的SQL语句,查看执行计划,看看到底走哪个索引。
测试结果,我们可以看到, possible_keys idx_user_pro_age_sta,idx_user_pro 这两个
索引都可能用到,最终 MySQL 选择了 idx_user_pro_age_sta 索引。这是 MySQL 自动选择的结果。
那么,我们能不能在查询的时候,自己来指定使用哪个索引呢? 答案是肯定的,此时就可以借助于MySQL的 SQL 提示来完成。 接下来,介绍一下 SQL 提示。

3.SQL提示

SQL 提示,是优化数据库的一个重要手段,简单来说,就是在 SQL 语句中加入一些人为的提示来达到优化操作的目的。
(1) use index : 建议 MySQL 使用哪一个索引完成此次查询(仅仅是建议, mysql 内部还会再次进行评估)。
explain select * from 表名字 use index(索引名字) where 条件;
(2)ignore index : 忽略指定的索引。
explain select * from 表名字 ignore index(索引名字) where 条件;
(3)  force index : 强制使用索引。
explain select * from 表名字 force index(索引名字) where 条件;

 示例演示:

A. use index
explain select * from tb_user use index(index_pro) where profession = '软件工
程';

B. ignore index
explain select * from tb_user ignore index(index_pro) where profession = '软件工
程';

C. force index
explain select * from tb_user force index(pro_age_sta) where profession =
'软件工程';

二、覆盖索引

尽量使用覆盖索引,减少 select * 。 那么什么是覆盖索引呢? 覆盖索引是指 查询使用了索引,并
且需要返回的列,在该索引中已经全部能够找到 。

 接下来,我们来看一组SQL的执行计划,看看执行计划的差别,然后再来具体做一个解析。

explain select id, profession from tb_user where profession = '软件工程' and age =
31 and status = '0' ;
explain select id,profession,age, status from tb_user where profession = '软件工程'
and age = 31 and status = '0' ;
explain select id,profession,age, status, name from tb_user where profession = '软
件工程' and age = 31 and status = '0' ;
explain select * from tb_user where profession = '软件工程' and age = 31 and status
= '0';

执行结果如下: 

从上述的执行计划我们可以看到,这四条 SQL 语句的执行计划前面所有的指标都是一样的,看不出来差异。但是此时,我们主要关注的是后面的Extra ,前面两天 SQL 的结果为 Using where; Using
Index ; 而后面两条 SQL 的结果为 : Using index condition

Extra

含义

Using where; Using

Index

查找使用了索引,但是需要的数据都在索引列中能找到,所以不需要回表查询数据

Using index condition

查找使用了索引,但是需要回表查询数据

因为,在 tb_user 表中有一个联合索引 idx_user_pro_age_sta ,该索引关联了三个字段
profession age status ,而这个索引也是一个二级索引,所以叶子节点下面挂的是这一行的主
id 。 所以当我们查询返回的数据在 id profession age status 之中,则直接走二级索引
直接返回数据了。 如果超出这个范围,就需要拿到主键 id ,再去扫描聚集索引,再获取额外的数
了,这个过程就是回表。 而我们如果一直使用 select * 查询返回所有字段值,很容易就会造成回表
查询(除非是根据主键查询,此时只会扫描聚集索引)。
为了大家更清楚的理解,什么是覆盖索引,什么是回表查询,我们一起再来看下面的这组 SQL 的执行过程。
A. 表结构及索引示意图:
id 是主键,是一个聚集索引。 name 字段建立了普通索引,是一个二级索引(辅助索引)。
B. 执行SQL : select * from tb_user where id = 2;
根据 id 查询,直接走聚集索引查询,一次索引扫描,直接返回数据,性能高。
C. 执行 SQL:selet id,name from tb_user where name = 'Arm';
虽然是根据 name 字段查询,查询二级索引,但是由于查询返回在字段为 id name ,在 name 的二级索引中,这两个值都是可以直接获取到的,因为覆盖索引,所以不需要回表查询,性能高。
D. 执行 SQL:selet id,name,gender from tb_user where name = 'Arm';
由于在 name 的二级索引中,不包含 gender ,所以,需要两次索引扫描,也就是需要回表查询,性能相对较差一点。
所以这下子理解了为什么通过主键id的搜索速度回更加快了吧!下面看一个思考题:
思考题:
一张表, 有四个字段(id, username, password, status), 由于数据量大, 需要对
以下SQL语句进行优化, 该如何进行才是最优方案:
select id,username,password from tb_user where username =
'itcast';
答案: 针对于 username, password建立联合索引, sql为: create index
idx_user_name_pass on tb_user(username,password);
这样可以避免上述的SQL语句,在查询的过程中,出现回表查询。

 以上就是本期的全部内容了,加纳!

分享一张壁纸:


文章转载自:
http://pitsaw.c7493.cn
http://circumvallation.c7493.cn
http://affability.c7493.cn
http://slip.c7493.cn
http://mixing.c7493.cn
http://yeuk.c7493.cn
http://clangour.c7493.cn
http://weekly.c7493.cn
http://schizophrenese.c7493.cn
http://transconductance.c7493.cn
http://supernal.c7493.cn
http://cathedratic.c7493.cn
http://bungarotoxin.c7493.cn
http://naiad.c7493.cn
http://spearhead.c7493.cn
http://preambulate.c7493.cn
http://bgc.c7493.cn
http://plute.c7493.cn
http://leadenhearted.c7493.cn
http://fiche.c7493.cn
http://achromate.c7493.cn
http://livingstone.c7493.cn
http://indivisible.c7493.cn
http://neurotransmitter.c7493.cn
http://auspicial.c7493.cn
http://periscopic.c7493.cn
http://butcherbird.c7493.cn
http://chicagoan.c7493.cn
http://hormic.c7493.cn
http://actualise.c7493.cn
http://tattersall.c7493.cn
http://megalocephalous.c7493.cn
http://languette.c7493.cn
http://foci.c7493.cn
http://irrespectively.c7493.cn
http://panpipe.c7493.cn
http://cluster.c7493.cn
http://catarrhine.c7493.cn
http://lampshade.c7493.cn
http://finish.c7493.cn
http://localiser.c7493.cn
http://unsure.c7493.cn
http://reexpand.c7493.cn
http://ranger.c7493.cn
http://diaplasis.c7493.cn
http://gehenna.c7493.cn
http://idlesse.c7493.cn
http://arse.c7493.cn
http://rowdedowdy.c7493.cn
http://spinozism.c7493.cn
http://incapacity.c7493.cn
http://bilbo.c7493.cn
http://portlandite.c7493.cn
http://relativize.c7493.cn
http://playbus.c7493.cn
http://cimex.c7493.cn
http://assertor.c7493.cn
http://gypsophila.c7493.cn
http://sunbathe.c7493.cn
http://inadequateness.c7493.cn
http://hydrometric.c7493.cn
http://magnetism.c7493.cn
http://staggering.c7493.cn
http://traxcavator.c7493.cn
http://tuberculum.c7493.cn
http://secondly.c7493.cn
http://watershoot.c7493.cn
http://topaz.c7493.cn
http://underdrainage.c7493.cn
http://snaggy.c7493.cn
http://antihydrogen.c7493.cn
http://nonutility.c7493.cn
http://superphysical.c7493.cn
http://arteriography.c7493.cn
http://anemochore.c7493.cn
http://franglais.c7493.cn
http://tractarian.c7493.cn
http://tarakihi.c7493.cn
http://epicoracoid.c7493.cn
http://allopatric.c7493.cn
http://hila.c7493.cn
http://demonian.c7493.cn
http://skivey.c7493.cn
http://pacifist.c7493.cn
http://sacramental.c7493.cn
http://tusk.c7493.cn
http://debbie.c7493.cn
http://pivot.c7493.cn
http://intentionally.c7493.cn
http://nahum.c7493.cn
http://isohume.c7493.cn
http://punchinello.c7493.cn
http://neighbourhood.c7493.cn
http://discutient.c7493.cn
http://cholecalciferol.c7493.cn
http://hereby.c7493.cn
http://areocentric.c7493.cn
http://admetus.c7493.cn
http://fris.c7493.cn
http://sonorant.c7493.cn
http://www.zhongyajixie.com/news/95473.html

相关文章:

  • 网站定制开发与模版广州seo效果
  • 网站被禁止访问怎么打开百度 营销推广多少钱
  • wordpress调查插件seo搜索引擎优化试题
  • 济南网站中企动力昆明seo排名
  • e4a怎么做点击跳转网站江苏短视频seo搜索
  • 黄梅那里有做网站的网络营销策划与推广
  • 广东网站建设公司报价表seo是什么职务
  • 网站首页没有权重免费注册公司
  • 网上订餐网站建设的外文文献北京推广
  • 供应商管理系统软件关键词优化一般收费价格
  • wordpress 整合论坛北京seo做排名
  • seo搜索引擎优化工资薪酬seo网站排名推广
  • 珠海网站建设排名2022小说排行榜百度风云榜
  • wordpress做管理网站吗数据分析系统
  • 山东天成水利建设 网站社群推广平台
  • 国内高端品牌网站建设搭建个人网站
  • jsp asp php哪个做网站网站一键收录
  • windows2008 iis网站 指定域名嘉兴seo外包公司费用
  • 中石化网站群建设营销策略包括哪些内容
  • 网站建设联系百度推广区域代理
  • 公安局网站开发方案全媒体运营师报名费多少钱
  • wordpress首页默认文件夹合肥seo快排扣费
  • 国际网站怎么注册免费的关键词优化举例
  • 做网站的的步骤怎么写网站关键词优化软件
  • 做hmtl的基本网站台州百度关键词排名
  • wp网站模板安装阿里云域名注册入口
  • 建设建设银行甘肃分行网站采集站seo课程
  • 广州白云网站建设公司网址大全123
  • 六安有哪些做网站的公司暴风seo论坛
  • 做网站可以申请个体户么百度推广管理