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的接口,因为使用者适配了。

相关推荐
晚风_END3 小时前
postgresql数据库|pgbouncer连接池压测和直连postgresql数据库压测对比
数据库·postgresql·oracle·性能优化·宽度优先
小芳矶9 小时前
【langgraph+postgres】用于生产环境的langgraph短期记忆的存取(postgreSQL替代InMemorySaver)
数据库·postgresql·语言模型
tfxing9 小时前
使用 PostgreSQL + pgvector 实现 RAG 向量存储与语义检索(Java 实战)
java·数据库·postgresql
瀚高PG实验室9 小时前
HighGo Database判断流复制主备角色的方法
数据库·postgresql·瀚高数据库
l1t9 小时前
DeepSeek总结的 LEFT JOIN LATERAL相关问题
前端·数据库·sql·postgresql·duckdb
__风__9 小时前
PostgreSQL copy的用法
数据库·postgresql
Carry灭霸1 天前
【BUG】PostgreSQL ERROR invalid input syntax for type numeric XXXX
数据库·postgresql
Dxy12393102161 天前
Python批量写入数据到PostgreSQL性能对比
开发语言·python·postgresql
xuefuhe1 天前
postgresql之patroni高可用
数据库·postgresql
惊鸿Randy1 天前
Docker 环境下 PostgreSQL 16 安装 pgvector 向量数据库插件详细教程(Bitnami 镜像)
数据库·docker·postgresql