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 1rnP4p-00D6Cf-0I for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Mar 2024 20:31:51 +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 1rnP4n-00G3kq-KR for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Mar 2024 20:31:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnP4n-00G3kh-B3 for pgsql-hackers@lists.postgresql.org; Thu, 21 Mar 2024 20:31:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnP4k-005jJN-9V for pgsql-hackers@lists.postgresql.org; Thu, 21 Mar 2024 20:31: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 42LKVj2q642443; Thu, 21 Mar 2024 16:31:45 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org cc: alex work , Robert Haas Subject: Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs In-reply-to: <619340.1711050134@sss.pgh.pa.us> References: <341186.1711037256@sss.pgh.pa.us> <619340.1711050134@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 21 Mar 2024 15:42:14 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <642441.1711053105.1@sss.pgh.pa.us> Date: Thu, 21 Mar 2024 16:31:45 -0400 Message-ID: <642442.1711053105@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > ... I still see the problematic GRANT taking ~250ms, compared > to 5ms in v15. roles_is_member_of is clearly on the hook for that. Ah: looks like that is mainly the fault of the list_append_unique_oid calls in roles_is_member_of. That's also an O(N^2) cost of course, though with a much smaller constant factor. 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. regards, tom lane