Visibility computation internals
Understanding how this is implemented in the server is helpful both to help predict how statements will act, and so that you can interpret the diagnostic information available.
As transactions are created in the database, PostgreSQL advances a transaction ID counter, usually just called the XID, to keep track of them. When you insert a row into the database, or update an existing row, the new row created by that operation saves the session's transaction ID into a field named the insertion XID, also referred to as the xmin
. This is the minimum XID capable of seeing this bit of information, once it's been committed.
When a query or statement starts (tracking at either granularity can happen depending on what mode you're in—more on this later), it notes the current transaction ID as a hard line for what it should consider visible. As rows are considered for inclusion in the query results, if they are committed and their insertion...