对PostgreSQL cmin和cmax的理解
看例子:
开两个终端来对比:
在终端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的理解的更多相关文章
- PostgreSQL Replication之第一章 理解复制概念(1)
PostgreSQL Replication系列翻译自PostgreSQL Replication一书 在本章中,将会介绍不同的复制概念,您会了解哪些类型的复制对哪一种实用场景是最合适的. 在本章的最 ...
- PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(5)
2.5 XLOG的内部结构 我们将使用事务贯穿本书,并让您在技术层面上更深地洞察事情是如果工作的,我们已经增加了这部分专门处理XLOG的内部工作机制.我们会尽量避免前往下降到C级,因为这将超出本书的范 ...
- PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(4)
2.4 调整检查点和XLOG 目前为止,这一章已经提供深入洞察PostgreSQL如何写入数据,一般来说,XLOG是用来干什么的.考虑到这方面的知识,我们现在可以继续并学习我们能做些什么来使我们的数据 ...
- PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(3)
2.3 理解一致性和数据丢失 挖掘PostgreSQL事务日志而不考虑一致性是不可能的.在本章的第一部分,我们已经大体上解释了事务日志的基本思想.您已经知道,无需事先的日志改变的能力,使数据处于一种好 ...
- PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(1)
在前面的章节中,我们已经理解了各种复制概念.这不仅仅是一个为了接下来将要介绍的东西而增强您的意识的理论概述,还将为您介绍大体的主题. 在本章,我们将更加接近实际的解决方案,并了解PostgreSQL内 ...
- PostgreSQL Replication之第一章 理解复制概念(3)
1.3 使用分片和数据分配 本节您将了解基本可扩展性技术,例如数据库分片.分片被广泛应用于高端系统并提供一个简单而且可靠的扩展设置方式来向外扩展.近年来,分片已经成为一种扩大专业系统规模的标准方式. ...
- PostgreSQL Replication之第一章 理解复制概念(2)
1.2不同类型的复制 现在,您已经完全地理解了物理和理论的局限性,可以开始学习不同类型的复制了. 1.2.1 同步和异步复制 我们可以做的第一个区分是同步复制和异步复制的区别. 这是什么意思呢?假设我 ...
- PostgreSQL 的 distinct on 的理解
摘录自:http://www.cnblogs.com/gaojian/archive/2012/09/05/2671381.html 对于 select distinct on , 可以利用下面的例子 ...
- PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(2)
2.2 XLOG和复制 在本章中,您已经了解到PostgreSQL的事务日志已经对数据库做了所有的更改.事务日志本身被打包为易用的16MB段. 使用这种更改集来复制数据的想法是不牵强的.事实上,这是在 ...
随机推荐
- 音频(3)Android TTS技术支持朗读英文
Android对TTS技术的支持 Android 1.6开始支持TTS(Text To Speech)技术,通过该技术可以将文本转换成语音.目前2015-09-06只支持朗读英文. TTS技术的核心是 ...
- Android开发UI之给ImageView添加蒙版
ImageView控件添加蒙版, 通过属性:android:tint="" 比如 android:tint="#44ff0000"
- Windows下Vim设置
进入安装目录,找到_vimrc文件,用文本编辑器打开,在前面加入下述内容 设置中文支持 " 设置编码自动识别, 中文引号显示 " set fileencodings=utf-8,c ...
- HTML5学习(五)----SVG
参考教程地址:http://www.w3school.com.cn/html5/html_5_svg.asp HTML5 支持内联 SVG. 什么是SVG? SVG 指可伸缩矢量图形 (Scalabl ...
- Mysql DBA 20天速成教程,DBA大纲
Mysql DBA 20天速成教程 基本知识1.mysql的编译安装2.mysql 第3方存储引擎安装配置方法3.mysql 主流存储引擎(MyISAM/innodb/MEMORY)的特点4.字符串编 ...
- 数据结构———KMP
今天照着课本敲了一下KMP.. 以OJ上的一个题为例敲了一下.. 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem& ...
- poj 2251 Dungeon Master( bfs )
题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A, 上代码 #include <iostream> #include<cst ...
- hdu 1412 (STL list)
简单例题 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1412 list 相关博客:http://www.cnblogs.com/fangyukuan/a ...
- c++ 头文件 及 sort
c++ sort :http://www.16kan.com/post/997260.html http://wenku.baidu.com/view/e064166daf1ffc4ffe47ac6 ...
- UVa 10214 (莫比乌斯反演 or 欧拉函数) Trees in a Wood.
题意: 这道题和POJ 3090很相似,求|x|≤a,|y|≤b 中站在原点可见的整点的个数K,所有的整点个数为N(除去原点),求K/N 分析: 坐标轴上有四个可见的点,因为每个象限可见的点数都是一样 ...