看例子:

开两个终端来对比:

在终端A:

[pgsql@localhost bin]$ ./psql
psql (9.1.)
Type "help" for help. pgsql=# begin;
BEGIN
pgsql=# select xmin,xmax,cmin,cmax,* from tab01;
xmin | xmax | cmin | cmax | id | cd
------+------+------+------+-----------+----
| | | | |
| | | | |
( rows) pgsql=# insert into tab01 values(,'');
INSERT
pgsql=# insert into tab01 values(,'');
INSERT
pgsql=# select xmin,xmax,cmin,cmax,* from tab01;
xmin | xmax | cmin | cmax | id | cd
------+------+------+------+-----------+----
| | | | |
| | | | |
| | | | |
| | | | |
( rows) pgsql=#

此时的终端B:

[pgsql@localhost bin]$ ./psql
psql (9.1.)
Type "help" for help. pgsql=# select xmin,xmax,cmin,cmax, * from tab01;
xmin | xmax | cmin | cmax | id | cd
------+------+------+------+-----------+----
| | | | |
| | | | |
( rows) pgsql=#

然后再在终端A进行提交:

pgsql=# commit;
COMMIT
pgsql=# select xmin,xmax,cmin,cmax,* from tab01;
xmin | xmax | cmin | cmax | id | cd
------+------+------+------+-----------+----
| | | | |
| | | | |
| | | | |
| | | | |
( rows) pgsql=#

此时,再在终端B进行观察:

pgsql=# select xmin,xmax,cmin,cmax, * from tab01;
xmin | xmax | cmin | cmax | id | cd
------+------+------+------+-----------+----
| | | | |
| | | | |
| | | | |
| | | | |
( rows) pgsql=#

继续研究cmin是咋回事:

pgsql=# begin;
BEGIN
pgsql=# insert into tab01(id,cd) values(generate_series(,),'xx');
INSERT
pgsql=# select xmin,xmax,cmin,cmax,* from tab01;
xmin | xmax | cmin | cmax | id | cd
------+------+------+------+-----------+----
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | xx
| | | | | xx
( rows) pgsql=#

可以说cmin可理解为一个事务里,执行了几次sql命令的顺序。

那么cmax呢?在前面的基础上继续执行,居然没有看到区别:

pgsql=# update tab01 set id= where cd = '';
UPDATE
pgsql=# select xmin,xmax,cmin,cmax,* from tab01;
xmin | xmax | cmin | cmax | id | cd
------+------+------+------+----+----
| | | | |
| | | | |
| | | | |
| | | | | xx
| | | | | xx
| | | | |
( rows) pgsql=# commit;
COMMIT
pgsql=# select xmin,xmax,cmin,cmax,* from tab01;
xmin | xmax | cmin | cmax | id | cd
------+------+------+------+----+----
| | | | |
| | | | |
| | | | |
| | | | | xx
| | | | | xx
| | | | |
( rows) pgsql=#

经过反复折腾,终于发现,其实 cmin和 cmax就是一个东西:

看源代码:

/* ----------------
* heap_getsysattr
*
* Fetch the value of a system attribute for a tuple.
*
* This is a support routine for the heap_getattr macro. The macro
* has already determined that the attnum refers to a system attribute.
* ----------------
*/
Datum
heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
{
Datum result; Assert(tup); /* Currently, no sys attribute ever reads as NULL. */
*isnull = false; switch (attnum)
{
case SelfItemPointerAttributeNumber:
/* pass-by-reference datatype */
result = PointerGetDatum(&(tup->t_self));
break;
case ObjectIdAttributeNumber:
result = ObjectIdGetDatum(HeapTupleGetOid(tup));
break;
case MinTransactionIdAttributeNumber:
result = TransactionIdGetDatum(HeapTupleHeaderGetXmin(tup->t_data));
break;
case MaxTransactionIdAttributeNumber:
result = TransactionIdGetDatum(HeapTupleHeaderGetXmax(tup->t_data));
break;
case MinCommandIdAttributeNumber:
case MaxCommandIdAttributeNumber: /*
* cmin and cmax are now both aliases for the same field, which
* can in fact also be a combo command id. XXX perhaps we should
* return the "real" cmin or cmax if possible, that is if we are
* inside the originating transaction?
*/

result = CommandIdGetDatum(HeapTupleHeaderGetRawCommandId(tup->t_data));
break;
case TableOidAttributeNumber:
result = ObjectIdGetDatum(tup->t_tableOid);
break;
default:
elog(ERROR, "invalid attnum: %d", attnum);
result = ; /* keep compiler quiet */
break;
}
return result;
}

对PostgreSQL cmin和cmax的理解的更多相关文章

  1. PostgreSQL Replication之第一章 理解复制概念(1)

    PostgreSQL Replication系列翻译自PostgreSQL Replication一书 在本章中,将会介绍不同的复制概念,您会了解哪些类型的复制对哪一种实用场景是最合适的. 在本章的最 ...

  2. PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(5)

    2.5 XLOG的内部结构 我们将使用事务贯穿本书,并让您在技术层面上更深地洞察事情是如果工作的,我们已经增加了这部分专门处理XLOG的内部工作机制.我们会尽量避免前往下降到C级,因为这将超出本书的范 ...

  3. PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(4)

    2.4 调整检查点和XLOG 目前为止,这一章已经提供深入洞察PostgreSQL如何写入数据,一般来说,XLOG是用来干什么的.考虑到这方面的知识,我们现在可以继续并学习我们能做些什么来使我们的数据 ...

  4. PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(3)

    2.3 理解一致性和数据丢失 挖掘PostgreSQL事务日志而不考虑一致性是不可能的.在本章的第一部分,我们已经大体上解释了事务日志的基本思想.您已经知道,无需事先的日志改变的能力,使数据处于一种好 ...

  5. PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(1)

    在前面的章节中,我们已经理解了各种复制概念.这不仅仅是一个为了接下来将要介绍的东西而增强您的意识的理论概述,还将为您介绍大体的主题. 在本章,我们将更加接近实际的解决方案,并了解PostgreSQL内 ...

  6. PostgreSQL Replication之第一章 理解复制概念(3)

    1.3 使用分片和数据分配 本节您将了解基本可扩展性技术,例如数据库分片.分片被广泛应用于高端系统并提供一个简单而且可靠的扩展设置方式来向外扩展.近年来,分片已经成为一种扩大专业系统规模的标准方式. ...

  7. PostgreSQL Replication之第一章 理解复制概念(2)

    1.2不同类型的复制 现在,您已经完全地理解了物理和理论的局限性,可以开始学习不同类型的复制了. 1.2.1 同步和异步复制 我们可以做的第一个区分是同步复制和异步复制的区别. 这是什么意思呢?假设我 ...

  8. PostgreSQL 的 distinct on 的理解

    摘录自:http://www.cnblogs.com/gaojian/archive/2012/09/05/2671381.html 对于 select distinct on , 可以利用下面的例子 ...

  9. PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(2)

    2.2 XLOG和复制 在本章中,您已经了解到PostgreSQL的事务日志已经对数据库做了所有的更改.事务日志本身被打包为易用的16MB段. 使用这种更改集来复制数据的想法是不牵强的.事实上,这是在 ...

随机推荐

  1. Tiny4412之C语言实现流水灯,Tiny4412裸机程序[3]

    在前边我们使用汇编完成了一个流水灯实验: Tiny4412汇编流水灯代码,Tiny4412裸机LED操作 ---- - -- -- -- - -- -- 修改: # ${MKBL2} ${SOURCE ...

  2. 安装安装.net framework过程中出现的问题

    1.安装Microsoft..net framework2.0 SP2 出现 必须使用控制面板中的打开或关闭windows功能,安装或配置.net framework2.0 SP2 原因:可以打开控制 ...

  3. PL/SQL Developer使用技巧

    1.PL/SQL Developer记住登陆密码 在使用PL/SQL Developer时,为了工作方便希望PL/SQL Developer记住登录Oracle的用户名和密码: 设置方法:PL/SQL ...

  4. JAVA高级特性 - 注解

    注解是插入到代码中用于某种工具处理的标签.这些标签可以在源码层次上进行操作,或者可以处理编译器将其纳入到注解类文件中. 注解不会改变对程序的编译方式.Java编译器会对包含注解和不包含注解的代码生成相 ...

  5. sencha touch 2 tabpanel中List的不显示问题,解决方案

    笔者在做sencha项目的时候碰到一个需求,就是"好友列表"中分为"未确认好友"和"已确认好友",两个都是一个list,自然想到的就是使用t ...

  6. PHP超大文件下载,断点续传下载

    源代码: <?php $sourceFile = "1.tmp"; //要下载的临时文件名 $outFile = "用户订单.xls"; //下载保存到客 ...

  7. PHP内置的Web Server的使用

    自PHP5.4之后 PHP内置了一个Web 服务器. 让我们来看看php Web Server的简单使用: 启动php Web Server php -S localhost:8080 通过 php ...

  8. JVM问题定位工具

    JDB JDB是基于文本和命令行的调试工具,Jikes在JDB的基础上提供了GUI.熟悉JDB还是有价值的,很多情况下需要我们在命令行下完成简单的debug问题定位. 1 2 3 jdb -class ...

  9. 【转】android开发工具Eclipse,androidStudio,adt网盘下载--不错

    原文网址:http://tools.android-studio.org/index.php/85-tools/109-android-tools-download

  10. css页面重构面试题

    偶然间又看到博客园中这两道页面重构面试题.题一:分别用2个DIV,3个DIV,5个DIV实现水平垂直均居中显示一个宽50px,高200px的正十字架.思路:水平垂直均居中的实现,当然非absolute ...