why does txid_current() assign new transaction-id?
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
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
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 ....) ..
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
Attached is a doc patch among those lines.
--
Michael
Name | Return Type | Description |
---|---|---|
txid_current() | bigint | get current transaction ID, assigning a new one if the current transaction does not have one |
txid_current_snapshot() | txid_snapshot | get current snapshot |
Snapshot Components
Name | Description |
---|---|
xmin | Earliest transaction ID (txid) that is still active. All earlier transactions will either be committed and visible, or rolled back and dead. |
xmax | First as-yet-unassigned txid. All txids greater than or equal to this are not yet started as of the time of the snapshot, and thus invisible. |
xip_list | Active txids at the time of the snapshot. The list includes only those active txids between xmin and xmax; there might be active txids higher thanxmax. A txid that is xmin <= txid < xmax and not in this list was already completed at the time of the snapshot, and thus either visible or dead according to its commit status. The list does not include txids of subtransactions. |
txid_snapshot's textual representation is xmin:xmax:xip_list. For example 10:20:10,14,15 means xmin=10, xmax=20, xip_list=10, 14, 15.
参考:
http://postgresql.nabble.com/why-does-txid-current-assign-new-transaction-id-td5851159.html
http://www.postgresql.org/docs/devel/static/functions-info.html
posted on 2015-08-13 23:04 Still water run deep 阅读(575) 评论(0) 编辑 收藏 举报