- 在这之前,做个与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'