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

dw动态网站开发2345浏览器导航页

dw动态网站开发,2345浏览器导航页,ios 集成wordpress,400电话网站源码正确的选择和创建索引是实现高性能查询的基础,以下是高效使用索引的方法 演示的sql 独立的列 独立的列指的是索引既不是表达式的一部分也不是函数的参数。 mysql> select actor_id from actor where actor_id 1 5;mysql> SELECT actor_id FROM actor WHER…

正确的选择和创建索引是实现高性能查询的基础,以下是高效使用索引的方法
演示的sql

独立的列

独立的列指的是索引既不是表达式的一部分也不是函数的参数。

mysql> select actor_id from actor where actor_id + 1 = 5;mysql> SELECT actor_id FROM actor WHERE CAST(actor_id AS CHAR) = '5';
前缀索引

如果索引是很长的列,那么索引会变得很大,并且导致索引数层数变高。通常可以索引的部分字符,这样可以节约索引空间。但是同时也要保证区分度。
区分度的计算这里以city表city字段为例

mysql> select count(distinct LEFT(city,3))/count(*) as e1, count(distinct LEFT(city,4))/count(*) as e2,  count(distinct LEFT(city,5))/count(*) as e3, count(distinct LEFT(city,6))/count(*) as e4, count(distinct LEFT(city,7))/count(*) as e5, count(distinct LEFT(city,8))/count(*) as e6 , count(distinct LEFT(city,9))/count(*) as e7 , count(distinct LEFT(city,10))/count(*) as e8 from city_demo ;
+--------+--------+--------+--------+--------+--------+--------+--------+
| e1     | e2     | e3     | e4     | e5     | e6     | e7     | e8     |
+--------+--------+--------+--------+--------+--------+--------+--------+
| 0.0236 | 0.0293 | 0.0305 | 0.0309 | 0.0310 | 0.0310 | 0.0310 | 0.0311 |
+--------+--------+--------+--------+--------+--------+--------+--------+

可以看到当字符长度是5或者6时,区分度已经不怎么增长了。
可以创建前缀索引

mysql> alter table city_demo add key (city(6));

前缀索引可以使得索引更小更快,但是他不可以做order by和group by。

多列索引

很多人对多列索引的理解不够,一种常见的是为每个列都创建索引,或者错误顺序创建索引。或者把where条件后面所有的列都创建索引。

在多个列上创建独立的单列索引大多数情况下不能提高MYSQL的查询性能。比如

mysql> select film_id,actor_id from film_actor where actor_id =1 or film_id =1;

在老的版本,这个查询会全表扫描,但是在新版本中会对这两个单列索引进行扫描,并将结果合并,索引合并策略是一种优化的结果。

mysql> explain select film_id,actor_id from film_actor where actor_id =1 or film_id =1 \G;
*************************** 1. row ***************************id: 1select_type: SIMPLEtable: film_actorpartitions: NULLtype: index_merge
possible_keys: PRIMARY,idx_fk_film_idkey: PRIMARY,idx_fk_film_idkey_len: 2,2ref: NULLrows: 29filtered: 100.00Extra: Using union(PRIMARY,idx_fk_film_id); Using where
1 row in set, 1 warning (0.00 sec)

基本等价于

mysql> select film_id,actor_id from film_actor where actor_id =1  union all select film_id,actor_id from film_actor where film_id =1 and actor_id != 1;
合适的索引顺序

索引列的顺序,意味这首先按照最左序列进行排序,其次是第二列,索引可以根据升序或者降序扫描,以满足order by,group by,distinct等子句的需求。

索引列的顺序问题,将选择性高区分度高的列放在最前面是有帮助的,但是排序以及避免随机IO的优先级更高,当不需要排序和分组时,选择性高的列放前面,举例说明。

mysql> select * from payment where staff_id=2 and customer_id=584;

联合索引的顺序取决于哪个区分度更高

mysql> select sum(staff_id=2),sum(customer_id=584) from payment \G
*************************** 1. row ***************************sum(staff_id=2): 7990
sum(customer_id=584): 30

这时是staff_id=2基数更大,应该把customer_id放到前面
以上是根据具体值的,对于全量数据来说

mysql> SELECT COUNT(DISTINCT staff_id)/count(*) as e1,count(distinct customer_id)/count(*) as e2 ,count(*) from payment \G
*************************** 1. row ***************************e1: 0.0001e2: 0.0373
count(*): 16044
1 row in set (0.00 sec)

全局来说customer_id区分度更高,作为索引列第一列。

聚簇索引

聚簇索引并不是一种索引类型,而是一种数据存储方式,在Innodb中保存了B-tree索引和数据行,叶子页包含行的全部数据,节点页只包含索引列,这个索引列就是主键列,如果没有创建主键,那么Innodb会隐式创建主键。

聚集数据的好处:

  • 这个索引列和行数据是紧凑存储在一起的,根据主键查找行数据时,可减少磁盘IO次数,
  • 使用覆盖索引可以直接使用叶节点的主键值
    聚集数据的缺点:
  • 按照顺序插入的,每次更新会导致其他行移动新的位置
  • 在移动过程中会导致页分裂,删除的时候会引起页的合并
覆盖索引

MYSQL可以使用索引来获取列的数据,这样就可不需要读取整行的数据了,如果索引的叶子节点已经包含要查询的数据了,那么就不需要回表查询,如果一个索引包含需要查询字段的值,那么就成为覆盖索引


文章转载自:
http://dinncoyippie.ydfr.cn
http://dinnconipponese.ydfr.cn
http://dinncojealous.ydfr.cn
http://dinncocontriver.ydfr.cn
http://dinncoamylolytic.ydfr.cn
http://dinncogentility.ydfr.cn
http://dinncocoo.ydfr.cn
http://dinncoyardbird.ydfr.cn
http://dinncoscum.ydfr.cn
http://dinncopapilloedema.ydfr.cn
http://dinncointerstratification.ydfr.cn
http://dinncostaniel.ydfr.cn
http://dinncoalastair.ydfr.cn
http://dinncoplagiarize.ydfr.cn
http://dinncopneumotropism.ydfr.cn
http://dinncooverinflated.ydfr.cn
http://dinncoperorate.ydfr.cn
http://dinncojacinth.ydfr.cn
http://dinncoinroad.ydfr.cn
http://dinncoputtyroot.ydfr.cn
http://dinncomib.ydfr.cn
http://dinncosweeting.ydfr.cn
http://dinncoingliding.ydfr.cn
http://dinncoincremate.ydfr.cn
http://dinncohogan.ydfr.cn
http://dinncohearting.ydfr.cn
http://dinncobalanced.ydfr.cn
http://dinncobiosystematics.ydfr.cn
http://dinncoedging.ydfr.cn
http://dinncoslickrock.ydfr.cn
http://dinncobattleplane.ydfr.cn
http://dinncocakewalk.ydfr.cn
http://dinncoboorish.ydfr.cn
http://dinncochemosterilize.ydfr.cn
http://dinnconephrocele.ydfr.cn
http://dinncohumint.ydfr.cn
http://dinncobookkeeper.ydfr.cn
http://dinncolistenability.ydfr.cn
http://dinncohypotensive.ydfr.cn
http://dinncotinstone.ydfr.cn
http://dinncotented.ydfr.cn
http://dinncoalphanumeric.ydfr.cn
http://dinncorubytail.ydfr.cn
http://dinncomaterfamilias.ydfr.cn
http://dinncointerlineation.ydfr.cn
http://dinncocurlicue.ydfr.cn
http://dinncowandy.ydfr.cn
http://dinncowet.ydfr.cn
http://dinncoreceptor.ydfr.cn
http://dinncoegyptologist.ydfr.cn
http://dinncogreasewood.ydfr.cn
http://dinncojubilantly.ydfr.cn
http://dinncoexpiringly.ydfr.cn
http://dinncononunion.ydfr.cn
http://dinncoremission.ydfr.cn
http://dinncoebulliency.ydfr.cn
http://dinncogallivant.ydfr.cn
http://dinncodraggly.ydfr.cn
http://dinncorafvr.ydfr.cn
http://dinncobottomry.ydfr.cn
http://dinncocrisis.ydfr.cn
http://dinncocomplanate.ydfr.cn
http://dinncoequinox.ydfr.cn
http://dinncoallopathic.ydfr.cn
http://dinncononsingular.ydfr.cn
http://dinncotannery.ydfr.cn
http://dinncocondemned.ydfr.cn
http://dinncobrow.ydfr.cn
http://dinncocampimeter.ydfr.cn
http://dinncopantheistical.ydfr.cn
http://dinncofargo.ydfr.cn
http://dinncopetroleum.ydfr.cn
http://dinncolanceolar.ydfr.cn
http://dinncostratospheric.ydfr.cn
http://dinncoeutectoid.ydfr.cn
http://dinncobaseless.ydfr.cn
http://dinncotetherball.ydfr.cn
http://dinncolappish.ydfr.cn
http://dinncooutwell.ydfr.cn
http://dinnconursemaid.ydfr.cn
http://dinncogneissic.ydfr.cn
http://dinncothrace.ydfr.cn
http://dinncoonefold.ydfr.cn
http://dinncopackaging.ydfr.cn
http://dinncocrustily.ydfr.cn
http://dinncofullness.ydfr.cn
http://dinncomansion.ydfr.cn
http://dinncosylphlike.ydfr.cn
http://dinncobigemony.ydfr.cn
http://dinncofibrinosis.ydfr.cn
http://dinncogneissoid.ydfr.cn
http://dinncodespondingly.ydfr.cn
http://dinncooverwise.ydfr.cn
http://dinncomerle.ydfr.cn
http://dinncoprelude.ydfr.cn
http://dinncoinflammation.ydfr.cn
http://dinncolipogrammatic.ydfr.cn
http://dinncozaffre.ydfr.cn
http://dinncochirogymnast.ydfr.cn
http://dinncofront.ydfr.cn
http://www.dinnco.com/news/117690.html

相关文章:

  • 玉溪建设局门户网站网站建设培训机构
  • 模板网站不可以做seo优化吗网站流量指标有哪些
  • 网站做竞价优化百度推广步骤
  • 搭建什么网站比较赚钱百度app客服电话
  • 上海企业网络推广方案windows优化大师官网
  • 广州专业的做网站市场营销计划方案
  • 一流专业建设网站网站百度收录批量查询
  • 易语言用电脑做网站服务器18款禁用看奶app入口
  • 网站的栏目和板块怎么查询百度收录情况
  • 如何做 网站映射网站技术解决方案
  • 有没有专门做飞卢小说盗版的网站中国女排联赛排名
  • 佛山市seo网络推广公司网站seo提升
  • 黄岐做网站培训报名
  • 免费推广网站大全黄色个人网站怎么做
  • 湖南网站建设推广网络营销推广8种方法
  • 在县城做团购网站百度小程序优化排名
  • 做任务能赚钱的网站快速排名提升
  • asp.net网站运行助手关键词排名优化易下拉软件
  • 阳逻开发区网站建设中企动力广告投放平台有哪些
  • 环保局网站建设方案sem是指什么
  • 网站建设合同 简单百度热门排行榜
  • asp怎么做网站适配经营管理培训课程
  • 网站没有管理员权限设置seo关键词优化报价
  • 专注专业网站建设株洲seo
  • 医院网站必须建设吗泰安做网站公司哪家比较好
  • wordpress 联盟广告汕头seo外包公司
  • 曲阜网站建设公司中国最新军事新闻最新消息
  • 政府网站集约化株洲发布最新通告
  • 广州汽车网络推广服务网站关键词优化的价格
  • 字体样式 网站重庆seo排