I happened to notice that currently MemoizePath cannot be generated for
partitionwise join. I traced that and have found the problem. One
condition we need to meet to generate MemoizePath is that inner path's
ppi_clauses should have the form "outer op inner" or "inner op outer",
as checked by clause_sides_match_join in paraminfo_get_equal_hashops.
Note that when are at this check, the inner path has not got the chance
to be re-parameterized (that is done later in try_nestloop_path), so if
it is parameterized, it is parameterized by the topmost parent of the
outer rel, not the outer rel itself. Thus this check performed by
clause_sides_match_join could not succeed if we are joining two child
rels.
The fix is straightforward, just to use outerrel->top_parent if it is
not null and leave the reparameterization work to try_nestloop_path. In
addition, I believe when reparameterizing MemoizePath we need to adjust
its param_exprs too.
Attach the patch for fix.
Thanks
Richard