Postgresql关于EOH的使用注意

注意通常拿到的指针不是EOH头

EOH是一种扩展数据结构,之前有几篇博客讨论过了,最近在改相关代码加深了一些理解。

EOH目前支持ER_methods、EA_methods两套实现,分别是record类型展开和数组类型展开。

在内存中的样子大概是(EA为例)

复制代码
typedef struct ExpandedArrayHeader
{
	ExpandedObjectHeader hdr;

	int			ea_magic;

	int			ndims;			/* # of dimensions */
	int		   *dims;			/* array dimensions */
	int		   *lbound;			/* index lower bounds for each dimension */

	Oid			element_type;	/* element type OID */
	int16		typlen;			/* needed info about element datatype */
	bool		typbyval;
	char		typalign;
	...
	...
	...
  • 注意:使用时传的不是指向EOH头部的指针,而是使用hdr->eoh_rw_ptr或hdr->eoh_ro_ptr中存放的指针(指向EOH头部)。
  • 注意eoh_rw_ptr和eoh_ro_ptr是1be结构,用DatumGetEOHP函数取出其中存放的指针。

使用时经常需要一层转换,例如这里:

注意使用value的逻辑一般都兼容EOH或valena结构

EOH使用EOH_flatten_into后会拉平数据,输出到result中紧凑存放。

一般的处理逻辑都可以适配EOH或这种紧凑形式,无需互相转换。

这就是为什么EOH只有flatten接口,没有生成EOH的接口,因为使用者适配了。

相关推荐
IvorySQL3 小时前
PostgreSQL 分区表的 ALTER TABLE 语句执行机制解析
数据库·postgresql·开源
Shi_haoliu3 小时前
python安装操作流程-FastAPI + PostgreSQL简单流程
python·postgresql·fastapi
符哥20084 小时前
Ubuntu 常用指令集大全(附实操实例)
数据库·ubuntu·postgresql
l1t5 小时前
DeepSeek总结的PostgreSQL解码GIF文件SQL移植到DuckDB的性能优化方法
sql·postgresql·性能优化
数据知道6 小时前
PostgreSQL 性能优化:分区表实战
数据库·postgresql·性能优化
数据知道7 小时前
PostgreSQL 性能优化:如何提高数据库的并发能力?
数据库·postgresql·性能优化
数据知道7 小时前
PostgreSQL性能优化:内存配置优化(shared_buffers与work_mem的黄金比例)
数据库·postgresql·性能优化
数据知道8 小时前
PostgreSQL 性能优化:连接数过多的原因分析与连接池方案
数据库·postgresql·性能优化
数据知道8 小时前
PostgreSQL性能优化:如何定期清理无用索引以释放磁盘空间(索引膨胀监控)
数据库·postgresql·性能优化
数据知道8 小时前
PostgreSQL 故障排查:万字详解如何找出数据库中的死锁
数据库·postgresql