postgresql里cmin与cmax有何不同.md
- 在这之前,做个与cmin和cmax相关的实验:
之前已经说过, cmin与cmax代表同一个事务里,该行记录所对应的sql执行的顺序,下面验证下
// 当前 user_info 表的信息,当前有5条记录。 cmin 与 cmax都是0
//原先已经存在的记录:
postgres=# select ctid,cmin,cmax,xmin,xmax,* from user_info ;ctid | cmin | cmax | xmin | xmax | id | info
-------+------+------+-------+------+----+------(0,1) | 0 | 0 | 36039 | 0 | 1 | test(0,2) | 0 | 0 | 36039 | 0 | 1 | test(0,3) | 0 | 0 | 36039 | 0 | 1 | test(0,4) | 0 | 0 | 36039 | 0 | 1 | test(0,5) | 0 | 0 | 36039 | 0 | 1 | test
(5 rows)// 同一个事务里,用4条sql插入4条语句:
postgres=# begin;
BEGIN
postgres=# insert into user_info(id,info) values(1,'test');
INSERT 0 1
postgres=# insert into user_info(id,info) values(1,'test');
INSERT 0 1
postgres=# insert into user_info(id,info) values(1,'test');
INSERT 0 1
postgres=# insert into user_info(id,info) values(1,'test');
INSERT 0 1
postgres=# commit;
COMMIT//查询结果:
postgres=# select ctid,cmin,cmax,xmin,xmax,* from user_info ;ctid | cmin | cmax | xmin | xmax | id | info
--------+------+------+-------+------+----+------(0,1) | 0 | 0 | 36039 | 0 | 1 | test(0,2) | 0 | 0 | 36039 | 0 | 1 | test(0,3) | 0 | 0 | 36039 | 0 | 1 | test(0,4) | 0 | 0 | 36039 | 0 | 1 | test(0,5) | 0 | 0 | 36039 | 0 | 1 | test//以下4条数据为刚刚同一个事务里所插入的tuple(记录),可以看出来 cmin与cmax是递增的,因为是同一个事务里的 四条sql的结果。(0,7) | 0 | 0 | 36041 | 0 | 1 | test(0,8) | 1 | 1 | 36041 | 0 | 1 | test(0,9) | 2 | 2 | 36041 | 0 | 1 | test(0,10) | 3 | 3 | 36041 | 0 | 1 | test
(9 rows)不显式开启事务,直接在psql执行3条语句:postgres=# insert into user_info(id,info) values(1,'test');
INSERT 0 1
postgres=# insert into user_info(id,info) values(1,'test');
INSERT 0 1
postgres=# insert into user_info(id,info) values(1,'test');
INSERT 0 1
postgres=# select ctid,cmin,cmax,xmin,xmax,* from user_info ;ctid | cmin | cmax | xmin | xmax | id | info
--------+------+------+-------+------+----+------(0,1) | 0 | 0 | 36039 | 0 | 1 | test(0,2) | 0 | 0 | 36039 | 0 | 1 | test(0,3) | 0 | 0 | 36039 | 0 | 1 | test(0,4) | 0 | 0 | 36039 | 0 | 1 | test(0,5) | 0 | 0 | 36039 | 0 | 1 | test(0,7) | 0 | 0 | 36041 | 0 | 1 | test(0,8) | 1 | 1 | 36041 | 0 | 1 | test(0,9) | 2 | 2 | 36041 | 0 | 1 | test(0,10) | 3 | 3 | 36041 | 0 | 1 | test//以下是执行结果:可以发现cmin与cmax均为0, 因为它们不在同以事务里,各自属于各自的事务。只有在同一事务执行,才会排序。(0,11) | 0 | 0 | 36042 | 0 | 1 | test(0,12) | 0 | 0 | 36043 | 0 | 1 | test(0,13) | 0 | 0 | 36044 | 0 | 1 | test
(12 rows)
- 问题来了: cmax与cmin有何不同???
下面是pg社区的官方回复:
- What is the difference between cmin and cmax
I looked into the source code, and I think I now understand it:
cmin and cmax are same! The documentation is too old now.
**翻译:我看了源码后,我也理解了,cmin与cmax就特么是一个东西!
cmin和cmax其实实相同的。**
I made another test:
In terminal A:
pgsql=# begin;
BEGIN
pgsql=# select * from tab01;id | cd
----+----
(0 rows)pgsql=# select xmin,xmax,cmin,cmax,* from tab01;xmin | xmax | cmin | cmax | id | cd
------+------+------+------+----+----
(0 rows)pgsql=# insert into tab01 values(1,'1'),(2,'2'),(3,'3');
INSERT 0 3
pgsql=# insert into tab01 values(4,'4'),(5,'5'),(6,'6');
INSERT 0 3
pgsql=# select xmin,xmax,cmin,cmax,* from tab01;xmin | xmax | cmin | cmax | id | cd
------+------+------+------+----+----1897 | 0 | 0 | 0 | 1 | 11897 | 0 | 0 | 0 | 2 | 21897 | 0 | 0 | 0 | 3 | 31897 | 0 | 1 | 1 | 4 | 41897 | 0 | 1 | 1 | 5 | 51897 | 0 | 1 | 1 | 6 | 6
(6 rows)pgsql=# commit;Then I begin to delete record:
pgsql=# begin;
BEGIN
pgsql=# delete from tab01 where id=1 or id=2;
DELETE 2
pgsql=# delete from tab01 where id=3;
DELETE 1
pgsql=# delete from tab01 where id=4;
DELETE 1
pgsql=# delete from tab01 where id=5;
DELETE 1
pgsql=#But I have not commit my deleting action.
Then in terminal B, I can see:
pgsql=# select xmin,xmax,cmin,cmax,* from tab01;xmin | xmax | cmin | cmax | id | cd
------+------+------+------+----+----1897 | 1898 | 0 | 0 | 1 | 11897 | 1898 | 0 | 0 | 2 | 21897 | 1898 | 1 | 1 | 3 | 31897 | 1898 | 2 | 2 | 4 | 41897 | 1898 | 3 | 3 | 5 | 51897 | 0 | 1 | 1 | 6 | 6
(6 rows)pgsql=#
In fact , in the source code of PG,I can find it—heap_getsysattr function
in heaptuple.c,here is it:
——–code begin—-
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;
——–code end——-
postgresql里cmin与cmax有何不同.md相关推荐
- PostgreSQL 从cmin/cmax到combo cid
cmin和cmax介绍 cmin和cmax是PostgreSQL中表的系统字段之一,用来判断同一个事务内的其他命令导致的行版本变更是否可见.即在事务中每个命令都应该能看到其之前执行的命令的变更. 很多 ...
- PostgreSQL从cmin/cmax到combo cid
作者:吴聪 cmin和cmax介绍 cmin和cmax是PostgreSQL中表的系统字段之一,用来判断同一个事务内的其他命令导致的行版本变更是否可见.即在事务中每个命令都应该能看到其之前执行的命令的 ...
- 对PostgreSQL cmin和cmax的理解
看例子: 开两个终端来对比: 在终端A: [pgsql@localhost bin]$ ./psql psql (9.1.2) Type "help" for help.pgsql ...
- postgresql 数据库表隐藏列 oid、tableoid、ctid、xmin、xmax、cmin、cmax
os: centos 7.4 db: postgresql 10.11 oid.tableoid.ctid.xmin.xmax.cmin.cmax 这些都是 postgresql 数据库表的隐藏列. ...
- PostgreSQL如何实现MVCC (基于xmin、xmax、cmin、cmax)
声明:本文是<PostgreSQL实战>读书笔记,参考了http://www.jasongj.com/sql/mvcc/ 部分,可以参考该书事务与并发控制章节 和 http://www.j ...
- postgresql源码学习(49)—— MVCC⑤-cmin与cmax 同事务内的可见性判断
一. 难以理解的场景 postgresql源码学习(十九)-- MVCC④-可见性判断 HeapTupleSatisfiesMVCC函数_Hehuyi_In的博客-CSDN博客 在前篇的可见性判断中有 ...
- xmin、xmax、cmin、cmax
作者:瀚高PG实验室 (Highgo PG Lab) 这四个字段在多版本实现中用于控制数据行是否对用户可见.PostgreSQL会将修改前后的数据都存储在相同的结构中,分为以下几种情况. 新插入一行时 ...
- PostgreSQL 中的系统字段:tableoid、xmin、xmax、cmin、cmax、ctid
文章目录 tableoid ctid xmin xmax cmin cmax oid 总结 大家好!我是只谈技术不剪发的 Tony 老师.今天我们来谈谈 PostgreSQL 数据表中几个隐藏的系统字 ...
- GeoServer如何发布PostgreSQL里的数据?
GIS服务端避免不了将数据存储在pg库里.本篇我们来说如何将其发布在geoserver上. 我们讲的全面一点,尽量从0开始,让小白都能看得懂. 首先假设你有一份shape数据,你可以同过postgis ...
最新文章
- 英特尔详解5G将如何助力VR的未来发展
- Python 库升级问题-module ‘requests.exceptions‘ has no attribute ‘ReadTimeout‘原因及解决办法
- Makefile的条件执行
- java try catch 异常后还会继续执行吗
- 微软推出 Microsoft.Data.SqlClient,替代 System.Data.SqlClient
- canvas图表(4) - 散点图
- 三、Unity中的鼠标、键盘的获取
- 第一次搭建vue项目--添加依赖包、启动项目
- CCCC-GPLT L2-017. 人以群分 团体程序设计天梯赛
- linux文件名变量,文件名通配符、变量以及管道知识点的总结
- EXCEL,如何进行查找,单条件和多条件查询
- 一个高中生的编程自学经历
- 第一章 ContextCapture 19 基础操作
- 2019年蚂蚁金服面经(已拿Offer)!附答案!!
- Oracle 表字段的创建、删除、修改、查询
- Python进行数据分析探索
- 呜啦啦啦~我胡汉三又回来了
- 全面了解大数据“三驾马车”的开源实现
- 在Pygtk和Glade使用Gtkbuilder
- 曾经的Uber自动驾驶,其实成败只在一念之间?
热门文章
- 澳洲大药房天猫618战绩:爆款面霜销量够一个妹子用13个世纪
- step7 professional v11 sp2 sp1详细安装方法
- MySQL的复合查询
- 局域网共享设置软件_一铭操作系统(国产操作系统)设置打印机局域网共享
- 日语语法归纳--「に」的用法
- 全球3大项目外包和接单网站介绍
- 20221010Deep learning techniques applied to superresolution chemistry transport modeling for...
- OpenLayers3 在 Mac 视网膜屏下的响应式设计
- OpenCV实现手套表面缺陷检测
- 关于百度开发者文档的使用心得