[GENERAL] have trouble understanding xmin and xmax with update operationsfrom two different sessions - Mailing list pgsql-general

From rajan
Subject [GENERAL] have trouble understanding xmin and xmax with update operationsfrom two different sessions
Date
Msg-id 1498890748169-5969629.post@n3.nabble.com
Whole thread Raw
Responses Re: [GENERAL] have trouble understanding xmin and xmax with updateoperations from two different sessions  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
have trouble understanding xmin and xmax with update operations from two
different sessions

So, as found below, Session2 is trying to update a row which is already
updated with a different value and it's update fails with *UPDATE 0*

But from Session3, I see that xmax value is visible as Session2's txid. Why
is it like that?
Can we not put Session2's txid to xmin instead(although the update failed)?
And if we try to consider that xmax is update with Session2's txid bcoz the
update failed, then why bother updating the xmax?

Please help me understand this.

*Session1*
testdb=# BEGIN;
BEGIN
testdb=# select ctid, xmin, xmax, * from numbers;
 ctid  |  xmin  | xmax | number
-------+--------+------+--------
 (0,2) | 519107 |    0 |     14
 (0,3) | 519112 |    0 |     23
(2 rows)

testdb=# select txid_current();
 txid_current
--------------
       519114
(1 row)

testdb=# update numbers set number=24 where number=14;
UPDATE 1
testdb=# COMMIT;
COMMIT


*Session 2*
testdb=# BEGIN;
BEGIN
testdb=# select txid_current();
 txid_current
--------------
       519115
(1 row)

testdb=# select ctid, xmin, xmax, * from numbers;
 ctid  |  xmin  | xmax | number
-------+--------+------+--------
 (0,2) | 519107 |    0 |     14
 (0,3) | 519112 |    0 |     23
(2 rows)

testdb=# select ctid, xmin, xmax, * from numbers;
 ctid  |  xmin  |  xmax  | number
-------+--------+--------+--------
 (0,2) | 519107 | 519114 |     14
 (0,3) | 519112 |      0 |     23
(2 rows)

testdb=# update numbers set number=25 where number=14;
UPDATE 0
testdb=# COMMIT;
COMMIT

*Session 3*
testdb=# select txid_current();
 txid_current
--------------
       519116
(1 row)

testdb=# select ctid, xmin, xmax, * from numbers;
 ctid  |  xmin  |  xmax  | number
-------+--------+--------+--------
 (0,3) | 519112 |      0 |     23
 (0,4) | 519114 | 519115 |     24
(2 rows)




-----
--
Thanks,
Rajan.
--
View this message in context:
http://www.postgresql-archive.org/have-trouble-understanding-xmin-and-xmax-with-update-operations-from-two-different-sessions-tp5969629.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Steven Chang
Date:
Subject: Re: [GENERAL] duplicate key value violates unique constraint andduplicated records
Next
From: leason
Date:
Subject: [GENERAL] Buy real Passports(designerdesigner@yahoo.com)Visa, DrivingLicense, ID CARDS, marriage certificates, diplomas