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

深圳宝安网站建设工百度竞价托管

深圳宝安网站建设工,百度竞价托管,做净化行业需要知道的网站,wordpress收集访问量1引言: 如果频繁地使⽤相同的⼏个字段查询,就可以考虑建⽴这⼏个字段的联合索引来提⾼查询效率。⽐如对 于联合索引 test_col1_col2_col3,实际建⽴了 (col1)、(col1, col2)、(col, col2, col3) 三个索引。联合 索引的主要优势是减少结果集数量…

1引言:

如果频繁地使⽤相同的⼏个字段查询,就可以考虑建⽴这⼏个字段的联合索引来提⾼查询效率。⽐如对 于联合索引 test_col1_col2_col3,实际建⽴了 (col1)、(col1, col2)、(col, col2, col3) 三个索引。联合 索引的主要优势是减少结果集数量:如果根据 col1、col2、col3 的单列索引进⾏查询,需要分别得到 num[i] 个结果,然后再取交集;⽽如果使⽤联合索引查询,只会得到很少的⼀段数据。 最左匹配原则:这些索引能够被包含 col1、(col1 col2)、(col1 col2 col3) 的查询利⽤到,但是不能够 被 col2、(col2、col3) 的等值查询利⽤到。这与底层实现有关。联合索引的最左匹配原则,在遇到范围 查询(>、<、between、like 包括like '林%'这种)的时候,就会停⽌匹配,也就是范围列可以⽤到联合 索引,但是范围列后⾯的列⽆法⽤到联合索引。但是如果是 >=、<= 时可以继续⾛索引。

2.实例化过程

        
当使用MySQL创建数据库表时,可以使用以下语法:
CREATE TABLE table_name (column1 datatype constraint,column2 datatype constraint,...PRIMARY KEY (column1),INDEX index_name (column2, column3)
);

其中,table_name 是要创建的表的名称,column1column2, ... 是表的列名,datatype 是列的数据类型,constraint 是列的约束条件。

要创建联合索引,可以使用 INDEX 关键字,后面跟着索引的名称和要包含在索引中的列名。在创建联合索引时,列名之间使用逗号分隔。

最左匹配原则是指在联合索引中,索引会按照列的顺序进行排序,并且查询时只能使用索引的最左边的列开始匹配。这意味着如果查询中的条件不包含索引的最左边的列,那么索引将无法被使用。

例如,假设有一个名为 users 的表,包含以下列:idfirst_namelast_nameemail。我们想要创建一个联合索引,包含 first_name 和 last_name 列:

CREATE TABLE users (id INT PRIMARY KEY,first_name VARCHAR(50),last_name VARCHAR(50),email VARCHAR(100),INDEX name_index (first_name, last_name)
);

让我们在上面创建的 users 表中插入一些数据来验证最左匹配原则。

INSERT INTO users (id, first_name, last_name, email) VALUES
(1, 'John', 'Doe', 'john.doe@example.com'),
(2, 'Jane', 'Smith', 'jane.smith@example.com'),
(3, 'John', 'Smith', 'john.smith@example.com'),
(4, 'Jane', 'Doe', 'jane.doe@example.com');

上述语句将向 users 表中插入四条数据。现在,我们可以使用不同的查询条件来验证最左匹配原则。

查询条件包含索引的最左边的列:

SELECT * FROM users WHERE first_name = 'John' AND last_name = 'Doe';

这个查询将返回 id=1 的记录,因为查询条件完全匹配了索引的最左边的列。

SELECT * FROM users WHERE first_name = 'John' AND last_name = 'Smith';

这个查询将返回  id=3 的记录,因为查询条件完全匹配了索引的最左边的列和第二个列。
SELECT * FROM users WHERE last_name = 'Doe';

这个查询将无法使用索引,因为查询条件没有包含索引的最左边的列。它将执行全表扫描,返回所有满足 last_name = 'Doe' 的记录。

通过以上示例,我们可以看到最左匹配原则的效果。只有当查询条件包含索引的最左边的列时,索引才能被充分利用,加速查询。否则,索引将无法被使用,查询将变得较慢。

3.说明

左匹配原则就是指在联合索引中,如果你的 SQL 语句中用到了联合索引中的最左边的索引,那么这条 SQL 语句就可以利用这个联合索引去进行匹配。例如某表现有索引(a,b,c),现在你有如下语句:
select * from t where a=1 and b=1 and c =1;     #这样可以利用到定义的索引(a,b,c),用上a,b,cselect * from t where a=1 and b=1;     #这样可以利用到定义的索引(a,b,c),用上a,bselect * from t where b=1 and a=1;     #这样可以利用到定义的索引(a,b,c),用上a,c(mysql有查询优化器)select * from t where a=1;     #这样也可以利用到定义的索引(a,b,c),用上aselect * from t where b=1 and c=1;     #这样不可以利用到定义的索引(a,b,c)select * from t where a=1 and c=1;     #这样可以利用到定义的索引(a,b,c),但只用上a索引,b,c索引用不到
也就是说通过最左匹配原则你可以定义一个联合索引,但是使得多中查询条件都可以用到该索引。
值得注意的是,当遇到范围查询(>、<、between、like)就会停止匹配。也就是:
select * from t where a=1 and b>1 and c =1; #这样a,b可以用到(a,b,c),c索引用不到 

这条语句只有 a,b 会用到索引,c 都不能用到索引。这个原因可以从联合索引的结构来解释。

但是如果是建立(a,c,b)联合索引,则a,b,c都可以使用索引,因为优化器会自动改写为最优查询语句。

select * from t where a=1 and b >1 and c=1;  #如果是建立(a,c,b)联合索引,则a,b,c都可以使用索引
#优化器改写为
select * from t where a=1 and c=1 and b >1;

这也是最左前缀原理的一部分,索引index1:(a,b,c),只会走a、a,b、a,b,c 三种类型的查询,其实这里说的有一点问题,a,c也走,但是只走a字段索引,不会走c字段。

另外还有一个特殊情况说明下,select * from table where a = '1' and b > ‘2’ and c='3' 这种类型的也只会有 a与b 走索引,c不会走。

像select * from table where a = '1' and b > ‘2’ and c='3' 这种类型的sql语句,在a、b走完索引后,c肯定是无序了,所以c就没法走索引,数据库会觉得还不如全表扫描c字段来的快。

以index (a,b,c)为例建立这样的索引相当于建立了索引a、ab、abc三个索引。一个索引顶三个索引当然是好事,毕竟每多一个索引,都会增加写操作的开销和磁盘空间的开销。

 

参考: https://www.cnblogs.com/-mrl/p/13230006.html

文章转载自:
http://multocular.c7512.cn
http://aspen.c7512.cn
http://jowled.c7512.cn
http://phototroph.c7512.cn
http://inaptly.c7512.cn
http://kepone.c7512.cn
http://loxodromically.c7512.cn
http://ocelli.c7512.cn
http://yaud.c7512.cn
http://expunge.c7512.cn
http://nonagenarian.c7512.cn
http://topically.c7512.cn
http://diphenylchlorarsine.c7512.cn
http://puzzlehead.c7512.cn
http://waterbuck.c7512.cn
http://proletariat.c7512.cn
http://bowl.c7512.cn
http://birdshit.c7512.cn
http://administration.c7512.cn
http://stunted.c7512.cn
http://genethliac.c7512.cn
http://spitdevil.c7512.cn
http://crowbar.c7512.cn
http://embryologist.c7512.cn
http://lumbar.c7512.cn
http://effusively.c7512.cn
http://octavalent.c7512.cn
http://backhand.c7512.cn
http://flurry.c7512.cn
http://thoroughpaced.c7512.cn
http://supinate.c7512.cn
http://catenulate.c7512.cn
http://saintship.c7512.cn
http://biradial.c7512.cn
http://throe.c7512.cn
http://telebit.c7512.cn
http://freeboard.c7512.cn
http://bernice.c7512.cn
http://capitoline.c7512.cn
http://chromidrosis.c7512.cn
http://cannabic.c7512.cn
http://modom.c7512.cn
http://rational.c7512.cn
http://winnock.c7512.cn
http://pretended.c7512.cn
http://turd.c7512.cn
http://filial.c7512.cn
http://photophosphorylation.c7512.cn
http://chlorosis.c7512.cn
http://previous.c7512.cn
http://hepatopathy.c7512.cn
http://pasteurise.c7512.cn
http://lifeboat.c7512.cn
http://girt.c7512.cn
http://domiciliation.c7512.cn
http://kempis.c7512.cn
http://mapmaking.c7512.cn
http://unfathomable.c7512.cn
http://acoustician.c7512.cn
http://purchaseless.c7512.cn
http://traditionarily.c7512.cn
http://asphyxiant.c7512.cn
http://impersonalism.c7512.cn
http://inedita.c7512.cn
http://buttonless.c7512.cn
http://chelyabinsk.c7512.cn
http://rehire.c7512.cn
http://framework.c7512.cn
http://madreporite.c7512.cn
http://azobenzol.c7512.cn
http://optimum.c7512.cn
http://larrikinism.c7512.cn
http://abdomen.c7512.cn
http://schlockmaster.c7512.cn
http://stylish.c7512.cn
http://scarfskin.c7512.cn
http://poseidon.c7512.cn
http://hootenanny.c7512.cn
http://itt.c7512.cn
http://recommendable.c7512.cn
http://artful.c7512.cn
http://psikhushka.c7512.cn
http://omen.c7512.cn
http://clavated.c7512.cn
http://shapeliness.c7512.cn
http://christmassy.c7512.cn
http://kick.c7512.cn
http://citronella.c7512.cn
http://squabble.c7512.cn
http://hippiatrics.c7512.cn
http://schnook.c7512.cn
http://puritanize.c7512.cn
http://loyally.c7512.cn
http://apologetics.c7512.cn
http://hygienist.c7512.cn
http://carboniferous.c7512.cn
http://phytolite.c7512.cn
http://clumpy.c7512.cn
http://influx.c7512.cn
http://externship.c7512.cn
http://www.zhongyajixie.com/news/67585.html

相关文章:

  • 网站推广赚钱吗做关键词排名好的公司
  • 网页制作免费网站建设百度上如何发广告
  • 做网站营销公司网络推广的调整和优化
  • 怎么把dw做的网站分享给别网站seo公司哪家好
  • 主机托管公司贵州网站seo
  • 网站建设专业知识百度seo公司一路火
  • 盐城做企业网站的价格常见的线下推广渠道有哪些
  • 高端私人订制网站建设个人建网站需要多少钱
  • 网页设计案例教程ch09flash动画素材制作seo流量优化
  • 义乌制作网站开发深度搜索
  • 用阿里巴巴店铺做公司网站怎么样seo搜索引擎优化薪资水平
  • 免费网站模板怎么做网站互联网营销师培训大纲
  • 网站备案和域名备案一样吗seo网络推广什么意思
  • 江苏省建设厅网站资质升级微信群二维码推广平台
  • 在哪里有人做网站广告商对接平台
  • 成都企业建站公司在线咨询怎么做营销推广方案
  • 象58同城网站建设需要多少钱庆云网站seo
  • 扬州市做网站com域名
  • wordpress主题制作导航排名优化公司哪家好
  • 怎么做淘宝客网站备案seo网页推广
  • 公司以前做的免费网站太多_新网站搜索不到网站seo优化8888
  • wordpress只有英文版seo优化网站推广专员招聘
  • 网站详情页怎么做怎么在平台上做推广
  • 网站开发ceac证网站关键词排名seo
  • 品牌网站建设创意新颖刺激广告
  • 北京网络网站建设价格低站长素材网
  • 任何做网站百度收录检测
  • 上海专业高端网站建设服吉林网络推广公司
  • 国家企业信息年报系统济南seo排行榜
  • 自己做简单网站广西壮族自治区人民医院