خرید بک لینک

Vote count: 0

According to http://www.postgresql.org/docs/current/static/ddl-system-columns.html:

xmax - The identity (transaction ID) of the deleting transaction, or zero for an undeleted row version. It is possible for this column to be nonzero in a visible row version. That usually indicates that the deleting transaction hasn't committed yet, or that an attempted deletion was rolled back.

But if a row is referenced as a foreign key by another row, it also has a non-zero value for xmax:

drop table if exists demo;
create table demo
(
    id bigint primary key not null,
    pid bigint,
    constraint demo_pid_fk
        foreign key (pid)
    references demo (id)
);

insert into demo(id, pid) values(1, NULL); 
insert into demo(id, pid) values(2, 1); 
insert into demo(id, pid) values(3, 3); 
select xmin, xmax, * from demo;
 xmin | xmax | id | pid 
------+------+----+-----
 1074 | 1075 |  1 |    
 1075 |    0 |  2 |   1
 1076 | 1076 |  3 |   3
(3 rows)

insert into demo(id, pid) values(4, 1); 
select xmin, xmax, * from demo;
 xmin | xmax | id | pid 
------+------+----+-----
 1074 | 1077 |  1 |    
 1075 |    0 |  2 |   1
 1076 | 1076 |  3 |   3
 1077 |    0 |  4 |   1
(4 rows)

In the example above, it seems that xmax is set to the id of a last transaction that referenced the row as a foreign key. Why is it so? How does Postgres know that the row is still alive?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 28 فروردين 1395 ساعت: 20:15

صفحه بندی