aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2023-08-07 22:14:21 +1200
committerDavid Rowley <drowley@postgresql.org>2023-08-07 22:14:21 +1200
commit990c3650c535f6fc84d53abb0bd03ad0dd16c576 (patch)
treed218e9b7251f86c456b81bbbce87add562caa52b /src
parentc2e08b04c9e71ac6aabdc7d9b3f8e785e164d770 (diff)
downloadpostgresql-990c3650c535f6fc84d53abb0bd03ad0dd16c576.tar.gz
postgresql-990c3650c535f6fc84d53abb0bd03ad0dd16c576.zip
Don't Memoize lateral joins with volatile join conditions
The use of Memoize was already disabled in normal joins when the join conditions had volatile functions per the code in match_opclause_to_indexcol(). Ordinarily, the parameterization for the inner side of a nested loop will be an Index Scan or at least eventually lead to an index scan (perhaps nested several joins deep). However, for lateral joins, that's not the case and seq scans can be parameterized too, so we can't rely on match_opclause_to_indexcol(). Here we explicitly check the parameterization for volatile functions and don't consider the generation of a Memoize path when such functions are present. Author: Richard Guo Discussion: https://postgr.es/m/CAMbWs49nHFnHbpepLsv_yF3qkpCS4BdB-v8HoJVv8_=Oat0u_w@mail.gmail.com Backpatch-through: 14, where Memoize was introduced
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/path/joinpath.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c
index c1d478d2eb2..059e605e04e 100644
--- a/src/backend/optimizer/path/joinpath.c
+++ b/src/backend/optimizer/path/joinpath.c
@@ -667,6 +667,23 @@ get_memoize_path(PlannerInfo *root, RelOptInfo *innerrel,
return NULL;
}
+ /*
+ * Also check the parameterized path restrictinfos for volatile functions.
+ * Indexed functions must be immutable so shouldn't have any volatile
+ * functions, however, with a lateral join the inner scan may not be an
+ * index scan.
+ */
+ if (inner_path->param_info != NULL)
+ {
+ foreach(lc, inner_path->param_info->ppi_clauses)
+ {
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+
+ if (contain_volatile_functions((Node *) rinfo))
+ return NULL;
+ }
+ }
+
/* Check if we have hash ops for each parameter to the path */
if (paraminfo_get_equal_hashops(root,
inner_path->param_info,