Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vGo72-004Q8V-AY for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Nov 2025 00:44:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vGhhE-003mJj-Kg for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Nov 2025 17:53:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vGhhE-003mJ6-7r for pgsql-hackers@lists.postgresql.org; Wed, 05 Nov 2025 17:53:23 +0000 Received: from mail-yw1-x1129.google.com ([2607:f8b0:4864:20::1129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vGhhB-0069q7-05 for pgsql-hackers@postgresql.org; Wed, 05 Nov 2025 17:53:22 +0000 Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-7866aca9e25so270647b3.3 for ; Wed, 05 Nov 2025 09:53:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762365073; x=1762969873; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5ijXHOxtkI8f4CszkCzitmVsoztjXCwXuT5y7o4DkyI=; b=EtgR8k8wB0jaXeSGxe1UzJ43sEl52tXPBvYS9DHbkF3v7T2eSoMkUO/kr5lFJ1O04Z SEzovcNxJZOYWp+dj67cc5kvjTGPR7D5AknPVC/8l/oItUxkWxqYncbkB/mQYfqnATzZ OJIuR9+iRPyLklQ031JMgj4uOxA0OJafRVRq1IsDuJ4UKXg7OJp6gMu+pUhe3Q8mBGya 6nyJFawQk4gNcuHFDS7fF6Jpo9Fu+w4VMIfmIZZtXtkogE+xxnKi7GPAXUu+0ZUdaB8J 6Cvo25TfVW6hz3cahhvIZ+4xA+TL4ou24HMTAZ9aMY5nCeBIgAiTBGkaUgBNtqaIud9e +6xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762365073; x=1762969873; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5ijXHOxtkI8f4CszkCzitmVsoztjXCwXuT5y7o4DkyI=; b=rm4jNU6VRjPVa6xH+Kt8dOwF2iZriYIV+107g5sWfYnkxmQt+Yl4ukcMG0GXexvRZD s0nJl3J+lrCYGLAEyw2QVsCZmqbS1gz3XuLiwlNr0HPgLWiYcTujaZc7vlyuN+dvBRVH eu56hSAOMV0s3RiG/aiCbdeGYSai24rkFmI7+OY0isl4Xv6ls1gOc4DTjtDgLS/I4GFr g30yv14maO2AK3IEE4Wo7ndexmPIjoTxqX7uNME9Zkk3xEoLdsVoBvqm1sQNWmodz+gr bULlt/bcRby2/EUUl9vQqbBYpIPC19dqWYZWiQ8wZhWk1vN4IpePC2J2Lu0AsopjsGwo gAkQ== X-Forwarded-Encrypted: i=1; AJvYcCWIkxMsrUPX92OW5OU+rYLlWB2pLnvMlel7pKJT+z1hExMW+QST92iOHFpa/w3GSrRSX9Wk30HxuBQgpPna@postgresql.org X-Gm-Message-State: AOJu0YzIexZY/slF/XYYGdCEIKPPQxqMWUOKntmEUBlIuJroTdlon4Pt 7CVA/U17W2uOx1GuUW4AafZV0UvBeIcxMglOvs0sLXkNza90itBeU1H0cFx4n0P+AI7c5tvoGYd Xx22XsWuyLNpZMKq9NGPV7OWhaLrGxCI= X-Gm-Gg: ASbGncuxdUp4y/LrGc/tMTS2w3OYGLWd1T1tSgn/byKaBim6m8hDOfoOpSakySu7T45 yliamY+3323xWx12y311otzUQSFBw+h6pj8ZUxE6AC1A7SriO5dla9+3k5fXH14SlzAxQ/8Saiy ictekZmubSa7eubkAgXXvVi4AUCR6Re4kCQgFNNr4AQKquy4ZeKcM/HoE8FuP5FAeJAGywUQM8T 0BcI7nDSXLbh4oOrLNIf29DJIe2X7izkNVk3MIlfCmEzVX+MRtf4SkY6a8QdxhuYBjNAA== X-Google-Smtp-Source: AGHT+IGuzHisaMAzJERnkj86r/HRhQI0lu96XG5d0Jozo6voEwaUgYhk5iJvGUN8Dbc+o0ZX0HLLXLpOmP2KDg7M3ns= X-Received: by 2002:a05:690c:6ac3:b0:786:5712:46b5 with SMTP id 00721157ae682-786a427cdfemr38240017b3.69.1762365073365; Wed, 05 Nov 2025 09:51:13 -0800 (PST) MIME-Version: 1.0 References: <6899c044-4a82-49be-8117-e6f669765f7e@app.fastmail.com> <165530.1752362320@sss.pgh.pa.us> <02a7cd37-e2fc-4212-8b19-f8c239c95fb8@app.fastmail.com> <96f00bf1-cc9d-4520-9d02-9e14e7767c88@app.fastmail.com> <30c2aa7d-dd6c-4b68-a2e4-f217a1a34acf@app.fastmail.com> <0b4d402a-9ac2-4aa8-acf8-8231dbe579ea@app.fastmail.com> <3095599.1758644879@sss.pgh.pa.us> <0dc6a2cc-5216-4dc1-9dd2-430cafc6095b@app.fastmail.com> <52CC167F-763B-4ECA-B0B4-DAB381816828@gmail.com> <9186C6D0-F7A9-482A-9183-89E530B57E36@gmail.com> <1073593.1759423179@sss.pgh.pa.us> <4bd5e6c4-6fa7-44bb-869d-59a32a331fa8@app.fastmail.com> <85828f29-e72e-4400-94f3-9a69bc8dc239@app.fastmail.com> <2495353.1759860890@sss.pgh.pa.us> <8aeae418-92a6-4bbd-9c06-9574c79e59f7@app.fastmail.com> <2531672.1759868124@sss.pgh.pa.us> <474efa78-337c-41cd-a73a-f845a0115109@app.fastmail.com> <2749343.1759949176@sss.pgh.pa.us> <8bfca2be-1ec0-4e15-aafb-0b7b661fe936@app.fastmail.com> <9eba307f-f2fb-48f0-9507-2e197f39ef9e@app.fastmail.com> <8c71183a-0d28-4bcf-a806-78446ff95404@app.fastmail.com> <1009807.1760476747@sss.pgh.pa.us> <1F7227F5-C33D-4E2C-8511-33F1468590D0@gmail.com> <0a5a20d3-4621-46b3-b2ab-903f63a20dea@app.fastmail.com> <6F913129-ABEF-4004-AAF3-F22FC34!29AE8@gmail.com> <1547585.1760645808@sss.pgh.pa.us> <14865EB6-0BF4-462B-9072-10BDAC10C052@gmail.com> <0BCA1C2D-B92C-459E-B1A6-6D06BA4C62CF@gmail.com> <55d24cbb-e9ef-491f-a99b-b3dbd7cecdf9@app.fastmail.com> <38574cad-e90d-47b7-a015-753bb6bbc360@app.fastmail.com> <66631FB7-5BEA-4ED5-A694-9AD8B9CCFEE8@gmail.com> <4b7b49a5-5e1a-44a8-93e0-60457d15cb1d@app.fastmail.com> <82DEA2B6-6FC5-4A79-BDE3-1FD72F104A6E@gmail.com> <38de1036-d8cf-420c-b845-edb5a946b191@app.fastmail.com> <87E40BF8-8877-4DBD-9040-99AF8A4E6358@gmail.com> <7556f0d4-03fd-451a-bd34-5f62b424319a@app.fastmail.com> <290910DE-9A03-4AE6-B348-073D5DA96ACC@gmail.com> <4B243750-12BE-4C16-A769-A803268F40E3@gmail.com> In-Reply-To: <4B243750-12BE-4C16-A769-A803268F40E3@gmail.com> From: Arseniy Mukhin Date: Wed, 5 Nov 2025 20:51:01 +0300 X-Gm-Features: AWmQ_blpmHi5IZaBkBqOtf4bou4Hg765ICmdJ3GhbSVMqXifQFxXlCFpugOkQQk Message-ID: Subject: Re: Optimize LISTEN/NOTIFY To: Chao Li Cc: Joel Jacobson , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Nov 5, 2025 at 12:22=E2=80=AFPM Chao Li wr= ote: > > > > > On Nov 2, 2025, at 04:41, Arseniy Mukhin = wrote: > > > > This condition seems to be redundant. I would say it should always be > > true, otherwise it would mean that somebody allowed the listener to > > skip our notification. > > Hi Arseniy, > Hi Chao, > Did you read the example I explained in my previous email? > Yes, I read it. Thank you for the example. It shows the case where we can fail to apply 'direct advancement'. I think there are several cases where it can happen. IIUC all such cases are about lagging listeners that failed to catch up with the head before the notifier tries to apply 'direct advancement' to them. Your example is about listeners that finished reading but didn't update their positions because they were stuck on the lock. I think it is also possible that the listener can be in the process of reading or even didn't start reading at all (for example listener backend is in the active transaction at the moment). In these cases we also can't apply direct advancement. Don't know if some of these examples are more important, maybe some of them can be met more frequently. I think the current version of 'direct advancement' will work good for 'sleepy' listeners, but probably can be not very efficient for listeners that get notifications frequently, don't know. But maybe it's ok, we have optimization that sometimes works and have a quite simple implementation. Best regards, Arseniy Mukhin