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 1v9SX0-000q0K-Mx for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 18:16:54 +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 1v9SWz-00EdzM-KB for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 18:16:52 +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 1v9SWz-00EdzE-2O for pgsql-hackers@lists.postgresql.org; Thu, 16 Oct 2025 18:16:52 +0000 Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v9SWv-002ZWz-04 for pgsql-hackers@postgresql.org; Thu, 16 Oct 2025 18:16:51 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id D84C8140010B; Thu, 16 Oct 2025 14:16:46 -0400 (EDT) Received: from phl-imap-03 ([10.202.2.93]) by phl-compute-04.internal (MEProxy); Thu, 16 Oct 2025 14:16:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1760638606; x=1760725006; bh=48HxLzEWOd4n8apD7VbqERAsUB3hCpWUeKbS9XEeIlk=; b= M1jQix6iFCW2Vjg83FHEgFgVkZTj6LUqW4HE6jYBgGmdbY2eiwHPwDTxcxtrEGmO na49fWDVro9KyuZXJsIQ28HtIPi6J7Zim+ZB3aZwmk9H/Sfex6pByS2OZuAZ/fHv COZYI2xIUyJoizL26i1G1YSDSG4bK2wcIofdPGh/vPiF0fHM59cUJvHO1EYnn7ez nIzw0AC0aOhmU9r6LH5SjpqJojHtqbvjEsNNf3lHhl6DoW5KPc3urbinGrfURpfU Tx/s8VrQO8Kp5+HDOqcIFaTzzi8iqBQnj/CYqeunOZp+ZmGK9sf+lScL9tBBgT+q 0K/1L0IdS2rQM4y3c3hQnw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1760638606; x= 1760725006; bh=48HxLzEWOd4n8apD7VbqERAsUB3hCpWUeKbS9XEeIlk=; b=E LlcuY3kOdtbyb01B0/TD5nMEGyqSNE3+7ACX84G6hm80x0ev96W3AIHQZUu6pmzp cn7uy+05MTHhhsnx6CDbcYCxwAbFDXKIbfXs8Jn9HjQrzP2Uixhw84aaP8m6ZBDi cJ6ct+DI3eLOKSZPVs2BMtSS7lhEOP6KWLed2uuZ3GD7QOouvrRRlOC7r9FU5r/3 U5uijilnex3/O+ifU3v2lRQy+kaweKZMboctP57bi5NAROwwzmYobBbn32G5KqVi Uo4rNq62sSk1UASv2leaompUvHhd4d63Kr7jxGCPHhfNy9GtOB7UzjtZlnTYE0G/ /IoBfSN6wJ/alnD5JI64Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduvdeileekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefoggffhffvvefkjghfufgtgfesthhqre dtredtjeenucfhrhhomhepfdflohgvlhculfgrtghosghsohhnfdcuoehjohgvlhestgho mhhpihhlvghrrdhorhhgqeenucggtffrrghtthgvrhhnpedugeejgefgteetiefgffegtd efleffffekuefhleduuefgffeitdefledtvdeufeenucffohhmrghinhepghhithhhuhgs rdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epjhhovghlsegtohhmphhilhgvrhdrohhrghdpnhgspghrtghpthhtohepfedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtoheplhhirdgvvhgrnhdrtghhrghosehgmhgrihhlrd gtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhl rdhorhhgpdhrtghpthhtohepthhglhesshhsshdrphhghhdrphgrrdhush X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 26A9718E0054; Thu, 16 Oct 2025 14:16:46 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: AZ7XRsRLdGms Date: Thu, 16 Oct 2025 20:16:25 +0200 From: "Joel Jacobson" To: "Chao Li" Cc: "Tom Lane" , pgsql-hackers Message-Id: In-Reply-To: <6F913129-ABEF-4004-AAF3-F22FC3429AE8@gmail.com> 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-F22FC3429AE8@gmail.com> Subject: Re: Optimize LISTEN/NOTIFY 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 Thu, Oct 16, 2025, at 04:54, Chao Li wrote: >> On Oct 15, 2025, at 23:36, Joel Jacobson wrote: >> The latest version gets rid of GetPendingNotifyChannels() >> and replaces it with the local list pendingNotifyChannels. > > Sorry for the typo, Yes, I meant to dynahash=E2=80=9D that you have al= ready=20 > been using it. ... > My suggestion of using dynahah was for the same purpose. Because=20 > list_member_ptr() iterates through all list nodes until find the=20 > target, so this code is still O(n^2). > > Using a hash will make it faster. I used to work on project Concourse=20 > [1]. The system is heavily using the LISTEN/NOTIFY mechanism. There=20 > would be thousands of channels at runtime. In that case, hash search=20 > would be much faster than linear search. > > [1] https://github.com/concourse/concourse Building pendingNotifyChannels is O(N^2) yes, but how large N is realistic here? Note that pendingNotifyChannels is only the unique channels for the notifications in the *current transaction*. At Concourse, did you really do thousands of NOTIFY, with unique channel names, within the same transaction? /Joel