Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHnaz-0006wr-Na for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Jul 2023 15:42:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qHnay-00017j-H0 for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Jul 2023 15:42:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHnay-00017a-36 for pgsql-hackers@lists.postgresql.org; Fri, 07 Jul 2023 15:42:08 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qHnav-002Yfn-Mb for pgsql-hackers@postgresql.org; Fri, 07 Jul 2023 15:42:06 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-666e6ecb52dso1263521b3a.2 for ; Fri, 07 Jul 2023 08:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20221208.gappssmtp.com; s=20221208; t=1688744524; x=1691336524; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=TUzT7qlxqzOyhsu02UCi/E/14LgCU8alQ+2KcpkTTeQ=; b=ROJI/HBVAFOc2fTysOMxZe13mNhY7vIYjNGmDrRX8kjjAclu7pDoLfRpTmNzZcIpD7 7v2Afw03OyW/eZTZgZFVBT8rvD/iaAtiIpBQ9Qjo6veqZCVLT6iR0oLahLYSoMYf4gWr jKybmdpx2bVEWhkCSCweQudr42wc+fYZNGCJtpGps1ozizl4hGxVJGp1fdSxEmoGTImI h1LgYM11ZvPXOxI5ybT84mzaIE0E8RWiJ7isu7q3lq5LxY2BXjwgcf2DRRrts0g16zeN efMy8ksNnMq9vVmqTATTLZ1ifCBDLH5m7e/7KzKCQrRmk/F6XhHqj3T5dxjSTcUZUIp+ prZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688744524; x=1691336524; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TUzT7qlxqzOyhsu02UCi/E/14LgCU8alQ+2KcpkTTeQ=; b=fpCR/y2/1Xxzm16jQVQ96VNAY7kwzX4oKQYedxhq43bqEl/S35YZPPhWtnmorUmhpX wTSaCZy7SqD7R9HJJzVxbH9tkQBekRxU51dECGQpgQiJHlfRWkYHA7e7z0OniZzADppP S514BdTDq5VuCIFc3YUjt3Cf7zkbm+ebAj1joqaPS86n8WZ8QivPwj2M1Zp/3P/Iio46 lqmaqezDqsasgLJQ897JSA/EPLZ7XHN0Xn6AlURblFkiGC3FbWejkd4ulxHzLwJ3wPOd TWtX3blkXAzKLlHz91uKyBnoSXHaTj9ECU0vIro9yznOHRiqD9Co70TyuB8t0wR2Dhke mQzQ== X-Gm-Message-State: ABy/qLZW5yuVcmx86rH3Ale4VY7QKbe1D3jhFf4A2YeI+u2i5+EZGB3I zY9fygykyJbVvEkvsPKhLmVASQ== X-Google-Smtp-Source: APBJJlHgYybsMHbNromOahn38dad4LRxg5qiPztwB9zxDY5z3MDacY92NxA+1cR/f9uWl1fVyjHTWA== X-Received: by 2002:a05:6a00:98d:b0:67a:9208:87a with SMTP id u13-20020a056a00098d00b0067a9208087amr5435964pfg.23.1688744524170; Fri, 07 Jul 2023 08:42:04 -0700 (PDT) Received: from jeff-laptop.lan (c-73-170-46-202.hsd1.ca.comcast.net. [73.170.46.202]) by smtp.gmail.com with ESMTPSA id z12-20020aa785cc000000b0064928cb5f03sm3060102pfn.69.2023.07.07.08.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 08:42:03 -0700 (PDT) Message-ID: <6781cc79580c464a63fc0a1343637ed2b2b0cf09.camel@j-davis.com> Subject: Re: Fix search_path for all maintenance commands From: Jeff Davis To: Isaac Morland Cc: pgsql-hackers@postgresql.org, Nathan Bossart , Robert Haas , Noah Misch , "David G. Johnston" , Greg Stark , Tom Lane , GurjeetSingh Date: Fri, 07 Jul 2023 08:42:01 -0700 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, 2023-07-06 at 23:22 -0400, Isaac Morland wrote: > Maybe pg_upgrade could apply "SET search_path TO pg_catalog, pg_temp" > to any function used in a functional index that doesn't have a > search_path setting of its own? I don't think we want to go down the road of trying to solve this at upgrade time. > Now I'm doing more reading and I'm worried about SET TIME ZONE (or > more precisely, its absence) and maybe some other ones. That's a good point that it's not limited to search_path, but search_path is by far the biggest problem. For one thing, functions affected by TimeZone or other GUCs are typically marked STABLE, and can't be used in index expressions. Also, search_path affects a lot more functions. =C2=A0 > Change it so by default each function gets handled as if "SET > search_path FROM CURRENT" was applied to it? Yes, that's one idea, along with some syntax to get the old behavior (inherit search_path at runtime) if you want. It feels weird to make search_path too special in the syntax though. If we want a general solution, we could do something like: CREATE FUNCTION ... [DEPENDS ON CONFIGURATION {NONE|{some_guc}[, ...]}] [CONFIGURATION IS {STATIC|DYNAMIC}] where STATIC means "all of the GUC dependencies are SET FROM CURRENT unless specified otherwise" and DYNAMIC means "all of the GUC dependencies come from the session at runtime unless specified otherwise". The default would be "DEPENDS CONFIGURATION search_path CONFIGURATION IS STATIC". That would make search_path special only because, by default, every function would depend on it. Which I think summarizes the reason search_path really is special. That also opens up opportunities to do other things we might want to do: * have a compatibility GUC to set the default back to DYNAMIC * track other dependencies of functions better ("DEPENDS ON TABLE ...") * provide better error messages, like "can't use function xyz in index expression because it depends on configuration parameter foo" * be more consistent about using STABLE to mean that the function depends on a snapshot, rather than overloading it for GUC dependencies The question is, given that the acute problem is search_path, do we want to invent all of the syntax above? Are there other use cases for it, or should we just focus on search_path? > That's what I do for all my functions (maybe hurting performance?). It doesn't look cheap, although I think we could optimize it. > If a view calls a function, shouldn't it be called in the context of > the view's definer/owner? Yeah, there are a bunch of problems along those lines. I don't know if we can solve them all in one release. > Is the fundamental problem that we now find ourselves wanting to do > things that require different defaults to work smoothly? On some > level I suspect we want lexical scoping, which is what most of us > have in our programming languages, in the database; but the database > has many elements of dynamic scoping,=C2=A0and changing that is both a > compatibility break and requires significant changes in the way the > database=C2=A0is designed. Does that suggest another approach? Regards, Jeff Davis