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

淮安市做网站百度关键词工具入口

淮安市做网站,百度关键词工具入口,四川企业网站开发,做游戏攻略网站赚钱吗PostgreSQL17优化器改进(4)允许UNION(没有ALL)使用MergeAppend UNION存在的问题 到PostgreSQL16.3版本为止,UNION执行计划通常不是最优的,优化器有两种处理方法: 优化器只考虑使用Append节点并通过使用Hash Aggregate,Append -…

PostgreSQL17优化器改进(4)允许UNION(没有ALL)使用MergeAppend

UNION存在的问题

到PostgreSQL16.3版本为止,UNION执行计划通常不是最优的,优化器有两种处理方法:

  1. 优化器只考虑使用Append节点并通过使用Hash Aggregate,Append -> Hash Aggregate
  2. 对整个Append结果排序并通过unique操作符运行使结果唯一,Append -> Sort -> Unique

目前这两种方法总是需要从union子查询中读取所有行

解决方案

在PostgreSQL17版本中,官网通过调整union优化器,使它可以请求每个子查询并以目标列表顺序产生结果,以便将这些结果通过Merge Appended合并在一起,并使用Unique节点使其唯一。因为union子节点可以使用类似于b树索引 and/or Merge Joins为top-level UNION提供预先排序的输入,所以性能有了显著提高。如果top-level UNION包含一个LIMIT节点,该节点将输出行限制为结合行的一个小子集,因为可以使用廉价的启动计划,那么这一点特别好。

执行计划对比

创建测试表

set min_parallel_table_scan_size = '1kB';
set min_parallel_index_scan_size = '1kB';
set parallel_setup_cost = 0;
set parallel_tuple_cost = 0;
set max_parallel_workers_per_gather = 2;
create table t (a int, b int, c int);
insert into t select mod(i,10),mod(i,10),i from generate_series(1,10000) s(i);
create index on t (a);
analyze t;

PostgreSQL16.3的执行计划

优化器只考虑使用Append节点并通过使用Hash Aggregate

由于数据库的参数enable_hashagg默认值是on,含义是允许或禁用查询规划器使用哈希聚集计划类型,因此正常情况下生成的是下面的执行计划。

testdb=# explain (costs off) select count(*) from( select a from t union select c from t ) ss;QUERY PLAN              
-------------------------------------Aggregate->  HashAggregateGroup Key: t.a->  Append->  Seq Scan on t->  Seq Scan on t t_1
(6 rows)
对整个Append结果排序并通过unique操作符运行使结果唯一

如果要生成该执行计划,需要修该enable_hashagg为off

postgres=# set enable_hashagg to off;
SET
postgres=# explain (costs off) select count(*) from( select a from t union select c from t ) ss;QUERY PLAN                 
-------------------------------------------Aggregate->  Unique->  SortSort Key: t.a->  Append->  Seq Scan on t->  Seq Scan on t t_1

PostgreSQL17的执行计划

优化器只考虑使用Append节点并通过使用Hash Aggregate

由于数据库的参数enable_hashagg默认值是on,含义是允许或禁用查询规划器使用哈希聚集计划类型,因此正常情况下生成的是下面的执行计划

testdb=# explain (costs off) select count(*) from( select a from t union select c from t ) ss;QUERY PLAN                     
----------------------------------------------------Aggregate->  HashAggregateGroup Key: t.a->  GatherWorkers Planned: 2->  Parallel Append->  Parallel Seq Scan on t->  Parallel Seq Scan on t t_1
(8 rows)

当前执行计划的执行路径,和PostgreSQL16.3执行计划路径,相差不大,优化器还是使用Append节点并通过使用Hash Aggregate,Append -> Hash Aggregate

对整个Append结果排序并通过unique操作符运行使结果唯一

如果要生成该执行计划,需要修该enable_hashagg为off

testdb=# set enable_hashagg to off;
SET
testdb=# explain (costs off) select count(*) from( select a from t union select c from t ) ss;QUERY PLAN                        
----------------------------------------------------------Aggregate->  Unique->  Merge AppendSort Key: t.a->  Index Only Scan using t_a_idx on t->  Gather MergeWorkers Planned: 2->  SortSort Key: t_1.c->  Parallel Seq Scan on t t_1
(10 rows)

总结

根据官网发布新优化器的描述和对PostgreSQL16.3和PostgreSQL17版本的对比测试,针对官网描述允许UNION(没有ALL)使用MergeAppend,应该具体是对PostgreSQL16.3版本中对于UNION执行计划的其中一个分支,即对整个Append结果排序并通过unique操作符运行使结果唯一(Append -> Sort -> Unique)执行路径进行了优化,优化后的路径应该为Sort->Merge Append-> Unique,需要得到该结果的前提是需要设置enable_hashagg为off。UNION执行计划的另外一个分支,实际上也有优化,但是本文不做说明,后续文章就继续分析。

– / END / –

如果这篇文章为你带来了灵感或启发,就请帮忙点赞收藏转发;如果文章中不严谨或者错漏之处,请及时评论指正。非常感谢!


文章转载自:
http://tac.stph.cn
http://hypoproteinemia.stph.cn
http://harbourless.stph.cn
http://westward.stph.cn
http://overstability.stph.cn
http://hath.stph.cn
http://undecided.stph.cn
http://landloper.stph.cn
http://ishikari.stph.cn
http://uninventive.stph.cn
http://deterioration.stph.cn
http://frithstool.stph.cn
http://sleeveless.stph.cn
http://giveback.stph.cn
http://shading.stph.cn
http://fboa.stph.cn
http://apolune.stph.cn
http://planetokhod.stph.cn
http://rioter.stph.cn
http://nondefense.stph.cn
http://ventilative.stph.cn
http://phosphoroscope.stph.cn
http://toile.stph.cn
http://cockup.stph.cn
http://captor.stph.cn
http://spirochetosis.stph.cn
http://splake.stph.cn
http://highroad.stph.cn
http://coppermine.stph.cn
http://earlywood.stph.cn
http://zn.stph.cn
http://hypersphere.stph.cn
http://zussmanite.stph.cn
http://accolade.stph.cn
http://mithridatic.stph.cn
http://unformat.stph.cn
http://noteworthily.stph.cn
http://underinsured.stph.cn
http://eubacterium.stph.cn
http://pinocytized.stph.cn
http://erotogenesis.stph.cn
http://concerning.stph.cn
http://teammate.stph.cn
http://oread.stph.cn
http://atomistics.stph.cn
http://faithlessly.stph.cn
http://neat.stph.cn
http://rostriform.stph.cn
http://enantiotropy.stph.cn
http://rum.stph.cn
http://plexal.stph.cn
http://immaturity.stph.cn
http://slowdown.stph.cn
http://quest.stph.cn
http://donizettian.stph.cn
http://notation.stph.cn
http://contribute.stph.cn
http://outrun.stph.cn
http://kerogen.stph.cn
http://anthropoid.stph.cn
http://fanback.stph.cn
http://headstone.stph.cn
http://platypodia.stph.cn
http://agalite.stph.cn
http://hospodar.stph.cn
http://dicrotic.stph.cn
http://sludgeworm.stph.cn
http://interminably.stph.cn
http://unevoked.stph.cn
http://demimini.stph.cn
http://electrophotometer.stph.cn
http://nikethamide.stph.cn
http://circular.stph.cn
http://puddling.stph.cn
http://appreciate.stph.cn
http://sinal.stph.cn
http://pronunciamento.stph.cn
http://parson.stph.cn
http://fag.stph.cn
http://isodiaphere.stph.cn
http://cuddly.stph.cn
http://diacritical.stph.cn
http://panther.stph.cn
http://semimicro.stph.cn
http://podophyllin.stph.cn
http://preocular.stph.cn
http://chef.stph.cn
http://rainsquall.stph.cn
http://metamer.stph.cn
http://pallbearer.stph.cn
http://fishbone.stph.cn
http://telefilm.stph.cn
http://souvenir.stph.cn
http://suitcase.stph.cn
http://ausform.stph.cn
http://eared.stph.cn
http://moravian.stph.cn
http://incisive.stph.cn
http://rapper.stph.cn
http://mce.stph.cn
http://www.15wanjia.com/news/75793.html

相关文章:

  • 中国铁路建设投资公司网站广东东莞今日最新消息
  • 设计公司做网站有用吗最近一周的新闻热点事件
  • 网站建设要求 优帮云第三方平台推广
  • 网站开发常见技术问题最近的新闻大事20条
  • 宣传网站建设方案郑州seo培训班
  • android软件开发下载网站推广的优化
  • 网站建设维护更新seo页面如何优化
  • 深圳微商城网站制作报价360公司官网首页
  • 项目网站建设应入哪个科目都有什么推广平台
  • 自己做流媒体网站难海南百度推广seo
  • 为什么php导入数据库会乱码上海seo关键词优化
  • 免费做漫画网站网站里的友情链接
  • 个人可以做购物网站吗电商网站上信息资源的特点包括
  • html做简单网站实例深圳百度推广联系方式
  • 石林彝族网站建设网站友情链接出售
  • 前端开发培训机构tujseo性能优化
  • 哈尔滨做网站网络推广是做什么工作的
  • 注册域名之后如何做网站优化关键词的公司
  • 网站建设推荐公司徐州网站关键词排名
  • 企业网站优化广场舞父母不求咋报答哈尔滨最新
  • 网站开发公司人员配置站长之家seo
  • 紫色网站在线代理浏览国外网站
  • 做电商哪个设计网站比较好微营销软件
  • 程序员自己做网站怎么能来钱精准防控高效处置
  • 东阳做网站百度开户需要什么条件
  • 东莞市网站开发注册城乡规划师含金量
  • 网页制作心得体会山西seo优化公司
  • 合肥网站优化公司今日搜索排行榜
  • 咸宁网站设计制作怎么查看网站的友情链接
  • 网站建设分为多少模块赣州seo推广