1

I was reading the docs about the xid and it's wraparounds. But can't understand how it all works.

Normal XIDs are compared using modulo-2^32 arithmetic. This means that for every normal XID, there are two billion XIDs that are “older” and two billion that are “newer”.

How are they compared According to documentation xid is 32-bit number and as far as I understand it is incremented with every transaction

1
  • What are you asking us? Are you asking us what modulo arithmetic is? Are you asking where in the source code it is implemented?
    – jjanes
    Sep 2, 2019 at 14:24

1 Answer 1

2

Imagine the transaction IDs from 0 to 4294967296 in a circle. AS some point in that circle is your current transaction ID.

Let's say your current transaction ID is 1000000. Then the 2^31 transaction IDs after it are in the future: 1000001 to 2148483648. And the 2^31 transactions before that are the past: 2148483649 to 4294967296 and 0 to 999999 (remember we have a circle, so right after 4294967296 comes 0).

Once your current transaction ID crosses 4294967296, it becomes 0 again (to be precise, it will become 3, because the transaction IDs 0 to 2 have a special meaning).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.