Skip to content

Commit 990c365

Browse files
committed
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
1 parent c2e08b0 commit 990c365

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/backend/optimizer/path/joinpath.c

+17
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,23 @@ get_memoize_path(PlannerInfo *root, RelOptInfo *innerrel,
667667
return NULL;
668668
}
669669

670+
/*
671+
* Also check the parameterized path restrictinfos for volatile functions.
672+
* Indexed functions must be immutable so shouldn't have any volatile
673+
* functions, however, with a lateral join the inner scan may not be an
674+
* index scan.
675+
*/
676+
if (inner_path->param_info != NULL)
677+
{
678+
foreach(lc, inner_path->param_info->ppi_clauses)
679+
{
680+
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
681+
682+
if (contain_volatile_functions((Node *) rinfo))
683+
return NULL;
684+
}
685+
}
686+
670687
/* Check if we have hash ops for each parameter to the path */
671688
if (paraminfo_get_equal_hashops(root,
672689
inner_path->param_info,

0 commit comments

Comments
 (0)