PostgreSQL中Tuple可见性判断的基本逻辑是什么

发布时间:2021-11-10 19:03:00 作者:iii
来源:亿速云 阅读:165

这篇文章主要介绍“PostgreSQL中Tuple可见性判断的基本逻辑是什么”,在日常操作中,相信很多人在PostgreSQL中Tuple可见性判断的基本逻辑是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”PostgreSQL中Tuple可见性判断的基本逻辑是什么”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

判断逻辑
((Xmin == my-transaction &&       inserted by the current transaction
 Cmin < my-command &&          before this command, and
 (Xmax is null ||            the row has not been deleted, or
  (Xmax == my-transaction &&      it was deleted by the current transaction
   Cmax >= my-command)))       but not before this command,
||                     or
 (Xmin is committed &&          the row was inserted by a committed transaction, and
  (Xmax is null ||            the row has not been deleted, or
   (Xmax == my-transaction &&     the row is being deleted by this transaction
    Cmax >= my-command) ||      but it’s not deleted “yet”, or
    (Xmax != my-transaction &&    the row was deleted by another transaction
     Xmax is not committed))))    that has not been committed

其中,my-command在PG中通过cmin/cmax体现.
cmin/cmax
如下例所示,游标在删除命令前定义,因此Tuple可见.

10:51:21 (xdb@[local]:5432)testdb=# DELETE FROM mvcc_demo;
DELETE 3
10:51:22 (xdb@[local]:5432)testdb=# 
10:51:22 (xdb@[local]:5432)testdb=# BEGIN WORK;
BEGIN
10:51:22 (xdb@[local]:5432)testdb=#* INSERT INTO mvcc_demo VALUES (1);
INSERT 0 1
10:51:22 (xdb@[local]:5432)testdb=#* INSERT INTO mvcc_demo VALUES (2);
INSERT 0 1
10:51:22 (xdb@[local]:5432)testdb=#* INSERT INTO mvcc_demo VALUES (3);
INSERT 0 1
10:51:22 (xdb@[local]:5432)testdb=#* SELECT xmin, cmin, xmax, cmax, * FROM mvcc_demo;
 xmin | cmin | xmax | cmax | val 
------+------+------+------+-----
 2400 |    0 |    0 |    0 |   1
 2400 |    1 |    0 |    1 |   2
 2400 |    2 |    0 |    2 |   3
(3 rows)
10:51:23 (xdb@[local]:5432)testdb=#* DECLARE c_mvcc_demo CURSOR FOR
[local] xdb@testdb-# SELECT xmin, cmin, xmax, cmax, * FROM mvcc_demo; --> 定义游标
DECLARE CURSOR
10:51:34 (xdb@[local]:5432)testdb=#* DELETE FROM mvcc_demo; --> 删除数据
DELETE 3
10:51:34 (xdb@[local]:5432)testdb=#* SELECT xmin, cmin, xmax, cmax, * FROM mvcc_demo;
 xmin | cmin | xmax | cmax | val 
------+------+------+------+-----
(0 rows)
10:51:35 (xdb@[local]:5432)testdb=#* FETCH ALL FROM c_mvcc_demo; --> 游标在删除命令前定义,因此可见
 xmin | cmin | xmax | cmax | val 
------+------+------+------+-----
 2400 |    0 | 2400 |    0 |   1
 2400 |    1 | 2400 |    1 |   2
 2400 |    2 | 2400 |    2 |   3
(3 rows)

到此,关于“PostgreSQL中Tuple可见性判断的基本逻辑是什么”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. 分析PostgreSQL中的tuple locks
  2. PostgreSQL中AutoVacLauncherMain函数的实现逻辑是什么

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

postgresql tuple

上一篇:为什么Kubernetes不使用libnetwork

下一篇:Django中的unittest应用是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》