Re: How to safely compare transaction id?

From: "Marko Kreen" <markokr(at)gmail(dot)com>
To: alphax <alphax(at)vip(dot)163(dot)com>
Cc: pg-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to safely compare transaction id?
Date: 2008-01-12 19:53:31
Message-ID: e51f66da0801121153y25580c25y70308072417ee6a2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/12/08, alphax <alphax(at)vip(dot)163(dot)com> wrote:
> Thanks. Actually, I want to compares the system columns(xmin, xmax,
> ctid) with the tid returned by txid functions declared in
>
> http://developer.postgresql.org/pgdocs/postgres/functions-info.html#FUNCTIONS-TXID-SNAPSHOT
>
>
> I want to determines a given record which visible to current transaction
> whether or not be updated after some time point, that time point is
> indicated by aother transaction id started and committed in past time.
> How can I safely do that?

You cannot compare txids with each other and determine visibility,
you need snapshots for that.

Eg. PgQ (generic queue) is implemented in following way:

- Current txid is stored with data rows.
- Periodically txid_snapshot is stored to separate table (pgq.tick).
- later when reading data, 2 snapshots are taken from pgq.tick,
and from them are txids determined that were committed between
those.
- The data rows for the txids are fetched from data tables then.

AFAIK this is only way how to implement robust and high-performance
queue in otherwise generic RDBMS.

> By the way, Can I think that the value of system column "ctid" of an
> record is the logical "current version" of that record, and used to
> compare with txid returned by "FUNCTIONS-TXID-SNAPSHOT"?

No, it is just physical location of the row.

--
marko

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lew 2008-01-12 20:17:14 Re: Postgresql 8.2.4 on linux-sparc problem
Previous Message dterrors 2008-01-12 19:53:18 Re: A counter argument about DISTINCT and GROUP BY in PostgreSQL