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 1tzIDC-000OCp-Mf for pgsql-general@arkaria.postgresql.org; Mon, 31 Mar 2025 16:42:10 +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 1tzIDB-008WFo-6Q for pgsql-general@arkaria.postgresql.org; Mon, 31 Mar 2025 16:42:09 +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 1tzIDA-008WFf-Rb for pgsql-general@lists.postgresql.org; Mon, 31 Mar 2025 16:42:08 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tzID9-002Ahj-01 for pgsql-general@postgresql.org; Mon, 31 Mar 2025 16:42:07 +0000 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-3031354f134so6045217a91.3 for ; Mon, 31 Mar 2025 09:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743439326; x=1744044126; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=gbA/mTDSYYiFJiSGXeLOpUgOELcS5B4yHFybYUP8dIM=; b=fXC8TTp/V9gUydLJAEMKd/OoEop3n9LtQJienfTtttmdxLLSUwzptm/v1LikuqUkWy DfICgTKlyWb5itEYzICPj6H+ML7omzUGfHutNP+mZ+XS5V4+3yFXSmdNXjrTc/8spmyU Q4ZiNK7C9Mp2dP/VxUkMwvEI6xrimC67PdpotolXS3j55XtdgSdgSOT4IR3BadyVUH2X SZsSOiqH/9DhqZ6uUQhFu86EDghhSRiah1bTCiRLTxDEJrbJ9bkwZIP8X6H26fKGDhDV 4ugtcnM1luPHDUNcH4b8X6a7EfIlOOJf0H0dHLhYnHh+5v2EmLIosIqnKK1R8d80091Q 1Pqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743439326; x=1744044126; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gbA/mTDSYYiFJiSGXeLOpUgOELcS5B4yHFybYUP8dIM=; b=WT6oBIomh9xEV/HBnFzwzHrTknxwcfghJhbHtVnU8+RT1C6WBEaz6YztE8XttM4v68 9rfdfOFBYs96RQPerLfy5+IYw8oiBlSOMNgc3lUpgHthqAVuQEj7hj2gQe5xGSl9WlEl aNlxAnVqlXOEkZJ1XZ+wfkt85XfOFHsqIequpNJDWbPj4muD9wSgigrVvT4vEjYOmCjn ouc5Kic1polQHX5uijxOwIweNT1HX/yIZS/MT3spn4mgdqFKSNY/N72NO4UcV8v4WLaO TQTtGmVljCYEbDKMqAmuNO3UTkR5nT+uDBORKJvrRFlKMpIOqaTky5sXE8Mk3imDJArr 85xA== X-Forwarded-Encrypted: i=1; AJvYcCXVx44lBAjSRJ5Cv5WsBtbXZTVawLock3JNOSpyouhbWqwpf/LkHPJACZrZK20VbJ5lnZnOvEl9GG9hU1mQ@postgresql.org X-Gm-Message-State: AOJu0YyS+kDhtmM3Z8kFRZiI1ewSD6CEbiN7zfq6FeHpGQSksjQgyxiP 1K8T7PO44MY4nG4vjQeDCdQfp2UTBZpCoKX+c8oY9AViS1F1miMLvRqb3dPB3aGnS8PnNdadKGi dLE0y5i2v+hDaLuGh1fM3Xr1LoXU= X-Gm-Gg: ASbGncuGonL2BJUikNEfZuwJhLbHjFOsCDnlYA4v5XmbavuRZp2zdo6A+clKOJmVPEc 5/UGj/ZQC/l16SWgO2M4cegCwL6bzgb2+9SUBhLS5rUyPTo7SJrq9DwEHk1EoOR8K7yJjKooWEu ErYi1xdHy4/ywbQNcrOxRgLfon+4g= X-Google-Smtp-Source: AGHT+IFO94VKLL4PCYB/jz/EcRE/WYYgPI05wb49dxL4rAHXrlwaEgGoz2jTFjLokCLtVY3WT7LCxbOfoueruddv5ZM= X-Received: by 2002:a17:90b:2389:b0:305:5f25:59a5 with SMTP id 98e67ed59e1d1-3055f25715cmr786617a91.35.1743439325635; Mon, 31 Mar 2025 09:42:05 -0700 (PDT) MIME-Version: 1.0 References: <01020195b987abd3-a008b77d-8c63-4931-80a4-be36a351c8b2-000000@eu-west-1.amazonses.com> <01020195dd9e8337-c912f36d-54ef-4d3c-a00d-5e697b308d33-000000@eu-west-1.amazonses.com> In-Reply-To: From: Renan Alves Fonseca Date: Mon, 31 Mar 2025 18:41:54 +0200 X-Gm-Features: AQ5f1JpEb2BeyQG9shYwRhdJEL9nJ-EnTFdvGnYhjA-A6aZM8DLNgu2lE3c04Mc Message-ID: Subject: Re: Querying one partition in a function takes locks on all partitions To: David Rowley Cc: Evgeny Morozov , pgsql-general Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Mar 31, 2025 at 5:10=E2=80=AFAM David Rowley = wrote: > > On Sat, 29 Mar 2025 at 10:30, Renan Alves Fonseca > wrote: > > Currently, in the SQL function path the plan is always generic. The > > planner ignores the function arguments. The plan_cache_mode setting > > has no effect in this path. > > > > I agree that the docs should be more explicit about this. There is a > > high penalty for using generic plans in complex functions. > > If you have any suggestions about where you think those should be > added or wording for that, please feel free to suggest. > There is a specific chapter about functions written in SQL: [1]. It is in an advanced section of the docs, so I think it is a suitable place to address this level of detail. There is a Note that says: "The entire body of an SQL function is parsed before any of it is executed. While an SQL function can contain commands that alter ..." I would add another Note below like: "Except when inlined, an SQL function is always executed with a generic plan. This behavior may not be desired in some situations, and it will be fixed in future versions." I'm not sure if we should mention the fix or if we should mention a workaround... If I understood well [2], then both notes may be discarded together in the next version. Renan [1] https://www.postgresql.org/docs/17/xfunc-sql.html [2] https://www.postgresql.org/message-id/db42573039cc66815e80a48589eebea8%= 40postgrespro.ru