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 1m3Vx5-00034r-8d for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Jul 2021 03:52:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3Vx3-0007l2-9G for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Jul 2021 03:52:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3Vx3-0007ku-30 for pgsql-bugs@lists.postgresql.org; Wed, 14 Jul 2021 03:52:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3Vx1-0005XS-66 for pgsql-bugs@lists.postgresql.org; Wed, 14 Jul 2021 03:52:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 16E3qeup3455197; Tue, 13 Jul 2021 23:52:40 -0400 From: Tom Lane To: "David G. Johnston" cc: Japin Li , John Naylor , =?UTF-8?Q?L=C3=A6titia_Avrot?= , PostgreSQL mailing lists Subject: Re: Statistics updates is delayed when using `commit and chain` In-reply-to: References: <2950681.1626103840@sss.pgh.pa.us> <3453636.1626232720@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Tue, 13 Jul 2021 20:32:58 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3455195.1626234760.1@sss.pgh.pa.us> Date: Tue, 13 Jul 2021 23:52:40 -0400 Message-ID: <3455196.1626234760@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Tue, Jul 13, 2021 at 8:18 PM Tom Lane wrote: >> The protocol contract for that is that NOTIFY is delivered *between* >> transactions. > This is saying "We must not RECEIVE a notification unless the client is > prepared to handle it - idle and not within a transaction." Right. > So, the choice to delay releasing the notification upon committing the > first transaction of a chain is a design choice. Sure, you could argue that. But look at it from the client's side. How would it detangle its response to the notify event from whatever it's doing as part of the chained transaction? You don't want to risk the notify-response action failing because of a problem in the chained transaction, nor vice versa, because they are independent things. (Whatever the notify is about *did* commit, independently of what you are doing.) It's very hard to see how you could do that sanely, other than by delaying handling the notify event till after you're out of the chain. Another angle is that (I think) the proposed patch would allow notifies to be delivered during a commit that happens inside a procedure. At that point, the client doesn't even have control of the connection with which to do something in response to the notify. There might be value in the aspect of the patch that sends statistics upon commit/rollback. But NOTIFY is a *totally* different animal. The fact that the code happens to be physically adjacent in the current implementation doesn't mean that the semantic constraints are similar. regards, tom lane