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 1qR3qs-000Pwn-9G for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Aug 2023 04:52:50 +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 1qR3qo-002UBk-NI for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Aug 2023 04:52:47 +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 1qR3qo-002UBc-CC for pgsql-hackers@lists.postgresql.org; Wed, 02 Aug 2023 04:52:46 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qR3qh-00051j-88 for pgsql-hackers@postgresql.org; Wed, 02 Aug 2023 04:52:46 +0000 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-56481f2a148so41327a12.0 for ; Tue, 01 Aug 2023 21:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690951957; x=1691556757; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=BqW6Mo0oDViZ3yUbUU2QEtmDVKkzDm6iPYwAVi+ounI=; b=CUJgWaaVblPDTFWP9h/5SZM2co1+X3PcbJ3RCBnijhqnls25LPYyr6dkYe2Xv1ZGtl yYJA8jKkq1s2u1CI3g/AsKzjngXMR8TbzHTnF4Uw99+LsCd8C831oegevj3VohEClKD4 vPNlpC+zI1VG3N4xI/lLEzDp3KRPFnJiLM85V5LpGMy1EehGGi+b8w2nSZufarB9WQHx zY2YVrS7Nz0hFpE8jZpU+idh1MNfERjo34bvDMAUaNRJYok7Csjp4zyeKj+56Tcw1RUx cG1PsVPyeH+j0FVci3I1xpgyJnMBu0LqTKQoXfOJ8lyLNCE3OVVVw1iWK9GHvjFoiU/S Z3ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690951957; x=1691556757; h=in-reply-to:content-transfer-encoding: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=BqW6Mo0oDViZ3yUbUU2QEtmDVKkzDm6iPYwAVi+ounI=; b=krSEHL1aKuBYQr/jkWiR2Ft7csSAjefG2BKBXDaLMPsrBHgCUw2fq/huDDpf76X/x9 outDHiFKrXZCUWqQPgrqAEfZP8mYAxcRjFVDZ/Hanp3xkmMhmZb68RzTY4d+vbn5jrBO 9EcXejjuHqKaP8Zf8uwPlr41d/tC1yc73Mcd0/GS88D8TzWVKaDm1ezci1ogtWmC39Vm 6q/kzBzl4vayFgfD2wyuzyu+orVpn1KZMx48PRD3QTbfSUTaXaMfHC1bZE6To7X2zC2q Itw8aAdlgnBa/UAk1rBwi2Av4p7MEVKUm6/gN3G9Q/Ae5WCFIGz18mjaFd4oXCURht4o o6dw== X-Gm-Message-State: ABy/qLbuQ4Mmy9AVW7aaAYHOAAd/3JRk5Fq9ozXnSkNVZjYit03JUDZD uePvY0ZQjcN6yxP88xDsHgRnBi16mJI= X-Google-Smtp-Source: APBJJlHfFAV6ONvtejbyGzRprxf9n9EEb8p95Lkml1DiZZj9nei0q+NbxVoFnF1//iyHvomoAbTVAg== X-Received: by 2002:a17:90a:eb12:b0:268:2d92:55d3 with SMTP id j18-20020a17090aeb1200b002682d9255d3mr12912071pjz.39.1690951956731; Tue, 01 Aug 2023 21:52:36 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id c8-20020a17090ad90800b002682392506bsm295045pjv.50.2023.08.01.21.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 21:52:35 -0700 (PDT) Date: Tue, 1 Aug 2023 21:52:33 -0700 From: Nathan Bossart To: Jeff Davis Cc: pgsql-hackers@postgresql.org Subject: Re: Faster "SET search_path" Message-ID: <20230802045233.GA866741@nathanxps13> References: <04c8592dbd694e4114a3ed87139a7a04e4363030.camel@j-davis.com> <20230730045105.GB284134@nathanxps13> <715f07647308639fed5389ead1e6c8de16da8eec.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <715f07647308639fed5389ead1e6c8de16da8eec.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Aug 01, 2023 at 04:59:33PM -0700, Jeff Davis wrote: > + List *pair = lfirst(lc); > + char *name = linitial(pair); > + char *value = lsecond(pair); This is definitely a nitpick, but this List of Lists business feels strange to me for some reason. There might be some code that does this, but I typically see this done with two ѕeparate lists and forboth(). I doubt it makes terribly much difference in the end, and I really don't have a strong opinion either way, but it seemed like something that would inevitably come up in this thread. Is there any particular reason you chose to do it this way? > SplitIdentifierString() modifies its input, and it doesn't seem like a > net win in readability if the API sometimes modifies its input > (requiring a copy in the caller) and sometimes does not. I'm open to > suggestion about a refactor here, but I didn't see a clean way to do > so. That's fine by me. > +static inline uint32 > +nspcachekey_hash(SearchPathCacheKey *key) > +{ > + const unsigned char *bytes = (const unsigned char *)key->searchPath; > + int blen = strlen(key->searchPath); > + > + return hash_bytes(bytes, blen) ^ hash_uint32(key->roleid); > +} Any reason not to use hash_combine() here? > I changed it to move the hook so that it's called after retrieving from > the cache. Most of the speedup is still there with no behavior change. > It also means I had to move the deduplication to happen after > retrieving from the cache, which doesn't seem great but in practice the > search path list is not very long so I don't think it will make much > difference. (Arguably, we can do the deduplication before caching, but > I didn't see a big difference so I didn't want to split hairs on the > semantics.) I think you are right. This adds some complexity, but I don't have anything else to propose at the moment. > - /* Now safe to assign to state variables. */ > - list_free(baseSearchPath); > - baseSearchPath = newpath; > - baseCreationNamespace = firstNS; > - baseTempCreationPending = temp_missing; > } > > + /* Now safe to assign to state variables. */ > + list_free(baseSearchPath); > + baseSearchPath = finalPath; > + baseCreationNamespace = firstNS; > + baseTempCreationPending = temp_missing; I'm not following why this logic was moved. > New timings: > > baseline: 4.2s > test query: > without patch: 13.1s > 0001: 11.7s > 0001+0002: 10.5s > 0001+0002+0003: 8.1s Nice. It makes sense that 0003 would provide the most benefit. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com