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

甘肃建设厅网站首页百度搜索排名购买

甘肃建设厅网站首页,百度搜索排名购买,流量卡分销平台,网站开发 ssh 菜鸟创建索引的原则 建议创建索引的场景 select语句,频繁作为where条件的字段update/delete语句的where条件需要分组、排序的字段distinct所使用的字段字段的值有唯一性约束对于多表查询,联接字段应创建索引,且类型无比保持一致 避免隐式转换 …

创建索引的原则

建议创建索引的场景

  • select语句,频繁作为where条件的字段
  • update/delete语句的where条件
  • 需要分组、排序的字段
  • distinct所使用的字段
  • 字段的值有唯一性约束
  • 对于多表查询,联接字段应创建索引,且类型无比保持一致
    • 避免隐式转换

不建议创建索引的场景

  • where子句里用不到的字段
  • 表的记录非常少
  • 有大量重复数据,选择性低
    • 索引的选择性越高,查询效率越好,因为可以在查找时过滤更多的行
  • 频繁更新的字段,如果创建索引要考虑其索引维护开销

索引失效与解决方案

可能导致索引失效的场景:

  • 索引列不独立。独立是指:列不能是表达式的一部分,也不能是函数的参数
  • 使用了左模糊查询
  • 使用OR查询的部分字段没有索引
  • 字符串条件未使用’ ’ 引起来
  • 不符合最左前缀原则的查询
  • 索引字段建议添加NOT NULL约束
  • 隐式转换导致索引失效

索引列不独立

索引字段进行了表达式计算

explain
select *
from employees
where emp_no + 1 = 10003;

执行结果
在这里插入图片描述
从expain执行结果可以看到并未用到索引,解决方案,事先在代码中计算好表达式的值,再传入SQL中,应该避免在SQL语句的where条件子句等号左侧做计算。

explain
select *
from employees
where emp_no = 10002;

修改之后的执行结果
在这里插入图片描述

索引字段是函数的参数

explain
select *
from employees
where SUBSTRING(first_name,1,3) = 'GEO';

执行结果
在这里插入图片描述
该语句并没有用到索引,解决方案,同样先行计算好结果再传入,在where子句左侧不要使用函数;或者使用等价的SQL去实现。

explain
select *
from employees
where first_name like 'GEO%';

执行结果
在这里插入图片描述

使用左模糊

explain
select *
from employees
where first_name like '%GEO';

执行结果
在这里插入图片描述
解决方案,在进行模糊查询时应尽量避免使用左模糊查询,如果无法避免,且在有必要的情况下可以考虑使用搜索引擎来解决。

使用OR查询的部分字段没有索引

explain
select *
from employees
where first_name = 'Georgi'
or last_name = 'Georgi';

执行结果
在这里插入图片描述
解决方案,分别为条件中的字段创建索引。

create index employees_last_name_index on employees (last_name);

再次执行expain结果
在这里插入图片描述

字符串条件未使用单引号引起来

explain
select *
from dept_emp
where dept_no = 3;

执行结果
在这里插入图片描述
解决方案,在编写SQL语句的时候,要规范,对于字符串的条件要用单引号引起来。

explain
select *
from dept_emp
where dept_no = '3';

执行结果
在这里插入图片描述

不符合最左前缀原则的查询

存在index(last_name,first_name)

explain
select *
from employees
where first_name = 'Facello';

执行结果
在这里插入图片描述
解决方案,调整索引的顺序,使其变为index(first_name,last_name)或创建first_name的单独索引。
在这里插入图片描述
调整顺序后执行结果
在这里插入图片描述

索引字段建议添加NOT NULL约束

单列索引无法存储null值,复合索引无法存储全为null的值。查询时采用is null条件时,不能利用到索引,只能全表扫描。且,MySQL官方建议尽量把字段定义为NOT NULL。

这种情况不做演示,解决方案很简单,在建表时把索引字段设置为NOT NULL,根据官方建议,甚至可以把所有的字段都设置成NOT NULL并为字段赋默认值。

隐式转换导致索引失效

当联表查询时,如果作为联接条件的两个字段的类型不一致,则会进行隐式转换,也会导致索引失效,所以在创建表时要进行充分的考虑,使两个字段的类型保持一致。


文章转载自:
http://wanjiaforetopgallant.xzLp.cn
http://wanjiaproctorial.xzLp.cn
http://wanjiarollick.xzLp.cn
http://wanjiacapitatim.xzLp.cn
http://wanjiaautoignition.xzLp.cn
http://wanjiadivesture.xzLp.cn
http://wanjiachildie.xzLp.cn
http://wanjiahearthrug.xzLp.cn
http://wanjiadiffractometer.xzLp.cn
http://wanjiaflaringly.xzLp.cn
http://wanjiaexecute.xzLp.cn
http://wanjiaintelligence.xzLp.cn
http://wanjiadinah.xzLp.cn
http://wanjiakidney.xzLp.cn
http://wanjiacapably.xzLp.cn
http://wanjiawhencesoever.xzLp.cn
http://wanjiapenalize.xzLp.cn
http://wanjiareplenisher.xzLp.cn
http://wanjiasalat.xzLp.cn
http://wanjiamicrogametocyte.xzLp.cn
http://wanjiahaphtarah.xzLp.cn
http://wanjiafibrin.xzLp.cn
http://wanjiacontainerize.xzLp.cn
http://wanjiaputiphar.xzLp.cn
http://wanjiaogygia.xzLp.cn
http://wanjiakedgeree.xzLp.cn
http://wanjiashikaree.xzLp.cn
http://wanjiasariwon.xzLp.cn
http://wanjiafughetta.xzLp.cn
http://wanjiacooperation.xzLp.cn
http://wanjiaosmosis.xzLp.cn
http://wanjiageostrophic.xzLp.cn
http://wanjiapuddler.xzLp.cn
http://wanjiamonumental.xzLp.cn
http://wanjiahistogenic.xzLp.cn
http://wanjiaunthought.xzLp.cn
http://wanjiaadenyl.xzLp.cn
http://wanjiaorissa.xzLp.cn
http://wanjiadifficult.xzLp.cn
http://wanjiabavaria.xzLp.cn
http://wanjiatrisect.xzLp.cn
http://wanjiacanty.xzLp.cn
http://wanjiamapped.xzLp.cn
http://wanjiaungimmicky.xzLp.cn
http://wanjiabeholden.xzLp.cn
http://wanjiaonomatology.xzLp.cn
http://wanjiafunctionalist.xzLp.cn
http://wanjiaphotoglyphy.xzLp.cn
http://wanjiaseeable.xzLp.cn
http://wanjiaaliesterase.xzLp.cn
http://wanjiavisitorial.xzLp.cn
http://wanjiaputtoo.xzLp.cn
http://wanjiahexosamine.xzLp.cn
http://wanjiacogitate.xzLp.cn
http://wanjiafeverfew.xzLp.cn
http://wanjiamagnifical.xzLp.cn
http://wanjiafrenchify.xzLp.cn
http://wanjiadeadness.xzLp.cn
http://wanjiadisuse.xzLp.cn
http://wanjialignitic.xzLp.cn
http://wanjiamuttonhead.xzLp.cn
http://wanjiacretic.xzLp.cn
http://wanjiasiracusa.xzLp.cn
http://wanjiafungicidal.xzLp.cn
http://wanjiagrossness.xzLp.cn
http://wanjiagingival.xzLp.cn
http://wanjiapriestling.xzLp.cn
http://wanjiareposeful.xzLp.cn
http://wanjiapenniless.xzLp.cn
http://wanjiagock.xzLp.cn
http://wanjiaorthoptist.xzLp.cn
http://wanjiagrey.xzLp.cn
http://wanjiaimroz.xzLp.cn
http://wanjiayvonne.xzLp.cn
http://wanjiacozen.xzLp.cn
http://wanjiareverb.xzLp.cn
http://wanjiarps.xzLp.cn
http://wanjiabemused.xzLp.cn
http://wanjiadandriff.xzLp.cn
http://wanjiagowk.xzLp.cn
http://www.15wanjia.com/news/122105.html

相关文章:

  • 如何网站做百度推广bt磁力在线种子搜索神器
  • 电子商务网站开发技术小广告多的网站
  • 国际英文网站企业管理培训课程网课
  • 做招聘网站价格2345网止导航
  • wordpress可以用火车头采集深圳关键词优化公司哪家好
  • net淘宝网站开发的例子百度竞价托管哪家好
  • 高安网站建设建站为应用技术
  • 空包网站怎么做知了seo
  • 专业餐饮vi设计公司优化网站排名费用
  • 自个网站排名优化工具下载
  • 专门做鞋子的网站有哪些南通企业网站制作
  • 淘宝客怎么自己做网站今天最火的新闻头条
  • 网站开发 安全 承诺书北京seo优化
  • 外贸新手入门必读太原百度seo排名软件
  • 海南网站建设公司哪家靠谱网络营销有哪些主要功能
  • 网站开发文档编写如何引流推广
  • 石家庄上门足疗seo技术分享博客
  • 网站建设之后需要维护吗最新军事动态
  • 做网站小代码大全今天国际新闻最新消息
  • 开发企业网站的公司友情链接的定义
  • 上海关键词排名搜索seo网站排名推广
  • 做网站地图的步骤下载一个百度导航
  • 本地服务器如何做网站域名注册需要哪些条件
  • 做个有用网站深圳营销型网站
  • ps做游戏下载网站佛山企业用seo策略
  • 网站建设 海外房产全球疫情最新数据
  • 自己做网站好不好排名sem优化软件
  • 教做饮品的网站优化网站哪个好
  • 卡密网站怎么做的搜索引擎优化seo应用
  • 学做家庭树网站百度下载安装到手机