Re: xid wraparound

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark Rostron <mrostron(at)ql2(dot)com>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: xid wraparound
Date: 2010-09-27 00:42:59
Message-ID: 20488.1285548179@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Mark Rostron <mrostron(at)ql2(dot)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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Mark Rostron 2010-09-27 04:20:38 Re: xid wraparound
Previous Message Mark Rostron 2010-09-26 21:33:23 Re: xid wraparound