pgsql: Cache if PathTarget and RestrictInfos contain volatile functions

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Cache if PathTarget and RestrictInfos contain volatile functions
Date: 2021-03-29 02:00:17
Message-ID: E1lQhCT-0003tW-2Q@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Cache if PathTarget and RestrictInfos contain volatile functions

Here we aim to reduce duplicate work done by contain_volatile_functions()
by caching whether PathTargets and RestrictInfos contain any volatile
functions the first time contain_volatile_functions() is called for them.
Any future calls for these nodes just use the cached value rather than
going to the trouble of recursively checking the sub-node all over again.
Thanks to Tom Lane for the idea.

Any locations in the code which make changes to a PathTarget or
RestrictInfo which could change the outcome of the volatility check must
change the cached value back to VOLATILITY_UNKNOWN again.
contain_volatile_functions() is the only code in charge of setting the
cache value to either VOLATILITY_VOLATILE or VOLATILITY_NOVOLATILE.

Some existing code does benefit from this additional caching, however,
this change is mainly aimed at an upcoming patch that must check for
volatility during the join search. Repeated volatility checks in that
case can become very expensive when the join search contains more than a
few relations.

Author: David Rowley
Discussion: https://postgr.es/m/3795226.1614059027@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f58b230ed0dba2a3d396794a2ec84541e321d92d

Modified Files
--------------
src/backend/nodes/copyfuncs.c | 1 +
src/backend/nodes/outfuncs.c | 2 +
src/backend/optimizer/path/allpaths.c | 40 +++++++++---------
src/backend/optimizer/plan/initsplan.c | 4 +-
src/backend/optimizer/util/clauses.c | 67 +++++++++++++++++++++++++++++++
src/backend/optimizer/util/restrictinfo.c | 7 ++++
src/backend/optimizer/util/tlist.c | 17 ++++++++
src/include/nodes/pathnodes.h | 16 ++++++++
8 files changed, 134 insertions(+), 20 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Geoghegan 2021-03-29 03:10:19 pgsql: PageAddItemExtended(): Add LP_UNUSED assertion.
Previous Message Stephen Frost 2021-03-28 15:29:24 pgsql: doc: Define TLS as an acronym