Re: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18 - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18
Date
Msg-id CAKFQuwYUnr+fnd_3eoPxxyZc9Yiv4zQ3Pc0-cDHcBFerZj+qPA@mail.gmail.com
Whole thread
In response to Re: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18  (Damian Lukowski <pgsql-bugs@arcsin.de>)
Responses Re: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18
List pgsql-bugs
On Thursday, March 12, 2026, Damian Lukowski <pgsql-bugs@arcsin.de> wrote:
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?

IIRC the first five invocations will get replanned using the parameter as a constant; then after either every call will be replanned or none will.

David J.

pgsql-bugs by date:

Previous
From: Damian Lukowski
Date:
Subject: Re: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18
Next
From: Andrew Dunstan
Date:
Subject: Re: BUG #19431: limitation of the data type jsonb equals 8Kb