有没有比执行虚拟更新更好的方法来“触摸”一行?

Jac*_*las 6 postgresql

我使用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 |
*/
Run Code Online (Sandbox Code Playgroud)

(SQL 小提琴)

我很好奇是否有另一种方法可以在xid不进行更新的情况下进行碰撞,类似于 unixtouch命令?

Pet*_*aut 7

好吧,如果您想更改 xmin,那么需要确保其他事务仍然可以看到该行的旧版本,因此您需要使用新的 xmin 进行复制,您可以使用UPDATE. 您可以通过更新非索引列来减少这种影响,以获得 HOT 的好处。

当然,这整个思路是可疑的,也许您应该完全使用其他一些工具。