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

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB 分布式版,标准版 2核8GB
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 标签PostgreSQL , UDT , 自定义类型背景PG 允许用户自定义复合类型,自定义复合类型由多个类型组成,使用时会引入一些deform的开销。例子postgres=# create unlogged table t(id int, c1 tp1, c2 int); C...

标签

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  
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
5月前
|
关系型数据库 Go PostgreSQL
golang pgx自定义PostgreSQL类型
golang的pgx驱动提供了大约70种PostgreSQL类型支持,但还是有一些类型没有涵盖,本文介绍如何自己编写代码支持特殊的类型。
76 3
|
存储 并行计算 Cloud Native
PolarDB 开源版通过pg_rational插件支持Stern-Brocot trees , 实现高效自定义顺序和调整顺序需求
PolarDB 的云原生存算分离架构, 具备低廉的数据存储、高效扩展弹性、高速多机并行计算能力、高速数据搜索和处理; PolarDB与计算算法结合, 将实现双剑合璧, 推动业务数据的价值产出, 将数据变成生产力. 本文将介绍PolarDB 开源版通过pg_rational插件支持Stern-Brocot trees , 实现高效自定义顺序和调整顺序需求.
163 0
|
SQL 监控 关系型数据库
21 PostgreSQL 监控2 趋势监控数据收集和分析 nagios 实时监控部署和自定义监控|学习笔记(三)
快速学习21 PostgreSQL 监控2 趋势监控数据收集和分析 nagios 实时监控部署和自定义监控
254 0
21 PostgreSQL 监控2 趋势监控数据收集和分析 nagios 实时监控部署和自定义监控|学习笔记(三)
PolarDB-X 1.0-用户指南-自定义控制指令-自定义控制指令简介
本文汇总了PolarDB-X支持的辅助SQL指令供您参考。
PolarDB-X 1.0-用户指南-自定义控制指令-帮助语句
您可以通过SHOW HELP帮助语句查看PolarDB-X支持的辅助类SQL语句及语句的详细描述。
126 0
|
存储 SQL 关系型数据库
PolarDB-X 1.0-用户指南-自定义控制指令-查看规则和节点拓扑类语句
本文汇总了PolarDB-X支持的查看规则和节点拓扑类的语句。
196 0
|
SQL 存储 关系型数据库
PolarDB-X 1.0-用户指南-自定义控制指令-SQL 调优类语句
本文汇总了PolarDB-X支持的SQL调优类语句。
186 0
|
SQL 存储 关系型数据库
PolarDB-X 1.0-用户指南-自定义控制指令-统计信息查询类语句
找出需调优的慢SQL后,先通过EXPLAIN查看执行计划,然后通过如下方法优化SQL:下推更多计算至存储层MySQL,适当增加索引,优化执行计划。
267 0
|
SQL 关系型数据库 MySQL
PolarDB-X 1.0-用户指南-自定义控制指令-SHOW PROCESSLIST指令与KILL指令
功能版本说明 当PolarDB-X版本号小于 5.1.28-1408022 时,PolarDB-X仅支持物理连接的 SHOW PROCESSLIST 与 KILL 功能,详情请参见老版本SHOW PROCESSLIST指令与KILL指令。 当PolarDB-X版本号大于或等于 5.1.28-1408022 时,PolarDB-X支持逻辑连接与物理连接的 SHOW PROCESSLIST 与 KILL 功能,请参见本文档。
188 0
|
SQL 关系型数据库 MySQL
PolarDB-X 1.0-用户指南-自定义控制指令-老版本SHOW PROCESSLIST指令与KILL指令
功能版本说明 当 PolarDB-X 版本号小于 5.1.28-1408022 时,PolarDB-X 仅支持物理连接的 SHOW PROCESSLIST 与 KILL 功能,请继续阅读此文档。 当 PolarDB-X 版本号大于等于 5.1.28-1408022 时,PolarDB-X 支持逻辑连接与物理连接的 SHOW PROCESSLIST 与 KILL 功能,请参见SHOW PROCESSLIST 指令与 KILL 指令。 获取 PolarDB-X 版本号,PolarDB-X 自助升级的方法以及更多的版本介绍请参见版本说明文档。
154 0

相关产品

  • 云原生数据库 PolarDB