PostgreSQL 自定义复合类型(composite type) deform引入的额外开销

标签

PostgreSQL , UDT , 自定义类型


背景

PG 允许用户自定义复合类型,自定义复合类型由多个类型组成,使用时会引入一些deform的开销。

例子

postgres=# create unlogged table t(id int, c1 tp1, c2 int);  
CREATE TABLE  postgres=# insert into t select id, '(1,2,3,4,5)'::tp1, id from generate_series(1,10000000) t(id);  
INSERT 0 10000000  postgres=# select pg_backend_pid();  pg_backend_pid   
----------------  57357  
(1 row)  

deform 引入一定开销

postgres=# explain (analyze,verbose,timing,costs,buffers) select max((t.c1).a) from t;  QUERY PLAN                                                            
-----------------------------------------------------------------------------------------------------------------------------  Aggregate  (cost=23931.62..23931.62 rows=1 width=4) (actual time=3020.162..3020.163 rows=1 loops=1)  Output: max((c1).a)  Buffers: shared hit=25707  ->  Seq Scan on public.t  (cost=0.00..2256.77 rows=10000000 width=41) (actual time=0.019..1310.990 rows=10000000 loops=1)  Output: id, c1, c2  Buffers: shared hit=25707  Planning Time: 0.083 ms  Execution Time: 3020.199 ms  
(8 rows)  
postgres=# explain (analyze,verbose,timing,costs,buffers) select max(c2) from t;  QUERY PLAN                                                           
----------------------------------------------------------------------------------------------------------------------------  Aggregate  (cost=23931.62..23931.62 rows=1 width=4) (actual time=2613.945..2613.946 rows=1 loops=1)  Output: max(c2)  Buffers: shared hit=25707  ->  Seq Scan on public.t  (cost=0.00..2256.77 rows=10000000 width=4) (actual time=0.017..1281.070 rows=10000000 loops=1)  Output: id, c1, c2  Buffers: shared hit=25707  Planning Time: 0.073 ms  Execution Time: 2613.980 ms  
(8 rows)  

perf 跟踪

perf top -p 57357 -ag  

自定义复合类型,引入开销 slot_deform_tuple

Samples: 4K of event 'cpu-clock', Event count (approx.): 710891745        Children      Self  Shared Objec  Symbol                                
+   13.71%    13.71%  postgres      [.] ExecInterpExpr                    
+   10.66%    10.66%  postgres      [.] slot_deform_tuple                 
+   10.27%    10.27%  postgres      [.] heap_getnext                      
+    7.54%     7.54%  postgres      [.] ExecEvalFieldSelect               
+    7.09%     7.09%  postgres      [.] HeapTupleSatisfiesMVCC            
+    5.09%     5.09%  postgres      [.] AllocSetAlloc                     
+    4.89%     4.89%  postgres      [.] MemoryContextReset                
+    4.29%     4.29%  postgres      [.] ExecScan                          
+    3.73%     3.73%  postgres      [.] slot_getsomeattrs                 
+    3.69%     3.69%  postgres      [.] heapgetpage                       
+    3.36%     3.36%  postgres      [.] XidInMVCCSnapshot                 
+    3.13%     3.13%  postgres      [.] AllocSetReset                     
+    2.87%     2.87%  postgres      [.] heap_tuple_untoast_attr           
+    2.82%     2.82%  postgres      [.] SeqNext                           
+    2.80%     2.80%  libc-2.17.so  [.] __memset_sse2                     
+    2.66%     2.66%  libc-2.17.so  [.] __memcpy_ssse3_back               
+    2.56%     2.56%  postgres      [.] ExecAgg                           
+    2.54%     2.54%  postgres      [.] ExecStoreTuple                    
+    1.83%     1.83%  postgres      [.] palloc                            
+    0.93%     0.93%  postgres      [.] TransactionIdFollowsOrEquals      
+    0.68%     0.68%  postgres      [.] int4larger                        
+    0.58%     0.58%  postgres      [.] hash_search_with_hash_value       0.47%     0.47%  postgres      [.] TransactionIdPrecedes             0.33%     0.33%  postgres      [.] ExecSeqScan                       0.33%     0.33%  postgres      [.] pg_detoast_datum                  0.31%     0.31%  postgres      [.] CheckForSerializableConflictOut   0.23%     0.23%  postgres      [.] heap_page_prune_opt               0.12%     0.12%  postgres      [.] memset@plt                        0.08%     0.08%  postgres      [.] ResourceOwnerForgetBuffer         0.08%     0.08%  postgres      [.] LWLockAcquire                     0.08%     0.08%  postgres      [.] PinBuffer                         0.04%     0.04%  postgres      [.] LWLockRelease                     0.04%     0.04%  postgres      [.] UnpinBuffer.constprop.6           0.04%     0.04%  postgres      [.] hash_any                          0.02%     0.02%  [kernel]      [k] sock_def_readable                 0.02%     0.02%  postgres      [.] memcpy@plt                        0.02%     0.02%  postgres      [.] ReadBuffer_common                 0.02%     0.02%  postgres      [.] RecoveryInProgress                0.02%     0.02%  postgres      [.] ReleaseBuffer                     0.02%     0.02%  postgres      [.] isTempToastNamespace  

内部字段perf输出

Samples: 3K of event 'cpu-clock', Event count (approx.): 811125000     Children      Self  Shared O  Symbol                                 
+   18.74%    18.74%  postgres  [.] slot_deform_tuple                  
+   18.26%    18.26%  postgres  [.] ExecInterpExpr                     
+   12.54%    12.54%  postgres  [.] heap_getnext                       
+   11.62%    11.62%  postgres  [.] HeapTupleSatisfiesMVCC             
+    4.96%     4.96%  postgres  [.] ExecScan                           
+    4.91%     4.91%  postgres  [.] slot_getsomeattrs                  
+    4.75%     4.75%  postgres  [.] ExecAgg                            
+    4.10%     4.10%  postgres  [.] SeqNext                            
+    4.02%     4.02%  postgres  [.] heapgetpage                        
+    4.02%     4.02%  postgres  [.] MemoryContextReset                 
+    3.61%     3.61%  postgres  [.] XidInMVCCSnapshot                  
+    3.34%     3.34%  postgres  [.] ExecStoreTuple                     
+    1.27%     1.27%  postgres  [.] int4larger                         
+    0.94%     0.94%  postgres  [.] TransactionIdFollowsOrEquals       
+    0.70%     0.70%  postgres  [.] TransactionIdPrecedes              
+    0.65%     0.65%  postgres  [.] hash_search_with_hash_value        0.40%     0.40%  postgres  [.] CheckForSerializableConflictOut    0.38%     0.38%  postgres  [.] ExecSeqScan                        0.27%     0.27%  postgres  [.] heap_page_prune_opt                0.11%     0.11%  postgres  [.] ReadBufferExtended                 0.08%     0.08%  postgres  [.] PinBuffer                          0.08%     0.08%  postgres  [.] UnpinBuffer.constprop.6            0.05%     0.05%  postgres  [.] LWLockAcquire                      0.05%     0.05%  postgres  [.] LWLockRelease                      0.05%     0.05%  postgres  [.] ResourceOwnerForgetBuffer          0.03%     0.03%  [kernel]  [k] rebalance_domains                  0.03%     0.03%  postgres  [.] LockBuffer                         0.03%     0.03%  postgres  [.] ReleaseBuffer  

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/448961.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第十二周作业

这个作业属于那个课程c语言这个作业要求在哪里https://edu.cnblogs.com/campus/zswxy/computer-scienceclass4-2018/homework/3236我在这个课程的目标是学习掌握单向链表,掌握二级指针的概念,以及指针数组这个作业在哪个具体方面帮助我实现目标前面3道题…

职场上的「小人」教我的事

很多人的小指头都会带一个尾戒,不是白金就是黄金,大部份是简单的一环,没有太多装饰,也很少镶宝石,目的不在于当作饰品,而是保命之用。 也有人不习惯戴尾戒,而是把指甲留得长长的,长到…

【Quartz】插件的使用

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。 Quartz 框架提供了几种用于扩展平台能力的方式。通过使用各种 "钩子" (通常指的就是扩展点),Quartz 变得很容易被扩…

自动化运维平台(前端vue)

前端的大体流程:首先是Login登录组件,当输入用户名和密码之后,发送post请求到后端,然后根据返回的数据的是否正常,如果正常,将返回的token以及用户名保存到sessionStorage中,并使用导航守卫进行…

老程序员的下场

长期从事编程活动的程序员都期望在50多岁时能爬到一个足够高的职位,或者能顺利的退休。 但我在这里讨论的可能是一个你还没有想过的问题:如果到那时你失业了呢? 50多岁时你的职业仕途会成为一个问题。如果你有很好的技术,有人雇…

Quartz 之入门示例

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。 环境:XPMyeclipse6.5JDK1.6 quartz官网:http://www.quartz-scheduler.org/ 参考资料 1 Quartz任务调度快速入门 http://www.blogjava…

CSS3最颠覆性的动画效果,基本属性[3D]

和2D一样也是transform 即变形 1)rotateX rotateY rotateZ(也可以用transform-origin来设置旋转中心点) 2)透视(perspective) 给父亲加透视,透视就是模拟眼睛到物体的距离,近大远小,即数值越小,3D越明显 理…

解决报错 :A component required a bean of type ‘gentle.test.Show‘ that could not be found

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。 1. 启动工程失败,报错如题: A component required a bean of type gentle.test.Show that could not be found.…

30天提升技术人的写作力-第十七天

约束作者在漫长的创作过程中,不偏离写作目标。当写的字数在十几万以上时,没有先规划,就会陷入混乱,发生注入重复、疏漏、相关知识未讲解等问题。制作长文章或书籍的大纲,需要使用发散收敛工具。所谓发散是多方向、多思…

白领必看的十种职场致命毒药

找到一个合适的工作可能需要3到15个月不等的时间——然而丢掉饭碗只需要几天或几周。下面是10种职场毒药的特点:       1、人际交往技能不佳       讨人喜欢会大有帮助。研究均表明和那些能力强而呆板的人相比,人们一致而且不可遏制地更喜欢和…

eclipse中folder、source folder和package的区别

今天做ssm项目时,突然发现了这个问题,特别好奇,sqlSessionFactory.xml文件如何找到: 1、放在src/hello目录下: InputStream inputStream Resources.getResourceAsStream("./hello/sqlMapperConfig.xml"); 2…

解决.quartz.ObjectAlreadyExistsException: Unable to store Job : ‘jyGroup.jyJob‘, because one already

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。 1. 报错如题: 定时任务出现异常 : org.quartz.ObjectAlreadyExistsException: Unable to store Job : jyGroup.…

WeMos-D1R2的使用

2019独角兽企业重金招聘Python工程师标准>>> WeMos介绍 WeMos-D1R2一个基于ESP8266-12 Wifi模块的Arduino-UNO开发板。也就是说,WeMos-D1R2是一个具有wifi功能的Arduino开发板,但WeMos-D1R2与Arduino-UNO的引脚不是一一对应的,其对…

职场中什么样的员工最易发展?

职场中什么样的员工最“抢手”?也许你会说有能力的人,没错有能力的人竞争力一定很强,但是能力会随着经验的丰富而慢慢变强,所以它不足以某个人在职场中站稳脚主要原因,反而是一个人的工作态度决定着他在职场中的发展方向与前景。…

PAT 1048 数字加密

题目链接 一开始我还以为以b的长度为基准,因为b是要加密的数据啊,看了答案才知道原来要以最长的长度为基准。但是这道题还有个bug,就是当你算出的结果前面有0竟然也可以通过,比如a为1111,b为1111,答案是020…

RabbitMQ MQTT协议和AMQP协议

RabbitMQ MQTT协议和AMQP协议 1 序言... 1 1.1 RabbitMq结构... 1 1.2 RabbitMq消息接收... 4 1.3 Exchange种类和消息发送模式... 4 1.4 RabbitMq的协议... 6 1.4.1 AMQP协议... 6 1.4.2 MQTT协议... 8 2 RabbitMq服务器安装和使用…

Quartz 定时任务(Scheduler)的 3 种实现方式

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 PS&#xff1a;第 3 种最简单。 一、引入 jar 。 <!-- quartz 定时任务调度 --><dependency><groupId>org.springfr…

加速财务自由的7种理财方法

有人说财务自由是个遥不可及的路&#xff0c;有人却觉得想要在财务上成功很简单&#xff0c;到底财务自由有没有一个正确的方法或是被证明的技巧可以被实现&#xff1f;如果你现在还没达成或是正在达成&#xff0c;底下这7种简单有效的行动与方法可以加速你建构财务自由之路。 …

Code Chef December Challenge 2018题解

传送门 \(MAXEP\) 二分&#xff0c;不过二分的时候要注意把\(mid\)设成\(\left\lfloor{9lr\over 10}\right\rfloor\)&#xff0c;这样往右的次数不会超过\(6\)次 //minamoto #include<bits/stdc.h> #define R register #define inline __inline__ __attribute__((always_…

Git 安装及 idea 配置 Git

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 1.git官网下载地址&#xff1a;点此跳转git官网 git具体安装不做详细叙述。 2.打开idea 点击Configure -> Settings 3.选择Git 找到…