我使用xmin
系统列来实现一种乐观锁定的形式,有时需要“触摸”行来碰撞xmin
而不实际更新行。我目前只是做一个“虚拟”更新:
create table t(id integer);
insert into t(id) values(1);
insert into t(id) values(2);
select xmin::text from t where id=1
/*
| XMIN |
---------
| 87159 |
*/
update t set id=id where id=1
select xmin::text from t where id=1
/*
| XMIN |
---------
| 87196 |
*/
我很好奇是否有另一种在xid
不进行更新的情况下碰撞的方法,类似于 unixtouch
命令?
好吧,如果要更改 xmin,则需要确保其他事务仍然可以看到该行的旧版本,因此您需要使用新的 xmin 进行复制,您可以使用
UPDATE
. 您可以通过更新非索引列来减少这种影响,以获得 HOT 的好处。当然,这整个思路是可疑的,也许您应该完全使用其他一些工具。