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 1mSqHG-0005hn-AX for pgsql-general@arkaria.postgresql.org; Wed, 22 Sep 2021 00:38:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mSqHE-0007co-3e for pgsql-general@arkaria.postgresql.org; Wed, 22 Sep 2021 00:38:20 +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 1mSqHC-0007cg-L1 for pgsql-general@lists.postgresql.org; Wed, 22 Sep 2021 00:38:19 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mSqH9-00055g-EX for pgsql-general@lists.postgresql.org; Wed, 22 Sep 2021 00:38:17 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 1A1025C016D; Tue, 21 Sep 2021 20:38:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 21 Sep 2021 20:38:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=v 0TVqROOMa3bD+n3ywJeMm8kdzgzj1ijA54hA/CBTH8=; b=tZT3zmTJyOt+CG2Q1 cpN9xpQWk6wlv+W+s79O9AGiQ0qB/HPXbDk7am/aqIkZBtsJEXd82gzlfQz2I547 dVyMDJi7ZMg5kzfyug71zeMBcMBRNcA3CeSB2KvsDbtZGOpBDZ+eV175zyWG2ngR 26moZBoosLdJrr0kuVea5TcgpWBjhoN0juvlwLybuxKj+leDcQCFoSQCHa96WDEC qebO+pvPMwMVtVEeEJ4U412BH7DJF1JKgvcHbCqCf9D38Z16PdhwXGPvVdK6Qs3u IneMx2xDQ949MB0309I6T6ZcEQaN0q2cGbiQHAaXjgkch9i5phxncL1Tbz0zlIgz EG/Lw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=v0TVqROOMa3bD+n3ywJeMm8kdzgzj1ijA54hA/CBT H8=; b=jyFst7sL5p4D887GKGuGHz3waGsP6VFGlUpXYLoN18yeJuwy361UNYoRw JbHyMTCPm1ZtvnEhoxLmu8q6trt9195hFWv9tsTtPlfq06tTfjjWM82rAlrsaZgw gbe8+O3cHShpWJZu9y5vhlzz6Z4MnCmNXTdfF0iTm6FAqTkw8u8Lc6WNUYqW50MK BXnB7vyAwboXjLrFn1td13ESxRWq5NKv+5LCclt/60b+wjiOYOt1tlZ/8gTvaO/+ j80LEG4JtM0etVEJ0HIGAoD1XvjOy+TFpNfI5fK4C9ppI4Zp1m2IWoj1hwHMq28i MudFn01NWVYP7OmVDN/VftTeIJYQw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeiiedgfeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeevveefveefueegffekkefhgeeiueffgfetueejvdfg hfeujeejhfekjeelgedtgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 21 Sep 2021 20:38:13 -0400 (EDT) Subject: Re: Surprising results from tests intended to show the difference in semantics between transaction_timestamp(), statement_timestamp(), and clock_timestamp() To: Bryn Llewellyn , pgsql-general list References: <6FCF660B-F151-4AA0-9AE5-C579591EF134@yugabyte.com> From: Adrian Klaver Message-ID: Date: Tue, 21 Sep 2021 17:38:12 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <6FCF660B-F151-4AA0-9AE5-C579591EF134@yugabyte.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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