一. 前言
openGauss在建表时,系统会自动插入tableoid,cmax,xmax,cmin,xmin,ctid 六个系统隐藏列,在select*的时候也会自动隐藏这6个系统隐藏列,如下所示:
本文主要走读代码了解openGauss是如何实现系统隐藏列的功能的。
二. create table时自动往表中插入系统隐藏列
create table时自动往表中插入系统隐藏列的核心代码入口在heap_create_with_catalog函数中,在往pg_attribute元数据表insert完普通的列后接着insert系统隐藏列的信息,代码流程如下所示:
heap_create_with_catalog
AddNewAttributeTuples
for (i = 0; i < natts; i++) {
InsertPgAttributeTuple(rel, attr, indstate); // 往PG_ATTRIBUTE系统表中插入表的普通字段
}
if (relkind != RELKIND_VIEW && relkind != RELKIND_COMPOSITE_TYPE && relkind != RELKIND_CONTQUERY) {
for (i = 0; i < (int)lengthof(SysAtt); i++) {