Which PG version is this exactly? Given the Memoize node shown
in your plan, I suppose 14.something, but is it up to date?
There were Memoize-related bug fixes in 14.2 and 14.4, and the
one in 14.2 looks particularly likely to be relevant.
If you are on the current minor release, does "set enable_memoize = off"
change the behavior?
As always, you hit the nail on the head. set enable_memoize = on fixes the problem!
Version is PostgreSQL 14.1, time to upgrade...
I'm sorry that I wasted your time.