Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mSqLo-0005uY-4A for pgsql-general@arkaria.postgresql.org; Wed, 22 Sep 2021 00:43:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mSqLm-0003SZ-M1 for pgsql-general@arkaria.postgresql.org; Wed, 22 Sep 2021 00:43:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mSqLm-0003SQ-7b for pgsql-general@lists.postgresql.org; Wed, 22 Sep 2021 00:43:02 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mSqLj-00057g-0D for pgsql-general@lists.postgresql.org; Wed, 22 Sep 2021 00:43:01 +0000 Received: by mail-pj1-x102d.google.com with SMTP id n13-20020a17090a4e0d00b0017946980d8dso3265748pjh.5 for ; Tue, 21 Sep 2021 17:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=JZGR2wBHnYsWSTnVu2NVKYKvS43DD1arNMbdGBMA9Ro=; b=MHWUv1GLzUjot/YlFUsDBmBgIyUydcjENCdrMc6TGxjxxKM4E8TRbgchXYZ2vF9RBm AEbYrDjs/jgD6qpF/epKtdr+CG/caQImoIicin2GxsH29MbOCth3EsGFSS8l0utPGcz9 /4NO+JrF4dvNGFP7IpTCynxU9ch7fiPaJ6T8A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=JZGR2wBHnYsWSTnVu2NVKYKvS43DD1arNMbdGBMA9Ro=; b=WWdKHbxHjVfIJOdy+jJvWNDM67TwgujOtg3w4l92mzvkk1axvf0oBsdofDHEWJzqKr Z6iZ3sTu3d5X3X7VgZSspDPYhlU45455fJQrL0fC0ScEMaFNhS5Ip/vPu2K8H02d4lc6 KmYT92Ub3f9avaIcs+BnIsuTkznDcXh+/gaLSKHBKadqRO+lOjxrFJXKBrWze0QyEGnK fvx8qPSbyQeQu5vMis9V/f+zOevhUDFAMjac6jbjb7kKEiORI3C6w5U3FCiQeLaz7PoS zue2Pix5Mi0sEnK+6oV/tzwoqMwc0qK4/ikRH/1TUX0g9/L2rvtZXQU7WiHv85H5QIH6 sx3g== X-Gm-Message-State: AOAM532FoYWyVm+JKQBisq9Oen6UtxH3gWXAqdLbG2RA3g5OL2BZhSSO S0IH3SJ90Idia4+d/No8UA2T8w== X-Google-Smtp-Source: ABdhPJyQ5WeQ/8wVjWMZtUf2uzdI1Zz+868vSOrZXfEJ+iHPXRGknPH8e6YP/ZUU0ALsg1RrT04GoQ== X-Received: by 2002:a17:902:6f01:b0:13b:7b8b:84a3 with SMTP id w1-20020a1709026f0100b0013b7b8b84a3mr29592201plk.40.1632271377286; Tue, 21 Sep 2021 17:42:57 -0700 (PDT) Received: from smtpclient.apple ([2601:646:101:7fda:7c94:a956:d32b:90ea]) by smtp.gmail.com with ESMTPSA id v7sm231077pjk.37.2021.09.21.17.42.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Sep 2021 17:42:56 -0700 (PDT) From: Bryn Llewellyn Message-Id: <25F60EC6-2891-4B16-B0AE-B9256BE2F90F@yugabyte.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_4740E473-71E2-4D63-A3BE-78C3C6F65472" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Thanks, David! 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:42:55 -0700 In-Reply-To: Cc: pgsql-general list To: "David G. Johnston" References: <6FCF660B-F151-4AA0-9AE5-C579591EF134@yugabyte.com> X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_4740E473-71E2-4D63-A3BE-78C3C6F65472 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > David G. Johnston wrote: >=20 > Bryn wrote: >=20 > I'm surprised by the results that I describe below. Please help me = interpret them. >=20 > 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.) >=20 > transaction_timestamp() as txn_11, > statement_timestamp() as stm_11, > =20 > t_finish in timestamptz, > t_start in timestamptz, > expected_diff in double precision) > =20 > select expected_tstz_diff_error('txn_11 - stm_11 =3D 0', = :s1_txn_11, :s1_stm_11, :zero); >=20 > txn_11 - stm_11 =3D 0 : error: -0.1 ms > =20 > err constant double precision not null :=3D > ( (extract(epoch from t_finish) - extract(epoch from = t_start)) - expected_diff )*dp_1000; > =20 >=20 > So, finish is the txn, start is the stm, and expected is 0 - thus if = finish (txn) is earlier than start (stm) your error will be negative. = Which it is, and since transaction should be earlier than statement this = would seem to be correct. In short, you seem to have mis-interpreted = the error sign=E2=80=99s meaning. Thanks, David. Damn... I'm so embarrassed. I'd been staring at my code for too long and = was blind to my stupidity. Just goes to show how important it is to = choose names sensibly. "Start" and "finish" were silly (a left-over from = a previous use of that code). I changed the names to "t_expected_later" = and "t_expected_sooner" =E2=80=94 and twizzled my arguments where = needed. All is clear now. In summary, the first statement after the explicit "start transaction" = is a bit later than the moment that the explicitly started txn = starts=E2=80=94in line with intuition. And, of course, the round trip to = invoke pg_sleep() takes time too. I was talking nonsense when I wrote "commit is bound to take time and = I'm not using an estimate for this". Doubtless "commit" does take some = time. But it happens after my last recorded time measurement. That, too, = was a left-over from a different test. Sigh... Case closed. --Apple-Mail=_4740E473-71E2-4D63-A3BE-78C3C6F65472 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
David G. Johnston = wrote:

Bryn 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.)

  transaction_timestamp() as = txn_11,
  statement_timestamp()   as = stm_11,
 

  t_finish     =   in timestamptz,
  t_start  =       in timestamptz,
  expected_diff  in double precision)
 

select expected_tstz_diff_error('txn_11 - = stm_11 =3D 0',            :s1_txn_11, = :s1_stm_11, :zero);

txn_11 - stm_11 =3D 0      =       : error: -0.1 ms
 
  err      constant double = precision not null :=3D
          =    ( (extract(epoch from t_finish) - extract(epoch from = t_start)) - expected_diff )*dp_1000;
 

So, finish is the txn, = start is the stm, and expected is 0 - thus if finish (txn) is earlier = than start (stm) your error will be negative.  Which it is, and = since transaction should be earlier than statement this would seem to be = correct.  In short, you seem to have mis-interpreted the error = sign=E2=80=99s meaning.

Thanks, David.

Damn... I'm so embarrassed. I'd been staring at my code for = too long and was blind to my stupidity. Just goes to show how important = it is to choose names sensibly. "Start" and "finish" were silly (a = left-over from a previous use of that code). I changed the names to = "t_expected_later" and "t_expected_sooner" =E2=80=94 and twizzled my = arguments where needed. All is clear now.

In summary, the first statement after = the explicit "start transaction" is a bit later than the moment that the = explicitly started txn starts=E2=80=94in line with intuition. And, of = course, the round trip to invoke pg_sleep() takes time too.

I was talking nonsense = when I wrote "commit is bound to take time and I'm not using an = estimate for this". Doubtless "commit" does take some time. But it = happens after my last recorded time measurement. That, too, was a = left-over from a different test. Sigh...

Case closed.

= --Apple-Mail=_4740E473-71E2-4D63-A3BE-78C3C6F65472--