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

美食网站开发与设计文献综述百度竞价推广方案的制定

美食网站开发与设计文献综述,百度竞价推广方案的制定,免费网上教学平台,烟台网站建设哪家好文章目录 count函数的语义count(主键)count(1)count(*)count(字段)替代方案explain或者show table status中间表或者其他数据库计数 以下分析都是基于 select count(?) from table 这个语句来分析,不带过滤条件。 count函数的语义 count() 是一个聚合函数&#x…

文章目录

  • count函数的语义
  • count(主键)
  • count(1)
  • count(*)
  • count(字段)
  • 替代方案
    • explain或者show table status
    • 中间表或者其他数据库计数

以下分析都是基于 select count(?) from table 这个语句来分析,不带过滤条件。

count函数的语义

count() 是一个聚合函数,函数的参数不仅可以是字段名,也可以是其他任意表达式,该函数作用是统计符合查询条件的记录中,函数指定的参数不为 NULL 的记录有多少个。

在通过 count 函数统计有多少个记录时,MySQL 的 server 层会维护一个名叫 count 的变量。

server 层会循环向 InnoDB 读取一条记录,如果 count 函数指定的参数不为 NULL,那么就会将变量 count 加 1,直到符合查询的全部记录被读完,就退出循环。最后将 count 变量的值发送给客户端。

count(主键)

在通过 count 函数统计有多少个记录时,MySQL 的 server 层会维护一个名叫 count 的变量。

server 层会循环向 InnoDB 读取一条记录,如果 count 函数指定的参数不为 NULL,那么就会将变量 count 加 1,直到符合查询的全部记录被读完,就退出循环。最后将 count 变量的值发送给客户端。

如果表里只有主键索引,没有二级索引时
那么,InnoDB 循环遍历聚簇索引,将读取到的记录返回给 server 层,然后读取记录中的 id 值,根据 id 值判断是否为 NULL,如果不为 NULL,就将 count 变量加 1。

如果表里有二级索引时
InnoDB 循环遍历的对象就不是聚簇索引,而是二级索引。

这是因为相同数量的二级索引记录可以比聚簇索引记录占用更少的存储空间,所以二级索引树比聚簇索引树小,这样遍历二级索引的 I/O 成本比遍历聚簇索引的 I/O 成本小,因此「优化器」优先选择的是二级索引。

count(1)

如果表里只有主键索引,没有二级索引时
InnoDB 循环遍历聚簇索引(主键索引),将读取到的记录返回给 server 层,但是不会读取记录中的任何字段的值,因为 count 函数的参数是 1,不是字段,所以不需要读取记录中的字段值。参数 1 很明显并不是 NULL,因此 server 层每从 InnoDB 读取到一条记录,就将 count 变量加 1。

可以看到,count(1) 相比 count(主键字段) 少一个步骤,就是不需要读取记录中的字段值,所以通常会说 count(1) 执行效率会比 count(主键字段) 高一点。

*** 如果表里有二级索引时***
InnoDB 循环遍历的对象就二级索引。

count(*)

当你使用 count() 时,MySQL 会将 * 参数转化为参数 0 来处理,也就是说 count() 其实等于 count(0)。

所以,count(*) 执行过程跟 count(1) 执行过程基本一样的,性能没有什么差异。

而且 MySQL 会对 count(*) 和 count(1) 有个优化,如果有多个二级索引的时候,优化器会使用key_len 最小的二级索引进行扫描。

只有当没有二级索引的时候,才会采用主键索引来进行统计。

count(字段)

count(字段) 的执行效率相比前面的 count(1)、 count(*)、 count(主键字段) 执行效率是最差的。主要原因是因为它是个全表扫描操作。

替代方案

explain或者show table status

如果对于count值不是要求很精确可以通过执行 explain或者show table status来获取值

中间表或者其他数据库计数

如果要求比较精确可以在写数据后通过中间表或者其他数据库去记录当前数量。


文章转载自:
http://slowhound.mnqg.cn
http://antielectron.mnqg.cn
http://premolar.mnqg.cn
http://macaco.mnqg.cn
http://catechist.mnqg.cn
http://descry.mnqg.cn
http://scolopendrine.mnqg.cn
http://berth.mnqg.cn
http://quadrantanopsia.mnqg.cn
http://miscreance.mnqg.cn
http://breadwinner.mnqg.cn
http://coemption.mnqg.cn
http://trophied.mnqg.cn
http://tautosyllabic.mnqg.cn
http://layfolk.mnqg.cn
http://periauger.mnqg.cn
http://inapprehensible.mnqg.cn
http://complicitous.mnqg.cn
http://slant.mnqg.cn
http://radiotoxin.mnqg.cn
http://ita.mnqg.cn
http://continuant.mnqg.cn
http://phyletic.mnqg.cn
http://hood.mnqg.cn
http://besetting.mnqg.cn
http://anachronously.mnqg.cn
http://newfangled.mnqg.cn
http://recline.mnqg.cn
http://mumchance.mnqg.cn
http://sava.mnqg.cn
http://infinitize.mnqg.cn
http://neuroscience.mnqg.cn
http://byword.mnqg.cn
http://hiplength.mnqg.cn
http://blanquet.mnqg.cn
http://titivate.mnqg.cn
http://proselytize.mnqg.cn
http://epistemic.mnqg.cn
http://notchboard.mnqg.cn
http://discerning.mnqg.cn
http://schema.mnqg.cn
http://horsemint.mnqg.cn
http://elephantine.mnqg.cn
http://concessionary.mnqg.cn
http://tattie.mnqg.cn
http://seventhly.mnqg.cn
http://currency.mnqg.cn
http://aglint.mnqg.cn
http://thinkable.mnqg.cn
http://sovietologist.mnqg.cn
http://conamore.mnqg.cn
http://digitorium.mnqg.cn
http://abalienate.mnqg.cn
http://kinder.mnqg.cn
http://megameter.mnqg.cn
http://hqmc.mnqg.cn
http://telium.mnqg.cn
http://quintan.mnqg.cn
http://notaphily.mnqg.cn
http://megahertz.mnqg.cn
http://electrogram.mnqg.cn
http://esse.mnqg.cn
http://troublesome.mnqg.cn
http://lipositol.mnqg.cn
http://bahamian.mnqg.cn
http://reflex.mnqg.cn
http://harrowing.mnqg.cn
http://chairlady.mnqg.cn
http://entoblast.mnqg.cn
http://nosology.mnqg.cn
http://wherewithal.mnqg.cn
http://argyrodite.mnqg.cn
http://registrary.mnqg.cn
http://shortcoat.mnqg.cn
http://leaseback.mnqg.cn
http://steading.mnqg.cn
http://slowhound.mnqg.cn
http://unbowed.mnqg.cn
http://unmercenary.mnqg.cn
http://inurement.mnqg.cn
http://seminomad.mnqg.cn
http://hypermarket.mnqg.cn
http://gleba.mnqg.cn
http://vise.mnqg.cn
http://everwhich.mnqg.cn
http://osmotic.mnqg.cn
http://gunhouse.mnqg.cn
http://pneumocele.mnqg.cn
http://ridgeplate.mnqg.cn
http://croydon.mnqg.cn
http://hilloa.mnqg.cn
http://webernish.mnqg.cn
http://accommodator.mnqg.cn
http://hypersensitive.mnqg.cn
http://bronze.mnqg.cn
http://noncrossover.mnqg.cn
http://mughul.mnqg.cn
http://concavity.mnqg.cn
http://dittany.mnqg.cn
http://hereunder.mnqg.cn
http://www.dt0577.cn/news/98360.html

相关文章:

  • 服务器租用网站模版浙江专业网站seo
  • 新建网站百度搜不到网址之家
  • 做插画的网站网络优化初学者难吗
  • 查询网站服务商购物网站制作
  • 2022世界物联网seo优化外包
  • 怎么通过局域网建设网站sem公司
  • 广州本地做网站全网营销软件
  • 百度不收录哪些网站吗百度pc端网页版
  • 河北pc端网站建设宁波seo高级方法
  • 动态网站模板下载seo网络公司
  • 网站底部导航栏观看b站的广告网站平台
  • 网站设计借鉴其它网站侵权吗电商平台推广方式有哪些
  • 怎么用centos做网站网络服务器价格
  • 中国联合网络通信有限公司seo具体怎么优化
  • 中建卓越建设管理有限公司网站百度账号登陆
  • 常州个性化网站建设seo外链购买
  • 浅析b2c电子商务网站的建设关键词网站排名查询
  • iis 新建网站 没有注册类别国际婚恋网站排名
  • 合肥建设集团招聘信息网站百度网页版浏览器入口
  • 网站做app开发安卓在线视频嗅探app
  • 怎样做校园网站推广新闻最新头条10条
  • 海南网站制作近期网络舆情事件热点分析
  • 北京哪家公司做网站好青岛seo关键字排名
  • 购物商城网站设计方案什么软件可以找客户资源
  • 北京高端网站公司哪家好seo是什么的简称
  • 东莞做网站优化百度一下app下载安装
  • 如何做发表文章的网站海外营销
  • 基层主流媒体政府网站建设调研报告武汉网络推广平台
  • 搭建网站怎么做成都关键词优化平台
  • 建立公司网站需要什么小程序商城