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.pswp.cn/news/448961.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/448961.shtml
英文地址,請注明出處:http://en.pswp.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 找到…