Middle+
Mis juhtub Xmin ja Xmax-iga uuendamisel?
sobes.tech AI
Vastus AI-lt
In PostgreSQL, during an UPDATE operation, not only is the row modified, but in fact a new version of the row is created (MVCC — multi-version concurrency control).
- Xmin is the transaction ID that created (inserted) the current version of the row.
- Xmax is the transaction ID that marked the row as deleted (for example, during an UPDATE or DELETE).
During an UPDATE:
- The old version of the row receives in the Xmax field the ID of the current transaction performing the UPDATE — this means that this version is now considered deleted for new transactions.
- A new version of the row is created with a new Xmin — the ID of the current transaction, and an empty Xmax.
Thus, an UPDATE is essentially a DELETE of the old version + an INSERT of the new version, which ensures transaction isolation and data consistency.