From f58b230ed0dba2a3d396794a2ec84541e321d92d Mon Sep 17 00:00:00 2001 From: David Rowley Date: Mon, 29 Mar 2021 14:47:05 +1300 Subject: 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 --- src/backend/optimizer/util/restrictinfo.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/backend/optimizer/util/restrictinfo.c') diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c index eb113d94c1..59ff35926e 100644 --- a/src/backend/optimizer/util/restrictinfo.c +++ b/src/backend/optimizer/util/restrictinfo.c @@ -137,6 +137,13 @@ make_restrictinfo_internal(PlannerInfo *root, else restrictinfo->leakproof = false; /* really, "don't know" */ + /* + * Mark volatility as unknown. The contain_volatile_functions function + * will determine if there are any volatile functions when called for the + * first time with this RestrictInfo. + */ + restrictinfo->has_volatile = VOLATILITY_UNKNOWN; + /* * If it's a binary opclause, set up left/right relids info. In any case * set up the total clause relids info. -- cgit v1.2.1