Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 11D3F1336473 for ; Sun, 26 Sep 2010 21:43:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 91160-02 for ; Mon, 27 Sep 2010 00:43:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 5987E1335ED4 for ; Sun, 26 Sep 2010 21:42:59 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o8R0gxm5020489; Sun, 26 Sep 2010 20:42:59 -0400 (EDT) To: Mark Rostron cc: "pgsql-admin@postgresql.org" Subject: Re: xid wraparound In-reply-to: References: <17534.1285462422@sss.pgh.pa.us> Comments: In-reply-to Mark Rostron message dated "Sun, 26 Sep 2010 14:33:23 -0700" Date: Sun, 26 Sep 2010 20:42:59 -0400 Message-ID: <20488.1285548179@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/153 X-Sequence-Number: 35697 Mark Rostron 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