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 1rnPD0-00D6lK-ML for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Mar 2024 20:40:19 +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 1rnPCy-00G689-Q4 for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Mar 2024 20:40:17 +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 1rnPCy-00G681-EH for pgsql-hackers@lists.postgresql.org; Thu, 21 Mar 2024 20:40:16 +0000 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rnPCv-005jNF-7y for pgsql-hackers@lists.postgresql.org; Thu, 21 Mar 2024 20:40:15 +0000 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-366fea117acso6379125ab.0 for ; Thu, 21 Mar 2024 13:40:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711053614; x=1711658414; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ggzeEgpswXN8fk/QpMvCk6UvZoTQTZqlucUvAxfCPTg=; b=iKOzpGRZ57LkWBvY5xn3ghpwSteOjEDX2PDZvg9UmkiCcJXWStJrUt1AKp9TR+BWMh ugdPJkzSrrcp/iNZ9On9kJEE0WO43BDJpgpDrOi9mGL0nxwz8lGluuJirbfJ+s9zAF// WS2FvEDv/2o0IqwTwiB4VfQPUyCFu36s8AnVKgQwyD54hWGcxg5FJAY9lmeny3BOCI7S vh555sB3SUt2DMDT2KygqwKp6EATb3jDSXltBFj7CA8JSjUMBJErjO29lWtsG6Ed8kky La/l6QUyT2IUcjVuJJQD87TTzv0UcAtLx1DdmEYVpllnDVRmgZ9rJu/gWkEJJOt2ZZLI rJgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711053614; x=1711658414; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ggzeEgpswXN8fk/QpMvCk6UvZoTQTZqlucUvAxfCPTg=; b=o/JhB5qdncmUwkYj+MGyt99GIztEoF7aWIL3Fq0BlwzmcEkOxonEeKqGQXgJTF74To 4IselRoWFGx5Kw9/oDjW95kf0o4/TzMkTQ7TZlDjqkS4zqMl2MesCAFOxpMX2hUy840b pe68DiDT+g5d+fT30TyAZQ3gpZht0bVloO3RUFtgsOmP4zDPNx3pRUudfNe1VhXkStIW sEPIaQ+V7sXVIWhuEa/sfmwvLmmKYJZiD08F1pJzAkjHov8NYznuR/KDFPBCu25hBURQ hARt7/H43KCDC5R6962+zOs7E3EXBoEFFXBDZ91CFJZltGwsTN9U8IIsXH6oE8onbOgq baRg== X-Gm-Message-State: AOJu0YyfC1OKYH6QMIE1ChPXhXqYCcM9jC4I5CJttm/uGU8lPQZCN4GE n2qCnJOnCO/FxFNDyFExJ0P0UNipdiPaIy+DUKrj4uHterep0E6N X-Google-Smtp-Source: AGHT+IEY8otYePgrElb9LJ5tcGqhHJuoIEC5D37u9DQIv98rhYQvN2s8KF9kq4PzND16UBRJ+xC9Hw== X-Received: by 2002:a92:909:0:b0:368:4fe6:ea12 with SMTP id y9-20020a920909000000b003684fe6ea12mr655540ilg.31.1711053613771; Thu, 21 Mar 2024 13:40:13 -0700 (PDT) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id j1-20020a056e02014100b00364ec1f92d9sm142999ilr.9.2024.03.21.13.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 13:40:13 -0700 (PDT) Date: Thu, 21 Mar 2024 15:40:12 -0500 From: Nathan Bossart To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org, alex work , Robert Haas Subject: Re: Slow GRANT ROLE on PostgreSQL 16 with thousands of ROLEs Message-ID: <20240321204012.GA1992418@nathanxps13> References: <341186.1711037256@sss.pgh.pa.us> <619340.1711050134@sss.pgh.pa.us> <642442.1711053105@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <642442.1711053105@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Mar 21, 2024 at 04:31:45PM -0400, Tom Lane wrote: > 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. Assuming these are larger lists, this might benefit from optimizations involving SIMD intrinsics. I looked into that a while ago [0], but the effort was abandoned because we didn't have any concrete use-cases at the time. (I'm looking into some additional optimizations in a separate thread [1] that would likely apply here, too.) [0] https://postgr.es/m/20230308002502.GA3378449%40nathanxps13 [1] https://postgr.es/m/20240321183823.GA1800896%40nathanxps13 -- Nathan Bossart Amazon Web Services: https://aws.amazon.com