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 1rni8v-00Ef3O-C4 for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 16:53:21 +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 1rni8t-005UAW-VO for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 16:53:20 +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 1rni8t-005TlG-A0 for pgsql-hackers@lists.postgresql.org; Fri, 22 Mar 2024 16:53:19 +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 1rni8q-005sso-9K for pgsql-hackers@lists.postgresql.org; Fri, 22 Mar 2024 16:53:18 +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 42MGrFfc939946; Fri, 22 Mar 2024 12:53:15 -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: <20240322163952.GA2347986@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> <806361.1711069194@sss.pgh.pa.us> <20240322144739.GA2321246@nathanxps13> <20240322145532.GA2346110@nathanxps13> <907785.1711121266@sss.pgh.pa.us> <20240322163952.GA2347986@nathanxps13> Comments: In-reply-to Nathan Bossart message dated "Fri, 22 Mar 2024 11:39:52 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <939944.1711126395.1@sss.pgh.pa.us> Date: Fri, 22 Mar 2024 12:53:15 -0400 Message-ID: <939945.1711126395@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nathan Bossart writes: > On Fri, Mar 22, 2024 at 11:27:46AM -0400, Tom Lane wrote: >> * Do we want to risk back-patching any of this, to fix the performance >> regression in v16? I think that the OP's situation is a pretty >> narrow one, but maybe he's not the only person who managed to dodge >> roles_is_member_of's performance issues in most other cases. > I've heard complaints about performance with many roles before, so I > certainly think this area is worth optimizing. As far as back-patching > goes, my current feeling is that the hash table is probably pretty safe and > provides the majority of the benefit, but anything fancier should probably > be reserved for v17 or v18. Yeah. Although both the catcache and list_append_unique_oid bits are O(N^2), the catcache seems to have a much bigger constant factor --- when I did a "perf" check on the unpatched code, I saw catcache eating over 90% of the runtime and list_member_oid about 2%. So let's fix that part in v16 and call it a day. It should be safe to back-patch the catcache changes as long as we put the new fields at the end of the struct and leave cc_lists present but empty. Would you like to review the catcache patch further, or do you think it's good to go? regards, tom lane