Re: xid wraparound - Mailing list pgsql-admin

From Tom Lane
Subject Re: xid wraparound
Date
Msg-id 20488.1285548179@sss.pgh.pa.us
Whole thread Raw
In response to Re: xid wraparound  (Mark Rostron <mrostron@ql2.com>)
Responses Re: xid wraparound  (Mark Rostron <mrostron@ql2.com>)
List pgsql-admin
Mark Rostron <mrostron@ql2.com> writes:
>> No.  XID comparisons are modulo 2^31.

> Thanks - I'm still trying to wrap my mind around this (sorry).

> So, for the sake of this description:
> - the XID space (size 2^32) is split into two sub-spaces, each of size 2^31

No, it is not.  The XID space is continuous and circular.  For any given
XID, there are 2^31-1 possible XIDs that are "before" it and 2^31-1 that
are "after" it (plus the special FrozenXID value, which is always before
everything else).  There's no absolute comparisons possible, only
relative ones.  Everything works without wraparound hiccups, because the
XID space has no endpoints.  The price is that consistency is lost if
there are ever XIDs in the system that are more than 2^31 transactions
apart.  We avoid that by replacing old XIDs with FrozenXID before they
get to be more than 2^31 transactions old.

> Therefore, a query can only see rows where:
> (q.o > r.o) && (q.s == r.s) || (q.o <= r.o) && (q.s != r.s)

Actually, to compare two XIDs we just do a signed subtraction (ignoring
overflow) and see if the result is positive or negative.

            regards, tom lane

pgsql-admin by date:

Previous
From: Mark Rostron
Date:
Subject: Re: xid wraparound
Next
From: Mark Rostron
Date:
Subject: Re: xid wraparound