看例子:

开两个终端来对比:

在终端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. HTML5学习(九)----应用程序缓存

    参考教程:http://www.w3school.com.cn/html5/html_5_app_cache.asp 使用 HTML5,通过创建 cache manifest 文件,可以轻松地创建 w ...

  2. CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)

    题目:http://codeforces.com/problemset/problem/135/B 题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形. 输出 第一行是正方形 ,第二行 ...

  3. [原]Unity3D深入浅出 - 认识开发环境中的Component(组件)菜单

    Component(组件)是用来添加到GameObject对象上的一组相关属性,本质上每个组件都是一个类的实例,比如在Cube上添加一个Mesh网格,即面向对象的思维方式可以理解成Cube对象里包含了 ...

  4. [原]Unity3D深入浅出 - 认识开发环境中的RenderSettings面板

    点击菜单栏的Edit项里的RenderSettings即可打开该面板. Fog:在Scene中开启雾效果 Fog Color:雾的颜色 Fog Mode:雾效果的模式,Linear(线性雾效果) Ex ...

  5. Unity3D集成SVN进行版本控制

    首先,AssetServer确实很好用,Unity内部集成的管理界面,操作很简单,提交冲突的后还可以进行文件比对.但学习使用过程中,发现文件体积较大的项目文件目录(600M),我提交不上去,会返回没有 ...

  6. 请用一句话概括JSONP

    服务器调用客户端的函数(即回调函数),在客户端就能拿到服务端传入的参数(即返回结果)

  7. 读取Excel任务列表并显示在Outlook日历上

    前几天,公司发了一个任务安排,时间不固定,但要求准时到,为了给自己加一个提醒,也为了回顾一下以前的技术,特做了一个Demo. 读取Excel就不多说了,代码很简单,但支持老版本Excel和的版本Exc ...

  8. HDU Senior's Gun (水题)

    题意: 给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路: 用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都 ...

  9. 如何在Azure Websites中配置PHP从而改变系统默认时区

    Shirley_Wang  Tue, Mar 3 2015 7:29 AM Azure Website为我们提供了可高度扩展的网站部署平台.由于Website是PaaS(平台即服务)层的服务,当用户把 ...

  10. Android开发优化宝典

    I. 网络相关 http头信息带Cache-Control域 确定缓存过期时间 防止重复请求 直接用IP直连,不用域名,策略性跟新本地IP列表. – DNS解析过程耗时在百毫秒左右,并且还有可能存在D ...