Re: why does txid_current() assign new transaction-id? - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: why does txid_current() assign new transaction-id?
Date
Msg-id CAB7nPqSVDhHWmYrc5Tt35N2WtZG88H+FGRxDF-G89mJ1DLRsEA@mail.gmail.com
Whole thread Raw
In response to why does txid_current() assign new transaction-id?  (Naoya Anzai <nao-anzai@xc.jp.nec.com>)
Responses Re: why does txid_current() assign new transaction-id?  (Naoya Anzai <nao-anzai@xc.jp.nec.com>)
List pgsql-hackers
On Tue, May 26, 2015 at 4:12 PM, Naoya Anzai <nao-anzai@xc.jp.nec.com> wrote:
> I have a question about txid_current().
> it is "Why does txid_current() assign new transaction-id?".
>
> When we executes txid_current() outside of transaction block, it assigns new transaction-id.
> I guess it doesn't need to assign a new txid because txid_current() is just a read-only function.
>
> I found a replaceable function by walking through pg-code, that is GetStableLatestTransactionId(void).
>
> I attached a patch which changing just 1-line.
> Could you please check the code?

txid_current has had the behavior of assigning a new transaction XID
when one is not assigned since its introduction. I don't think that it
is wise to change it now the way you do as many applications surely
rely on this assumption. Perhaps we could make the documentation
clearer about those things though, changing the description of this
function to "get current transaction ID, and assign a new one if one
is not assigned yet":
http://www.postgresql.org/docs/devel/static/functions-info.html

Regards,
-- 
Michael



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: RFC: Non-user-resettable SET SESSION AUTHORISATION
Next
From: Abhijit Menon-Sen
Date:
Subject: Re: fsync-pgdata-on-recovery tries to write to more files than previously