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 1rnTGQ-00DS7Z-Jh for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 01:00:07 +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 1rnTGO-00HVNS-DH for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 01:00:04 +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 1rnTGO-00HVNJ-3p for pgsql-hackers@lists.postgresql.org; Fri, 22 Mar 2024 01:00:04 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnTGH-005owe-Td for pgsql-hackers@lists.postgresql.org; Fri, 22 Mar 2024 01:00:03 +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 42M0xscH806362; Thu, 21 Mar 2024 20:59:54 -0400 From: Tom Lane To: Nathan Bossart cc: pgsql-hackers@lists.postgresql.org, alex work , Robert Haas Subject: Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs In-reply-to: <20240322005139.GA2060816@nathanxps13> References: <341186.1711037256@sss.pgh.pa.us> <619340.1711050134@sss.pgh.pa.us> <642442.1711053105@sss.pgh.pa.us> <20240321204012.GA1992418@nathanxps13> <20240322005139.GA2060816@nathanxps13> Comments: In-reply-to Nathan Bossart message dated "Thu, 21 Mar 2024 19:51:39 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <806360.1711069194.1@sss.pgh.pa.us> Date: Thu, 21 Mar 2024 20:59:54 -0400 Message-ID: <806361.1711069194@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nathan Bossart writes: > On Thu, Mar 21, 2024 at 03:40:12PM -0500, Nathan Bossart wrote: >> On Thu, Mar 21, 2024 at 04:31:45PM -0400, Tom Lane wrote: >>> I don't think we have any really cheap way to de-duplicate the role >>> OIDs, especially seeing that it has to be done on-the-fly within the >>> collection loop, and the order of roles_list is at least potentially >>> interesting. Not sure how to make further progress without a lot of >>> work. >> Assuming these are larger lists, this might benefit from optimizations >> involving SIMD intrinsics. > Never mind. With the reproduction script, I'm only seeing a ~2% > improvement with my patches. Yeah, you cannot beat an O(N^2) problem by throwing SIMD at it. However ... I just remembered that we have a Bloom filter implementation in core now (src/backend/lib/bloomfilter.c). How about using that to quickly reject (hopefully) most role OIDs, and only do the list_member_oid check if the filter passes? regards, tom lane