pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Bryn Llewellyn <bryn@yugabyte.com>
To: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Surprising results from tests intended to show the difference in semantics between transaction_timestamp(), statement_timestamp(), and clock_timestamp()
Date: Tue, 21 Sep 2021 17:38:12 -0700
Message-ID: <a9bda070-a396-4041-7369-d30dc3919e4a@aklaver.com> (raw)
In-Reply-To: <6FCF660B-F151-4AA0-9AE5-C579591EF134@yugabyte.com>
References: <6FCF660B-F151-4AA0-9AE5-C579591EF134@yugabyte.com>

On 9/21/21 4:23 PM, Bryn Llewellyn wrote:
> I'm surprised by the results that I describe below. Please help me 
> interpret them.
> 
> Briefly, why does transaction_timestamp() report a later value 
> than statement_timestamp() when they're both invoked in the very first 
> statement after "start transaction". (They report identical values in an 
> implicitly started txn.)

I'm not seeing it:

test(5432)=# begin;

select
   transaction_timestamp() as txn_11,
   statement_timestamp()   as stm_11,
   clock_timestamp()       as clk_11,
   pg_sleep(0.5)        as dummy,
   transaction_timestamp() as txn_12,
   statement_timestamp()   as stm_12,
   clock_timestamp()       as clk_12;

select pg_sleep(1);

select
   transaction_timestamp() as txn_2,
   statement_timestamp()   as stm_2,
   clock_timestamp()       as clk_2;

commit;

BEGIN
-[ RECORD 1 ]-------------------------
txn_11 | 2021-09-21 17:29:18.272042-07
stm_11 | 2021-09-21 17:29:18.2722-07
clk_11 | 2021-09-21 17:29:18.272297-07
dummy  |
txn_12 | 2021-09-21 17:29:18.272042-07
stm_12 | 2021-09-21 17:29:18.2722-07
clk_12 | 2021-09-21 17:29:18.772863-07

-[ RECORD 1 ]
pg_sleep |

-[ RECORD 1 ]------------------------
txn_2 | 2021-09-21 17:29:18.272042-07
stm_2 | 2021-09-21 17:29:19.774436-07
clk_2 | 2021-09-21 17:29:19.77456-07


No matter how many times I run this the transaction_timestamp() is less 
then statement_timestamp().  This is as it should be, as 
transaction_timestamp() fires with the begin; and statement_timestamp() 
fires at select ... and then updates with the subsequent select .... and 
clock_timestamp() just keeps marching on through the whole process.

-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (5+ messages)  latest in thread

Message-ID: <a9bda070-a396-4041-7369-d30dc3919e4a@aklaver.com>
Permalink:  ../a9bda070-a396-4041-7369-d30dc3919e4a@aklaver.com/
Also on:    postgresql.org/message-id/a9bda070-a396-4041-7369-d30dc3919e4a@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, bryn@yugabyte.com
  Subject: Re: Surprising results from tests intended to show the difference in semantics between transaction_timestamp(), statement_timestamp(), and clock_timestamp()
  In-Reply-To: <a9bda070-a396-4041-7369-d30dc3919e4a@aklaver.com>
  References: <6FCF660B-F151-4AA0-9AE5-C579591EF134@yugabyte.com> <a9bda070-a396-4041-7369-d30dc3919e4a@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox