PostgreSQL中的抽象数据类型--Datum

本文深入探讨了PostgreSQL中的Datum抽象数据类型,它是数据库内部表示各种数据的基础。通过解析varlena结构体,揭示了Datum如何存储变长数据,为数据库的高效存储和操作提供支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在学习PostgreSQL的源代码,下面是PostgreSQL中的抽象数据类型(ADT)--Datum的一些相关知识:
datum.h
typedef unsigned int uintptr_t;(stdint.h)
typedef uintptr_t Datum;  (postgres.h)
/*-------------------------------------------------------------------------
 *
 * datum.h
 * POSTGRES Datum (abstract data type) manipulation routines.
 *
 * These routines are driven by the 'typbyval' and 'typlen' information,
 * which must previously have been obtained by the caller for the datatype
 * of the Datum.  (We do it this way because in most situations the caller
 * can look up the info just once and use it for many per-datum operations.)
 *
 * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * src/include/utils/datum.h
 *
 *-------------------------------------------------------------------------
 */
#ifndef DATUM_H
#define DATUM_H


/*
 * datumGetSize - find the "real" length of a datum
 */
extern Size datumGetSize(Datum value, bool typByVal, int typLen);


/*
 * datumCopy - make a copy of a datum.
 *
 * If the datatype is pass-by-reference, memory is obtained with palloc().
 */
extern Datum datumCopy(Datum value, bool typByVal, int typLen);


/*
 * datumFree - free a datum previously allocated by datumCopy, if any.
 *
 * Does nothing if datatype is pass-by-value.
 */
extern void datumFree(Datum value, bool typByVal, int typLen);


/*
 * datumIsEqual
 * return true if two datums of the same type are equal, false otherwise.
 *
 * XXX : See comments in the code for restrictions!
 */
extern bool datumIsEqual(Datum value1, Datum value2,
bool typByVa
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值