您的位置:首页 > 其它

why does txid_current() assign new transaction-id?

2015-08-13 23:04 417 查看
Naoya:

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

Michael:

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

Naoya:

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

Michael:

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

NameReturn TypeDescription
txid_current()bigintget current transaction ID, assigning a new one if the current transaction does not have one
txid_current_snapshot()txid_snapshotget current snapshot
Snapshot Components

NameDescription
xminEarliest transaction ID (txid) that is still active. All earlier transactions will either be committed and visible, or rolled back and dead.
xmaxFirst 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_listActive 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: