Thread: why does txid_current() assign new transaction-id?

why does txid_current() assign new transaction-id?

From
Naoya Anzai
Date:
Hi,hackers!

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?

Regards,

Naoya

---
Naoya Anzai
Engineering Department
NEC Solution Inovetors, Ltd.
E-Mail: nao-anzai@xc.jp.nec.com
---


Attachment

Re: why does txid_current() assign new transaction-id?

From
Michael Paquier
Date:
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



Re: why does txid_current() assign new transaction-id?

From
Naoya Anzai
Date:
Thank you for comments.

I understand your points.

For only to read a current transaction-id, I know we just have to use
txid_current_snapshot and that is a best way, but I feel a little bit
hassle to explain columns of txid_current_snapshot for my supporting customers..
(Xmin is .... and Xmax is ....) ..

> 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
+1

I think that a description of txid_current is too rough and it might
be confused some users.
txid_current is a different operation depending on session situations,
I feel if detail of txid_current is documented then it will be better.

For example...
Inside of the transaction-block(begin..end), returns a transaction-id used by this block.
Outside of the transaction-block, returns a next transaction-id(but it is consumed by this function).

Regards,

Naoya

---
Naoya Anzai
Engineering Department
NEC Solution Inovetors, Ltd.
E-Mail: nao-anzai@xc.jp.nec.com
---






Re: why does txid_current() assign new transaction-id?

From
Michael Paquier
Date:
On Wed, May 27, 2015 at 5:13 PM, Naoya Anzai <nao-anzai@xc.jp.nec.com> wrote:
>> 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
> +1
>
> I think that a description of txid_current is too rough and it might
> be confused some users.
> txid_current is a different operation depending on session situations,
> I feel if detail of txid_current is documented then it will be better.
>
> For example...
> Inside of the transaction-block(begin..end), returns a transaction-id used by this block.
> Outside of the transaction-block, returns a next transaction-id(but it is consumed by this function).

Attached is a doc patch among those lines.
--
Michael

Attachment

Re: why does txid_current() assign new transaction-id?

From
Christoph Berg
Date:
Re: Michael Paquier 2015-05-28 <CAB7nPqSOx2TEgsypk8gbfa=_hJn7WNLf_tRZexY+SnN3fVF_nA@mail.gmail.com>
> Attached is a doc patch among those lines.

> diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
> index 89a609f..6485b42 100644
> --- a/doc/src/sgml/func.sgml
> +++ b/doc/src/sgml/func.sgml
> @@ -16233,7 +16233,7 @@ SELECT collation for ('foo' COLLATE "de_DE");
>        <row>
>         <entry><literal><function>txid_current()</function></literal></entry>
>         <entry><type>bigint</type></entry>
> -       <entry>get current transaction ID</entry>
> +       <entry>get current transaction ID, assigning a new one if current transaction does not have one</entry>
                                                           ^ the
 

Christoph
-- 
cb@df7cb.de | http://www.df7cb.de/



Re: why does txid_current() assign new transaction-id?

From
Naoya Anzai
Date:
> > diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
> > index 89a609f..6485b42 100644
> > --- a/doc/src/sgml/func.sgml
> > +++ b/doc/src/sgml/func.sgml
> > @@ -16233,7 +16233,7 @@ SELECT collation for ('foo' COLLATE "de_DE");
> >        <row>
> >         <entry><literal><function>txid_current()</function></literal></entry>
> >         <entry><type>bigint</type></entry>
> > -       <entry>get current transaction ID</entry>
> > +       <entry>get current transaction ID, assigning a new one if current transaction does not have one</entry>
>                                                                     ^ the

That looks good.

Regards,

Naoya

---
Naoya Anzai
Engineering Department
NEC Solution Inovetors, Ltd.
E-Mail: nao-anzai@xc.jp.nec.com
---



Re: why does txid_current() assign new transaction-id?

From
Fujii Masao
Date:
On Wed, Jun 3, 2015 at 9:04 AM, Naoya Anzai <nao-anzai@xc.jp.nec.com> wrote:
>> > diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
>> > index 89a609f..6485b42 100644
>> > --- a/doc/src/sgml/func.sgml
>> > +++ b/doc/src/sgml/func.sgml
>> > @@ -16233,7 +16233,7 @@ SELECT collation for ('foo' COLLATE "de_DE");
>> >        <row>
>> >         <entry><literal><function>txid_current()</function></literal></entry>
>> >         <entry><type>bigint</type></entry>
>> > -       <entry>get current transaction ID</entry>
>> > +       <entry>get current transaction ID, assigning a new one if current transaction does not have one</entry>
>>                                                                     ^ the
>
> That looks good.

Committed. Thanks!

Regards,

-- 
Fujii Masao



Re: why does txid_current() assign new transaction-id?

From
Michael Paquier
Date:


On Wed, Jun 3, 2015 at 12:13 PM, Fujii Masao <masao.fujii@gmail.com> wrote:
On Wed, Jun 3, 2015 at 9:04 AM, Naoya Anzai <nao-anzai@xc.jp.nec.com> wrote:
>> > diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
>> > index 89a609f..6485b42 100644
>> > --- a/doc/src/sgml/func.sgml
>> > +++ b/doc/src/sgml/func.sgml
>> > @@ -16233,7 +16233,7 @@ SELECT collation for ('foo' COLLATE "de_DE");
>> >        <row>
>> >         <entry><literal><function>txid_current()</function></literal></entry>
>> >         <entry><type>bigint</type></entry>
>> > -       <entry>get current transaction ID</entry>
>> > +       <entry>get current transaction ID, assigning a new one if current transaction does not have one</entry>
>>                                                                     ^ the
>
> That looks good.

Committed. Thanks!
 
Thanks for picking up the fix.
--
Michael