Re: Volatile functions under Memoize node

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Andrei Lepikhov <lepihov(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>, Richard Guo <guofenglinux(at)gmail(dot)com>
Subject: Re: Volatile functions under Memoize node
Date: 2024-09-20 02:36:47
Message-ID: CAApHDvopmkAOecfQczbOvkVvo=OK89rABXujVYsFevsk77Dqdw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 20 Sept 2024 at 04:47, Andrei Lepikhov <lepihov(at)gmail(dot)com> wrote:
> Excuse me if I made noise in vain. After discovering the limits of the
> Memoize node, I realized that volatile functions are allowed under the
> Memoize. Example:

I don't think we're particularly consistent about the number of
evaluations of volatile functions in general.

Here's something crafted up without Memoize:

create function volatilefunc(p int) returns int as $$
begin
raise notice '%', p;
return p;
end;
$$ language plpgsql volatile;

explain analyze select * from (values(1),(2)) t1(v) where t1.v
in(select t2.v from (values(1),(2)) t2(v) inner join (values(1),(2))
t3(v) on t2.v = volatilefunc(t3.v));

Normally:
NOTICE: 1
NOTICE: 2
NOTICE: 1
NOTICE: 2

But:
set enable_hashagg = 0;
set enable_hashjoin = 0;
set enable_material = 0;
set enable_sort = 0;

gives:
NOTICE: 1
NOTICE: 1
NOTICE: 2
NOTICE: 1
NOTICE: 2

I'm not sure if it's a good idea to penalise your case when we're not
all that consistent to start with. Is this causing some sort of
breakage?

David

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrei Lepikhov 2024-09-20 03:25:49 Re: Volatile functions under Memoize node
Previous Message Thomas Munro 2024-09-19 23:37:37 Re: [EXTERNAL] Re: Windows Application Issues | PostgreSQL | REF # 48475607