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 1qs8R4-006uFI-Gp for pgsql-general@arkaria.postgresql.org; Sun, 15 Oct 2023 21:14:06 +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 1qs8R2-00CpI4-1b for pgsql-general@arkaria.postgresql.org; Sun, 15 Oct 2023 21:14:04 +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 1qs8R1-00CpHb-ND for pgsql-general@lists.postgresql.org; Sun, 15 Oct 2023 21:14:04 +0000 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qs8Qz-000eGB-UZ for pgsql-general@lists.postgresql.org; Sun, 15 Oct 2023 21:14:03 +0000 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5a7ab31fb8bso45971667b3.1 for ; Sun, 15 Oct 2023 14:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697404440; x=1698009240; darn=lists.postgresql.org; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=YUm92MJH6lyl9/giMHCBKi/53WL/WWSSJwsnc4n2yBc=; b=l+0onDb6OBW+m4FmJL9TpHYf+tX2zZ9sSMsoVXL8ZS+Ne52VKOuraWcgTfGClJBvdZ 8OgHAWHIuIcRMWtc/6ihzw/Q1/gXom5ocJM7QKBUqh3i5VbEQnbHbxnN0MLt3LBzO66m D2n4Jjh8QrjQ6Ww3uNEkzrRa2lV4TxaTWOZx8pzDCsCKVtwMmVi0aDQhC9m9WMqWd7ic cA8MRWlsGe48X8+c1xh+fgzGn6eT8BJxBsZSJ2cFkkRd9AqqD5S4CK86igf9Ja8wos4J 6jCx7wwaY8jQ4PMHm7sSBNFIpUfEJu6xIqRVG4xXGuysf22r7G9Ajstdr0qs2r8jIyvy rfrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697404440; x=1698009240; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=YUm92MJH6lyl9/giMHCBKi/53WL/WWSSJwsnc4n2yBc=; b=kzuKT5GOrYyR8NOc5+6/Kf+NdJXwL0J7BpYC1Hwn9fnlsTwWegIxZxFVhCE2zdefel H+8EnWC4lXZZjiyeP9Z9oMVxw0AZlrJv9ermaqhQ/viZRd5ViejbeGKhsMikfP4MgwMF WQknxKHjfSbaNDBfe72ndwVHfE1Hd90InA16bmdhp/ny9vqBEAaurAZjzpnTkSC3BHGz /mKMiKlOr4WvYd0rvbAQIClIhsEGAAQce9sntgrQvvPECyjvKgCT5vv7HESutcmBOALo zfVIYmXgEVm9zBRsFIV/vgIK94gHonMNavTVZjp3xs4F+RnbdHs9as5+jKa6Pc1AIjJf uC1A== X-Gm-Message-State: AOJu0YwsO+C+IhEfZy12dmzuWryo4Y5YQXj8sBBRTyTr/2Xo63hTR4Js p/Ih7tyfYn9VF9AlmfTOO5nbnTyKKLY= X-Google-Smtp-Source: AGHT+IHsXZlR8JAJOc05l2Sy5a+VqLuDygJKVvLm1UH3r9/NfgPeceiSk8ThQVECluNbOTDzIAhsCA== X-Received: by 2002:a81:8645:0:b0:5a2:20ec:40be with SMTP id w66-20020a818645000000b005a220ec40bemr36672990ywf.29.1697404440626; Sun, 15 Oct 2023 14:14:00 -0700 (PDT) Received: from ?IPV6:2600:1700:bd2c:b810:3504:20dc:f3b1:66d3? ([2600:1700:bd2c:b810:3504:20dc:f3b1:66d3]) by smtp.googlemail.com with ESMTPSA id o11-20020a0dcc0b000000b005463e45458bsm1650035ywd.123.2023.10.15.14.14.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Oct 2023 14:14:00 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------jtQVmsubq6QVPasE0sIG0THZ" Message-ID: <3ca87218-264c-421b-8e2b-59cd93f48bb3@gmail.com> Date: Sun, 15 Oct 2023 16:14:00 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: right way of using case-expressions in plpgsql functions Content-Language: en-US To: pgsql-general@lists.postgresql.org References: From: Ron In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------jtQVmsubq6QVPasE0sIG0THZ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 10/15/23 11:19, Victor Dobrovolsky wrote: [snip] > The documentation states that after some executions of such functions the > plan should become generic. > What is a generic plan for such a case and how would it work? It's highly dependent on the query When I see this happen (after we notice that a procedure starts taking a /long/ time), the query planner flips from a custom plan to a generic plan after about the fifth execution in a session of a function/procedure. This will make it calculate the plan every time: set plan_cache_mode = force_custom_plan; -- Born in Arizona, moved to Babylonia. --------------jtQVmsubq6QVPasE0sIG0THZ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit On 10/15/23 11:19, Victor Dobrovolsky wrote:
[snip]
The documentation states that after some executions of such functions the plan should become generic.
What is a generic plan for such a case and how would it work?

It's highly dependent on the query

When I see this happen (after we notice that a procedure starts taking a long time), the query planner flips from a custom plan to a generic plan after about the fifth execution in a session of a function/procedure.

This will make it calculate the plan every time:
set plan_cache_mode = force_custom_plan;

--
Born in Arizona, moved to Babylonia.
--------------jtQVmsubq6QVPasE0sIG0THZ--