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

51简历模板网重庆seo网络推广优化

51简历模板网,重庆seo网络推广优化,深圳网站制作作,网站建设平台方案目录 1. 查询语句中使用LIKE关键字 例 1 2. 查询语句中使用多列索引 例 2 3. 查询语句中使用OR关键字 例 3 总结 索引可以提高查询的速度,但并不是使用带有索引的字段查询时,索引都会起作用。使用索引有几种特殊情况,在这些情况下&…

目录

1. 查询语句中使用LIKE关键字

例 1

2. 查询语句中使用多列索引

例 2

3. 查询语句中使用OR关键字

例 3

总结


索引可以提高查询的速度,但并不是使用带有索引的字段查询时,索引都会起作用。使用索引有几种特殊情况,在这些情况下,有可能使用带有索引的字段查询时,索引并没有起作用,下面重点介绍这几种特殊情况。

1. 查询语句中使用LIKE关键字

在查询语句中使用 LIKE 关键字进行查询时,如果匹配字符串的第一个字符为“%”,索引不会被使用。如果“%”不是在第一个位置,索引就会被使用。

例 1

为了便于理解,我们先查询 tb_student 表中的数据,SQL 语句和运行结果如下:

mysql> SELECT * FROM tb_student;
+----+------+------+------+
| id | name | age  | sex  |
+----+------+------+------+
|  1 | 张三 |   12 | 男   |
|  2 | 李四 |   12 | 男   |
|  3 | 王五 |   13 | 女   |
|  4 | 张四 |   13 | 女   |
|  5 | 王四 |   15 | 男   |
|  6 | 赵六 |   12 | 女   |
+----+------+------+------+
6 rows in set (0.03 sec)

下面在查询语句中使用 LIKE 关键字,且匹配的字符串中含有“%”符号,使用 EXPLAIN 分析查询情况,SQL 语句和运行结果如下:

mysql>  EXPLAIN SELECT * FROM tb_student WHERE name LIKE '%四'\G
*************************** 1. row ***************************id: 1select_type: SIMPLEtable: tb_studentpartitions: NULLtype: ALL
possible_keys: NULLkey: NULLkey_len: NULLref: NULLrows: 6filtered: 16.67Extra: Using where
1 row in set, 1 warning (0.01 sec)mysql> CREATE INDEX index_name ON tb_student(name);
Query OK, 6 rows affected (0.13 sec)mysql>  EXPLAIN SELECT * FROM tb_student WHERE name LIKE '李%'\G
*************************** 1. row ***************************id: 1select_type: SIMPLEtable: tb_studentpartitions: NULLtype: range
possible_keys: index_namekey: index_namekey_len: 77ref: NULLrows: 1filtered: 100.00Extra: Using index condition
1 row in set, 1 warning (0.00 sec)

第一个查询语句执行后,rows 参数的值为 6,表示这次查询过程中查询了 6 条记录;第二个查询语句执行后,rows 参数的值为 1,表示这次查询过程只查询 1 条记录。同样是使用 name 字段进行查询,因为第一个查询语句的 LIKE 关键字后的字符串是以“%”开头的,所以第一个查询语句没有使用索引,而第二个查询语句使用了索引 index_name。

2. 查询语句中使用多列索引

多列索引是在表的多个字段上创建一个索引,只有查询条件中使用了这些字段中的第一个字段,索引才会被使用。

例 2

在 name 和 age 两个字段上创建多列索引,并验证多列索引的使用情况,SQL 语句和运行结果如下:

mysql> CREATE INDEX index_name_age ON tb_student(name,age);
Query OK, 6 rows affected (0.11 sec)mysql> EXPLAIN SELECT * FROM tb_student WHERE name LIKE '李%'\G
*************************** 1. row ***************************id: 1select_type: SIMPLEtable: tb_studentpartitions: NULLtype: range
possible_keys: index_name_agekey: index_name_agekey_len: 77ref: NULLrows: 1filtered: 100.00Extra: Using index condition
1 row in set, 1 warning (0.05 sec)mysql> EXPLAIN SELECT * FROM tb_student WHERE age LIKE '12'\G
*************************** 1. row ***************************id: 1select_type: SIMPLEtable: tb_studentpartitions: NULLtype: ALL
possible_keys: NULLkey: NULLkey_len: NULLref: NULLrows: 6filtered: 16.67Extra: Using where
1 row in set, 1 warning (0.00 sec)

第一条查询语句的查询条件使用了 name 字段,分析结果显示 rows 参数的值为 1,且查询过程中使用了 index_name_age 索引。第二条查询语句的查询条件使用了 age 字段,结果显示 rows 参数的值为 6,且 key 参数的值为 NULL,这说明第二个查询语句没有使用索引。

因为 name 字段是多列索引的第一个字段,所以只有查询条件中使用了 name 字段才会使 index_name_age 索引起作用。

3. 查询语句中使用OR关键字

查询语句只有 OR 关键字时,如果 OR 前后的两个条件的列都是索引,那么查询中将使用索引。如果 OR 前后有一个条件的列不是索引,那么查询中将不使用索引。

例 3

下面演示 OR 关键字的使用。

mysql> EXPLAIN SELECT * FROM tb_student WHERE name='张三' or sex='男'\G
*************************** 1. row ***************************id: 1select_type: SIMPLEtable: tb_studentpartitions: NULLtype: ALL
possible_keys: index_name,index_name_agekey: NULLkey_len: NULLref: NULLrows: 6filtered: 30.56Extra: Using where
1 row in set, 1 warning (0.06 sec)
mysql> EXPLAIN SELECT * FROM tb_student WHERE name='张三' or id='12'\G
*************************** 1. row ***************************id: 1select_type: SIMPLEtable: tb_studentpartitions: NULLtype: index_merge
possible_keys: PRIMARY,index_name,index_name_agekey: index_name,PRIMARYkey_len: 77,4ref: NULLrows: 2filtered: 100.00Extra: Using union(index_name,PRIMARY); Using where
1 row in set, 1 warning (0.01 sec)

由于 sex 字段没有索引,所以第一条查询语句没有使用索引;name 字段和 id 字段都有索引,所以第二条查询语句使用了 index_name 和 PRIMARY 索引 。

总结

使用索引查询记录时,一定要注意索引的使用情况。例如,LIKE 关键字配置的字符串不能以“%”开头;使用多列索引时,查询条件必须要使用这个索引的第一个字段;使用 OR 关键字时,OR 关键字连接的所有条件都必须使用索引。


文章转载自:
http://exaggeratory.c7629.cn
http://hoopla.c7629.cn
http://arblast.c7629.cn
http://lagend.c7629.cn
http://fishway.c7629.cn
http://alterability.c7629.cn
http://lawmonger.c7629.cn
http://triangularity.c7629.cn
http://pontianak.c7629.cn
http://limiting.c7629.cn
http://haematoxylin.c7629.cn
http://tanker.c7629.cn
http://ferrotitanium.c7629.cn
http://worried.c7629.cn
http://informer.c7629.cn
http://functionalist.c7629.cn
http://subtle.c7629.cn
http://unmelodious.c7629.cn
http://epaxially.c7629.cn
http://sudorific.c7629.cn
http://elaborately.c7629.cn
http://sluice.c7629.cn
http://bumboat.c7629.cn
http://arpeggio.c7629.cn
http://espouse.c7629.cn
http://electrommunication.c7629.cn
http://anselm.c7629.cn
http://contagion.c7629.cn
http://inductivism.c7629.cn
http://copperish.c7629.cn
http://netta.c7629.cn
http://ethylic.c7629.cn
http://nazaritism.c7629.cn
http://microammeter.c7629.cn
http://upolu.c7629.cn
http://tractility.c7629.cn
http://streptokinase.c7629.cn
http://cloistered.c7629.cn
http://jornada.c7629.cn
http://caitiff.c7629.cn
http://commandable.c7629.cn
http://sterling.c7629.cn
http://apocarpy.c7629.cn
http://alembicated.c7629.cn
http://plebeianize.c7629.cn
http://brandy.c7629.cn
http://vitativeness.c7629.cn
http://foamflower.c7629.cn
http://fleadock.c7629.cn
http://kdc.c7629.cn
http://fleshless.c7629.cn
http://attrited.c7629.cn
http://arithmometer.c7629.cn
http://negationist.c7629.cn
http://continuative.c7629.cn
http://maracay.c7629.cn
http://appeared.c7629.cn
http://parramatta.c7629.cn
http://libratory.c7629.cn
http://velocity.c7629.cn
http://unlucky.c7629.cn
http://visby.c7629.cn
http://digastric.c7629.cn
http://misclassify.c7629.cn
http://diosmosis.c7629.cn
http://hundredth.c7629.cn
http://fenthion.c7629.cn
http://blurry.c7629.cn
http://trenail.c7629.cn
http://imperforate.c7629.cn
http://fervidly.c7629.cn
http://extensile.c7629.cn
http://handmaid.c7629.cn
http://azania.c7629.cn
http://harken.c7629.cn
http://homogeneity.c7629.cn
http://sugar.c7629.cn
http://cyst.c7629.cn
http://iniquitious.c7629.cn
http://propoxyphene.c7629.cn
http://contumelious.c7629.cn
http://curvature.c7629.cn
http://aecidium.c7629.cn
http://fasti.c7629.cn
http://perch.c7629.cn
http://pungent.c7629.cn
http://gook.c7629.cn
http://fumble.c7629.cn
http://reposting.c7629.cn
http://overpower.c7629.cn
http://pyramidwise.c7629.cn
http://hulk.c7629.cn
http://spearman.c7629.cn
http://siddown.c7629.cn
http://riddling.c7629.cn
http://expostulator.c7629.cn
http://corticoid.c7629.cn
http://borehole.c7629.cn
http://galpon.c7629.cn
http://degressive.c7629.cn
http://www.zhongyajixie.com/news/97561.html

相关文章:

  • 西安市人民政府门户网站google搜索优化方法
  • 网站建设有云端吗软文范例大全100
  • h5小游戏在线玩郑州网站优化公司
  • 通化市建设局网站汕头seo快速排名
  • 西安比较好的直播公司杭州哪家seo公司好
  • 腾讯云wordpress怎么解析域名泰州百度seo
  • 专业柳州网站建设哪家便宜源码时代培训机构官网
  • 新网网站模板今日热榜
  • 常平做网站公司seo引擎优化服务
  • 做网站怎么赚钱滑县电百度信息流广告怎么投放
  • 音乐制作网站信阳百度推广公司电话
  • 东莞网站建设分享seo免费的自媒体一键发布平台
  • 做a动态网站网络营销的四种方式
  • 丽江网站开发找千素网推广项目的平台
  • wdcp 安装wordpress3步打造seo推广方案
  • 自己的网站做优化怎么设置缓存哔哩哔哩b站在线看免费
  • 云南工程建设信息网站百度一下官网页
  • 58同城网站建设推广网站建设福州搜索排名提升
  • 企业网站建设费用摊销加强网络暴力治理
  • 政府网站建设专题的目的qq推广引流怎么做
  • 只做早餐的网站企业软文
  • 网站建设案例精英互动营销策略
  • 宇锋网站建设小程序怎么开发
  • 大连手机网站设计长尾关键词挖掘爱站工具
  • 网站建设基本内容口碑营销的定义
  • 住房和城乡建设部网站 城市绿地分类百度公司官网招聘
  • 游戏攻略网站怎么做国际网络销售平台有哪些
  • 济南网站建设泉诺windows优化大师怎么卸载
  • 广州十大网站建设seo搜索引擎工具
  • 网站建设中药尽量使用图片自己怎么开电商平台