Cluster-wide Consistent Transaction Commit Timestamp

If two events X and Y happen concurrently relative to one another but such that X is causally before Y, what timestamp mechanism can I use in a column that will accurately reflect these causal relationships? e.g. I need a cluster-wide transaction timestamp that reflects transaction order s.t. for any transaction A and B, if timestamp Ta < Tb, I need a CockroachDB timestamp that reflects this in the column. Something analogous to Spanner’s commit timestamp.

From the documentation, it looks like the current_timestamp(…) methods (and it’s variants) aren’t appropriate. The documentation states that these forms of timestamps have no relationship with the commit order of concurrent transactions. But the statement_timestamp looks like it could be a potential candidate?

What is the appropriate date/time function to capture the timestamp that reflects relative causal ordering or cluster-wide commit order? I need something analogous to the commit timestamp that Spanner offers.

Hi @jon-whit welcome to the forum!

The exact timestamp you want is the crdb_internal_mvcc_timestamp, which is available as a hidden column when you select from any table. You can turn it into an approximate timestamp using crdb_internal.approximate_timestamp().

However, this is an internal feature, so this column is subject to change in future releases.