1)创建了一个表

apple=# \d test_time
Table "public.test_time"
Column | Type | Modifiers
--------+-----------------------------+-----------
id | integer |
date | timestamp without time zone |

2)查看该表的所有字段 包括隐藏的:

apple=# select * from pg_attribute where attrelid in (select oid from pg_class where relname = 'test_time');
attrelid | attname | atttypid | attstattarget | attlen | attnum | attndims | attcacheoff | atttypmod | attbyval | attstorage | attalign | attnotnull | atthasdef | attisdropped | attislocal | attinhcount | attcollation | attacl | attoptions | attfdwoptions
----------+----------+----------+---------------+--------+--------+----------+-------------+-----------+----------+------------+----------+------------+-----------+--------------+------------+-------------+--------------+--------+------------+---------------
33433 | tableoid | 26 | 0 | 4 | -7 | 0 | -1 | -1 | t | p | i | t | f | f | t | 0 | 0 | | |
33433 | cmax | 29 | 0 | 4 | -6 | 0 | -1 | -1 | t | p | i | t | f | f | t | 0 | 0 | | |
33433 | xmax | 28 | 0 | 4 | -5 | 0 | -1 | -1 | t | p | i | t | f | f | t | 0 | 0 | | |
33433 | cmin | 29 | 0 | 4 | -4 | 0 | -1 | -1 | t | p | i | t | f | f | t | 0 | 0 | | |
33433 | xmin | 28 | 0 | 4 | -3 | 0 | -1 | -1 | t | p | i | t | f | f | t | 0 | 0 | | |
33433 | ctid | 27 | 0 | 6 | -1 | 0 | -1 | -1 | f | p | s | t | f | f | t | 0 | 0 | | |
33433 | id | 23 | -1 | 4 | 1 | 0 | -1 | -1 | t | p | i | f | f | f | t | 0 | 0 | | |
33433 | date | 1114 | -1 | 8 | 2 | 0 | -1 | -1 | t | p | d | f | f | f | t | 0 | 0 | | |
(8 rows)

可以发现有6个隐藏的字段,其中cmax xmax cmin xmin都跟事物有关,在PG事物处理相关文章中可以经常看到。

恰好前段时间研究PG表去重复数据用过ctid,物理地址块上的编号,因此今天再来学习一下tableoid。

3)初步分析结果:

A. 存磁盘的时候,数据是一行一行的存储,有必要知道该行数据属于哪个表。(那么如果支持列存储的话,确实可以对这些数据进行压缩了,只存一条即可。)

B. 继承表的情况,知道数据是在哪个子表里面。

4)视图不会有默认字段:

apple=# select * from pg_attribute where attrelid in (select oid from pg_class where relname in (select viewname from pg_views)) and attnum < 0;
attrelid | attname | atttypid | attstattarget | attlen | attnum | attndims | attcacheoff | atttypmod | attbyval | attstorage | attalign | attnotnull | atthasdef | attisdropped | attislocal | attinhcount | attcollation | attacl | attoptions | attfdwoptions
----------+---------+----------+---------------+--------+--------+----------+-------------+-----------+----------+------------+----------+------------+-----------+--------------+------------+-------------+--------------+--------+------------+---------------
(0 rows)

5)以后想查看表的oid再也不用去pg_class里面找了:

apple=# select tableoid from test_time;
tableoid
----------
33433
(1 row)

搞了半天发现也没啥,白折腾了......

-----------------------

在创建表的时候,可以选择是否创建有OID的隐藏列:create table xxx (id int,...) with oids;

apple=# create table test_without_oid(id int, info text, crt_time timestamp) without oids;
CREATE TABLE
apple=# select oid, * from test_without_oid ;
ERROR: column "oid" does not exist
LINE 1: select oid, * from test_without_oid ;
^
HINT: Perhaps you meant to reference the column "test_without_oid.id".
apple=# select * from test_without_oid ;
id | info | crt_time
----+------+----------
(0 rows) apple=# create table test_with_oid(id int, info text, crt_time timestamp) with oids;
CREATE TABLE
apple=# select oid, * from test_with_oid ;
oid | id | info | crt_time
-----+----+------+----------
(0 rows)

参考消息:

每个表都有几个系统字段,这些字段是由系统隐含定义的。 因此,这些名字不能用于用户定义的字段名。 (请注意这些限制与这个名字是否关键字无关;把名字用引号括起来并不能让你逃离这些限制。) 你实际上不需要注意这些字段,只要知道它们存在就可以了。

oid
行的对象标识符(对象 ID)。这个字段只有在创建表的时候使用了 WITH OIDS,或者是设置了配置参数 default_with_oids 时出现。 这个字段的类型是 oid(和字段同名); 参阅Section 8.12 获取有关这种类型的更多信息。
tableoid
包含本行的表的 OID。这个字段对那些从继承层次中选取的查询特别有用(参阅 Section 5.8), 因为如果没有它的话,我们就很难说明一行来自哪个独立的表。 tableoid 可以和pg_class 的 oid 字段连接起来获取表名字。

xmin
插入该行版本的事务的标识(事务 ID)。(注意:在这个环境里, 一个行版本是一行的一个状态;一行的每次更新都为同一个逻辑行创建一个新的行版本。)

cmin
在插入事务内部的命令标识(从零开始)。

xmax
删除事务的标识(事务ID),如果不是被删除的行版本,那么是零。 在一个可见行版本里,这个字段有可能是非零。这通常意味着删除事务还没有提交, 或者是一个删除的企图被回滚掉了。

cmax
在删除事务内部的命令标识符,或者是零。

ctid
一个行版本在它所处的表内的物理位置。请注意,尽管 ctid 可以用于非常快速地定位行版本,但每次 VACUUM FULL 之后, 一个行的 ctid 都会被更新或者移动。 因此 ctid 是不能作为长期的行标识符的。 应该使用OID,或者更好是用户定义的序列号,来标识一个逻辑行。

PostgreSQL隐藏字段的更多相关文章

  1. PostgreSQL隐藏字段tableoid

    问题来源: 今天群里有人问:tableoid字段在每行都有,而且一个表里面的值是重复的,这样不合理...... 因此做了一些分析: 1)创建了一个表 apple=# \d test_time Tabl ...

  2. 无废话ExtJs 入门教程九[数字字段:NumberField、隐藏字段Hidden、日期字段:DataFiedl]

    无废话ExtJs 入门教程九[数字字段:NumberField.隐藏字段Hidden.日期字段:DataFiedl] extjs技术交流,欢迎加群(201926085) 继上第六节内容,我们在表单里加 ...

  3. <记录>TP5 关联模型使用(嵌套关联、动态排序以及隐藏字段)

    在数据库设计中,常常会有如下这种关联模型,分类表中一条分类对应多个商品表中的商品 如果要获得分类表中每条分类 以及 对应的商品的信息,则需要先查询分类表中的数据,然后根据结果遍历查询商品表,最后把数据 ...

  4. TP5 关联模型使用(嵌套关联、动态排序以及隐藏字段)

    在数据库设计中,常常会有如下这种关联模型,分类表中一条分类对应多个商品表中的商品 如果要获得分类表中每条分类 以及 对应的商品的信息,则需要先查询分类表中的数据,然后根据结果遍历查询商品表,最后把数据 ...

  5. Spring MVC隐藏字段域

    以下示例显示如何在使用Spring Web MVC框架的表单中使用隐藏字段(Hidden).首先使用Eclipse IDE来创建一个WEB工程,实现在隐藏字段中指定用户编号的功能.并按照以下步骤使用S ...

  6. Spring MVC-表单(Form)标签-隐藏字段(Hidden Field)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_hidden.htm 说明:示例基于Spring MVC 4.1.6. 以下示例显 ...

  7. 验证ogg同步数据库表无主键表且目标表包含隐藏字段

    问题描述: 已知:OGG在同步无主键的表时,OGG会自动设置表的全字段为主键,若目标表字段多于源表,同步过程中replicat进程可以读取insert操作但无法进行update/delete操作,从而 ...

  8. 【HANA系列】SAP HANA SLT 在表中隐藏字段并传入HANA的方法

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SLT在表中隐 ...

  9. 【HANA系列】SAP HANA SLT在表中隐藏字段并传入HANA的方法

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SLT在表中隐 ...

随机推荐

  1. 【Git】pull遇到错误:error: Your local changes to the following files would be overwritten by merge:

    这种情况下,如何保留本地的修改同时又把远程的合并过来呢? 首先取决于你是否想要保存本地修改.(是 /否) 是 git stash git pull origin master git stash po ...

  2. python pycharm 正则表达式批量替换

    {accept:application/json, text/plain, */*,accept-encoding:gzip, deflate, br,accept-language:zh-CN,zh ...

  3. Python3.7 lxml引入etree

    用xml代替lxml,Python3.7中已经没有etree这个模块了 import xml.etree.ElementTree as etree from lxml import etree 这种方 ...

  4. Python入门学习指南

    对于初学者,入门至关重要,这关系到初学者是从入门到精通还是从入门到放弃.以下是结合Python的学习经验,整理出的一条学习路径,主要有四个阶段 NO.1 新手入门阶段,学习基础知识 总体来讲,找一本靠 ...

  5. Spring Boot 2.x基础教程:使用Elastic Job实现定时任务

    上一篇,我们介绍了如何使用Spring Boot自带的@Scheduled注解实现定时任务.文末也提及了这种方式的局限性.当在集群环境下的时候,如果任务的执行或操作依赖一些共享资源的话,就会存在竞争关 ...

  6. EasyUI:combotree(树形下拉框)复选框选中父节点(子节点的状态也全部选中)输入框中只显示父节点的文本值

    参考: https://blog.csdn.net/weixin_43236850/article/details/100320564

  7. js检测客户端是否安装

    前言 需求背景:一个web下载页面,需要检测pc是否安装了客户端软件(windows软件).网页上有一个打开客户端按钮.若安装了客户端软件,则直接打开,否则下载软件.支持web下载页面在iframe下 ...

  8. PAT甲级:1124 Raffle for Weibo Followers (20分)

    PAT甲级:1124 Raffle for Weibo Followers (20分) 题干 John got a full mark on PAT. He was so happy that he ...

  9. 【洛谷P2041 分裂游戏】数学+瞎蒙

    分析 我们推不出n=3的图,开始猜测,答案在n>2时无解.(<-正解) AC代码 #include <bits/stdc++.h> using namespace std; i ...

  10. C++ 定义默认值void locals_index(int reg, int offset = 1);

    看jvm源码的时候怎么也看不懂,来回看了几次了就是关于iload 6 指令的解析 def(Bytecodes::_lload , ubcp|____|____|____, vtos, ltos, ll ...