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.96) (envelope-from ) id 1w0fak-0026jj-1p for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Mar 2026 12:56:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0fai-00F0Tx-37 for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Mar 2026 12:56:41 +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.96) (envelope-from ) id 1w0fU4-00Ewaf-2n for pgsql-bugs@lists.postgresql.org; Thu, 12 Mar 2026 12:49:49 +0000 Received: from sigil.arcsin.de ([46.38.233.110]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w0fU3-00000001lpY-1TmN for pgsql-bugs@lists.postgresql.org; Thu, 12 Mar 2026 12:49:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=arcsin.de; h= in-reply-to:content-language:references:subject:subject:from :from:mime-version:date:date:message-id:content-type :content-type:x-amavis-category; s=dkim02; t=1773319785; x= 1775134186; bh=QKBRqIZblC2IlyDQR3yaB+m+VRokQj+jNLQZMa3cQFI=; b=R OcBSXz/TZatBSF2F3hp58G9TPeBrUMc3ZMRPAg4PkLKSEKG7fZqnMUrf6eEh1ail Yv5FSuuo5z6zhETPJh1tFTbPd2PdJgPTCVq6dphe4aQQPv+hFYExSX52BaXHfMEb oXVlz0cnTwUtTj7VTInU1Ttmqa2FvJCJT/K9jwHoGhffjuu/BPxtRc6XFP/9THYY sjPC301ScdkkydnC6kZ4ZJwlWmk93kPNtW4vHCGJm0t3jF1xptXr8WWupMZnXIof X22FbpsRVnWvYlOJ5aEmGTQ3RiveUC6hAhb+/EyIcZvjzKjBPfTemtfj3B/bXUlX cHQNqkzqzBqC52C87XxIw== X-Amavis-Category: sigil.arcsin.de; category=Clean Content-Type: multipart/alternative; boundary="------------ypLnbivVHkRyIKzX600txxLm" Message-ID: <0c78c92b-e3f5-42b6-a698-48855a1bd23b@arcsin.de> Date: Thu, 12 Mar 2026 13:49:44 +0100 MIME-Version: 1.0 From: Damian Lukowski Subject: Re: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18 To: "pgsql-bugs@lists.postgresql.org" References: <19428-d9ac6c4d84c0bc81@postgresql.org> <3708.1773251497@sss.pgh.pa.us> Content-Language: en-US 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. --------------ypLnbivVHkRyIKzX600txxLm Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit > On Thursday, March 12, 2026, Damian Lukowski wrote: > >> We have never promised to avoid constant-folding within the >> subexpressions of a CASE [1]. So it was pure accident that >> this example worked before, and I don't think it's a bug that >> it doesn't work now. > > For a better understanding, which one is the constant that is > being folded? I have found several articles explaining constant > folding but their examples are obvious, e.g. `7 + 1` can be folded > to `8` [1, 2], or `1 = 1` can be folded to `TRUE` [3]. > > However, I have not found any articles that resemble this case. > Aren't `arg` and `$1` variables? Where is the boundary between > constants and non-constants? > > The system is capable of postponing planning until (or performing > replanning) after parameter values are known, in which the values they > are given are constants. The `data` table could have millions of rows. Is the planner invoked for every actual call to `func`, or only once before any pages are read? --------------ypLnbivVHkRyIKzX600txxLm Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
On Thursday, March 12, 2026, Damian Lukowski <pgsql-bugs@arcsin.de> wrote:
We have never promised to avoid constant-folding within the
subexpressions of a CASE [1].  So it was pure accident that
this example worked before, and I don't think it's a bug that
it doesn't work now.

For a better understanding, which one is the constant that is being folded? I have found several articles explaining constant folding but their examples are obvious, e.g. `7 + 1` can be folded to `8` [1, 2], or `1 = 1` can be folded to `TRUE` [3].

However, I have not found any articles that resemble this case. Aren't `arg` and `$1` variables? Where is the boundary between constants and non-constants?

The system is capable of postponing planning until (or performing replanning) after parameter values are known, in which the values they are given are constants.
The `data` table could have millions of rows. Is the planner invoked for every actual call to `func`, or only once before any pages are read? --------------ypLnbivVHkRyIKzX600txxLm--