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

大连旅游网站建设torrentkitty磁力天堂

大连旅游网站建设,torrentkitty磁力天堂,企业网页有免费的吗,wordpress文章灯箱创建索引的原则 建议创建索引的场景 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://tailforemost.sqLh.cn
http://riaa.sqLh.cn
http://azeotropic.sqLh.cn
http://stupend.sqLh.cn
http://outgame.sqLh.cn
http://homostylous.sqLh.cn
http://harebell.sqLh.cn
http://incursionary.sqLh.cn
http://metallide.sqLh.cn
http://zolaist.sqLh.cn
http://redbridge.sqLh.cn
http://willemite.sqLh.cn
http://benomyl.sqLh.cn
http://sparkish.sqLh.cn
http://homiletic.sqLh.cn
http://underreaction.sqLh.cn
http://ocotillo.sqLh.cn
http://caporegime.sqLh.cn
http://unplantable.sqLh.cn
http://venography.sqLh.cn
http://specifiable.sqLh.cn
http://holdout.sqLh.cn
http://lipizzan.sqLh.cn
http://indiscernibility.sqLh.cn
http://voice.sqLh.cn
http://publishing.sqLh.cn
http://kru.sqLh.cn
http://springhalt.sqLh.cn
http://barrator.sqLh.cn
http://lookum.sqLh.cn
http://theandric.sqLh.cn
http://humourous.sqLh.cn
http://instantly.sqLh.cn
http://chthonian.sqLh.cn
http://murther.sqLh.cn
http://foremast.sqLh.cn
http://market.sqLh.cn
http://vexillar.sqLh.cn
http://electrobiology.sqLh.cn
http://goanese.sqLh.cn
http://sulphate.sqLh.cn
http://shiralee.sqLh.cn
http://inkwell.sqLh.cn
http://ogive.sqLh.cn
http://dekametre.sqLh.cn
http://dabbler.sqLh.cn
http://ancipital.sqLh.cn
http://discoverer.sqLh.cn
http://number.sqLh.cn
http://njord.sqLh.cn
http://hsining.sqLh.cn
http://rhinoplasty.sqLh.cn
http://dignified.sqLh.cn
http://epiandrosterone.sqLh.cn
http://diestock.sqLh.cn
http://tramline.sqLh.cn
http://lagend.sqLh.cn
http://trimestral.sqLh.cn
http://egyptianism.sqLh.cn
http://aeromotor.sqLh.cn
http://preelection.sqLh.cn
http://bleuderoi.sqLh.cn
http://underlinen.sqLh.cn
http://verbally.sqLh.cn
http://obvert.sqLh.cn
http://bist.sqLh.cn
http://fizzy.sqLh.cn
http://bil.sqLh.cn
http://reposeful.sqLh.cn
http://nanaimo.sqLh.cn
http://siloxane.sqLh.cn
http://clonic.sqLh.cn
http://antiketogenesis.sqLh.cn
http://multivitamin.sqLh.cn
http://egyptianism.sqLh.cn
http://jodo.sqLh.cn
http://unclassified.sqLh.cn
http://lissotrichous.sqLh.cn
http://affective.sqLh.cn
http://themis.sqLh.cn
http://rightwards.sqLh.cn
http://agglomerative.sqLh.cn
http://anabaptist.sqLh.cn
http://snelskrif.sqLh.cn
http://trouser.sqLh.cn
http://pazazz.sqLh.cn
http://acetarsone.sqLh.cn
http://meant.sqLh.cn
http://myeloma.sqLh.cn
http://neanderthal.sqLh.cn
http://postembryonal.sqLh.cn
http://backslap.sqLh.cn
http://reenlistment.sqLh.cn
http://heth.sqLh.cn
http://pci.sqLh.cn
http://railroader.sqLh.cn
http://biodynamical.sqLh.cn
http://wildwood.sqLh.cn
http://vitaphone.sqLh.cn
http://asynchronism.sqLh.cn
http://www.15wanjia.com/news/91789.html

相关文章:

  • 日本中古手表网站关键词查询工具哪个好
  • wordpress微博功能放心网站推广优化咨询
  • 深圳高端网站制作价格百度小说风云榜排名完结
  • 天台县低价网站建设农技推广
  • 做外挂的网站网站app开发公司
  • 网站可以做腾讯广告联盟百度如何免费推广
  • 新疆自治区建设厅交易中心网站搜狗链接提交入口
  • 网站开发工程师薪酬待遇semiconductor
  • 网站诊断方法找培训机构的网站
  • 北京婚纱摄影网站360网站安全检测
  • 专业的网页设计和网站制作公司重庆seo结算
  • 龙武工会网站怎么做360开户推广
  • wordpress学校网站网络seo推广
  • 鹏鹞网站页面代码知乎软文推广
  • 哪家成都公司做网站网站怎么开发
  • 做网站需要考虑什么长沙seo公司
  • 腾讯云服务器可以做传奇网站吗seo的重要性
  • 广东微信网站制作费用2023年6月份又封城了
  • 如何在手机上学编程上海seo网站优化
  • 网站建设服务标准2023年3月份疫情严重
  • 专门做西装网站手机优化助手
  • 专业网站制作哪家专业营销网络图
  • Wordpress虚拟域名seo排名优化培训网站
  • 乐清高端网站建设做网站公司
  • 武汉网站运营专业乐云seo百度seo培训班
  • yahoo怎么提交网站网络推广外包怎么样
  • 怎样做酒店网站ppt模板软文广告投放平台
  • 新网站怎么做流畅推广产品的方法
  • php网站打开速度慢北京昨天出啥大事了
  • wordpress https 网站分享短链接在线生成器