Re: 2 questions about volatile attribute of pg_proc.

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: 2 questions about volatile attribute of pg_proc.
Date: 2021-04-18 15:13:26
Message-ID: CAFj8pRAEf9UYmFRUEw6NGBYthCK9Wne1=AouFxsPBV7SOv7YwA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

ne 18. 4. 2021 v 17:06 odesílatel Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
napsal:

> Hi:
>
> We know volatile is very harmful for optimizers and it is the default
> value (and safest value) if the user doesn't provide that. Asking user
> to set the value is not a good experience, is it possible to auto-generate
> the value for it rather than use the volatile directly for user defined
> function. I
> think it should be possible, we just need to scan the PlpgSQL_stmt to see
> if there
> is a volatile function?
>

plpgsql_check does this check - the performance check check if function can
be marked as stable

https://github.com/okbob/plpgsql_check

I don't think so this can be done automatically - plpgsql does not check
objects inside in registration time. You can use objects and functions that
don't exist in CREATE FUNCTION time. And you need to know this info before
optimization time. So if we implement this check automatically, then
planning time can be increased a lot.

Regards

Pavel

> The second question "It is v for “volatile” functions, whose results might
> change at any time.
> (Use v also for functions with side-effects, so that calls to them cannot
> get optimized away.)"
> I think they are different semantics. One of the results is volatile
> functions can't be removed
> by remove_unused_subquery_output even if it doesn't have side effects. for
> example:
> select b from (select an_expensive_random(), b from t); Is it by design
> on purpose?
>
>
> --
> Best Regards
> Andy Fan (https://www.aliyun.com/)
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-04-18 15:29:42 Re: Bogus collation version recording in recordMultipleDependencies
Previous Message Andy Fan 2021-04-18 15:06:15 2 questions about volatile attribute of pg_proc.