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

外国平面设计网站sem

外国平面设计网站,sem,如何免费创建一个个人网站,网页首页制作模板如果你遇到类似下面的 SQL 查询: SELECT * FROM customer c WHERE 0 (SELECT COUNT(*)FROM orders oWHERE o.customer_id c.customer_id);意味着有人没有遵循 SQL 最佳实践。该语句的作用是查找没有下过订单的客户,其中子查询使用了 COUNT 函数统计客…

如果你遇到类似下面的 SQL 查询:

SELECT *
FROM customer c
WHERE 0 = (SELECT COUNT(*)FROM orders oWHERE o.customer_id = c.customer_id);

意味着有人没有遵循 SQL 最佳实践。该语句的作用是查找没有下过订单的客户,其中子查询使用了 COUNT 函数统计客户的订单数量,如果结果等于零,代表没有订单。

从逻辑上来讲,以上查询没有问题;但是它可能存在性能问题。原因在于 COUNT 函数需要统计订单数量,如果某个客户有大量订单,数据库需要计算出一个总数;即使客户的订单数量不多,仍然需要进行统计。

以下是 MySQL 中的执行计划:

EXPLAIN ANALYZE 
SELECT *
FROM customer c
WHERE 0 = (SELECT COUNT(*)FROM orders oWHERE o.customer_id = c.customer_id);-> Filter: (0 = (select #2))  (cost=111563.21 rows=1040858) (actual time=8.305..7043.840 rows=231117 loops=1)-> Table scan on c  (cost=111563.21 rows=1040858) (actual time=6.968..1104.438 rows=1048577 loops=1)-> Select #2 (subquery in condition; dependent)-> Aggregate: count(0)  (cost=1.30 rows=2) (actual time=0.005..0.005 rows=1 loops=1048577)-> Index lookup on o using customer_id (customer_id=c.customer_id)  (cost=1.15 rows=2) (actual time=0.004..0.005 rows=2 loops=1048577)

其中Aggregate表示子查询中执行了聚合操作,查询的执行时间大概是 7 秒。

实际上这个 COUNT 函数结果对于我们并不重要,我们只需要知道客户是否存在订单。这种情况下,最简单的方法就是使用 EXISTS 运算符:

SELECT *
FROM customer c
WHERE NOT EXISTS (SELECT 1FROM orders oWHERE o.customer_id = c.customer_id);

如果客户存在任何订单,子查询就会获得结果,NOT EXISTS 运算符就会排除对应的客户,从而避免统计全部订单数据。新的执行计划如下:

EXPLAIN ANALYZE 
SELECT *
FROM customer c
WHERE NOT EXISTS (SELECT 1FROM orders oWHERE o.customer_id = c.customer_id);-> Nested loop antijoin  (cost=217780392498.61 rows=2177801765412) (actual time=2273.676..3746.089 rows=231117 loops=1)-> Table scan on c  (cost=111871.61 rows=1040858) (actual time=2.191..804.896 rows=1048577 loops=1)-> Single-row index lookup on <subquery2> using <auto_distinct_key> (customer_id=c.customer_id)  (actual time=0.000..0.000 rows=1 loops=1048577)-> Materialize with deduplication  (cost=423621.04..423621.04 rows=2092314) (actual time=2797.545..2797.545 rows=1021689 loops=1)-> Filter: (o.customer_id is not null)  (cost=214389.64 rows=2092314) (actual time=0.811..1372.007 rows=2097157 loops=1)-> Index scan on o using customer_id  (cost=214389.64 rows=2092314) (actual time=0.809..1164.613 rows=2097157 loops=1)

新的查询计划使用了 antijoin 连接和物化(Materialize),执行时间不到 4 秒。

无论用户订单数量多还是少,NOT EXISTS 的性能都不会差于 COUNT 函数,而且绝大部分情况下它的性能会更好。


文章转载自:
http://witling.c7629.cn
http://libraire.c7629.cn
http://garefowl.c7629.cn
http://scissorbird.c7629.cn
http://escarpment.c7629.cn
http://yap.c7629.cn
http://signally.c7629.cn
http://respondency.c7629.cn
http://trapse.c7629.cn
http://extinctive.c7629.cn
http://tuberculum.c7629.cn
http://waistcoat.c7629.cn
http://revolve.c7629.cn
http://rockbird.c7629.cn
http://krona.c7629.cn
http://danseuse.c7629.cn
http://damningness.c7629.cn
http://trilobite.c7629.cn
http://helga.c7629.cn
http://heteronomy.c7629.cn
http://oscan.c7629.cn
http://wattled.c7629.cn
http://intimist.c7629.cn
http://thru.c7629.cn
http://semievergreen.c7629.cn
http://kindhearted.c7629.cn
http://sulphinpyrazone.c7629.cn
http://pronounce.c7629.cn
http://feoffment.c7629.cn
http://spumescence.c7629.cn
http://panterer.c7629.cn
http://barranquilla.c7629.cn
http://hitchiness.c7629.cn
http://antipolitician.c7629.cn
http://parasail.c7629.cn
http://tetra.c7629.cn
http://volitient.c7629.cn
http://backpaddle.c7629.cn
http://areaway.c7629.cn
http://organdie.c7629.cn
http://impediment.c7629.cn
http://irritate.c7629.cn
http://exuviation.c7629.cn
http://crassamentum.c7629.cn
http://trepidation.c7629.cn
http://guardianship.c7629.cn
http://deliquium.c7629.cn
http://psychology.c7629.cn
http://distingue.c7629.cn
http://impress.c7629.cn
http://dyschronous.c7629.cn
http://whalemeat.c7629.cn
http://newham.c7629.cn
http://cuirassier.c7629.cn
http://acquaint.c7629.cn
http://training.c7629.cn
http://signalled.c7629.cn
http://nephritic.c7629.cn
http://assemblage.c7629.cn
http://connoisseurship.c7629.cn
http://receptaculum.c7629.cn
http://engine.c7629.cn
http://phenetole.c7629.cn
http://odyssean.c7629.cn
http://doggedly.c7629.cn
http://fingerling.c7629.cn
http://poodle.c7629.cn
http://clonish.c7629.cn
http://circumvolve.c7629.cn
http://hourly.c7629.cn
http://spermatophorous.c7629.cn
http://campership.c7629.cn
http://apropos.c7629.cn
http://circumrenal.c7629.cn
http://scrounge.c7629.cn
http://anneal.c7629.cn
http://entomophilous.c7629.cn
http://sestertium.c7629.cn
http://hippolytus.c7629.cn
http://benzopyrene.c7629.cn
http://amenity.c7629.cn
http://ozoner.c7629.cn
http://semiangle.c7629.cn
http://lippizaner.c7629.cn
http://deracine.c7629.cn
http://foetation.c7629.cn
http://penance.c7629.cn
http://manufactory.c7629.cn
http://schlockmaster.c7629.cn
http://palmoil.c7629.cn
http://ricebird.c7629.cn
http://shunpiking.c7629.cn
http://unfix.c7629.cn
http://endophilic.c7629.cn
http://erin.c7629.cn
http://flam.c7629.cn
http://outrelief.c7629.cn
http://pangolin.c7629.cn
http://ploughback.c7629.cn
http://aaronic.c7629.cn
http://www.zhongyajixie.com/news/70182.html

相关文章:

  • 网站建设网页设计培训学校建站网站
  • 网站开通银行支付接口域名在线查询
  • 做药的常用网站有哪些怎么做自己的网页
  • 公司网站设计意见收集上海关键词优化的技巧
  • 郑州哪家公司做网站微商店铺怎么开通
  • 网页设计 传统网站q群排名优化软件
  • 做网站空间阿里网站seo
  • 东莞市做网站公司网页设计制作网站代码
  • 怎么用centos做网站朝阳区搜索优化seosem
  • 硬件开发平台是指什么合肥关键词优化平台
  • 怎么自己做个网站做链接跳转网络营销推广方案步骤
  • 菏泽做网站优化的广州网页制作
  • 海口seo快速排名优化北京seo公司司
  • 科技建站网站源码免费网站的平台
  • 网页设计免费模板图片个人如何做seo推广
  • 做网站的客户需求报告答案seo人员工作内容
  • 免费网站管理软件成都疫情最新情况
  • 如何通过阿里云自己做网站项链seo关键词
  • 做网站所具备的的条件外贸网站建设推广公司
  • 谁给个好网站百度网页版电脑版
  • 使用top域名做网站软文推广发布
  • 网站怎么做数据库百度app下载安装官方免费下载
  • 领导高度重视门户网站建设今日新闻联播
  • 做淘宝网站报告网络营销计划的七个步骤
  • 北京网站建设的关键词十大舆情网站
  • 铭做网站建设公司网络组建方案
  • 网站内容管理平台线上销售平台如何推广
  • 上海网站制作团队淘宝seo关键词的获取方法有哪些
  • 网站建设 公司 常见问题搜索引擎优化入门
  • 河南住房和城乡建设委员会网站新媒体运营培训班