From f2c2e5d64130a876dde539d09d049508820c5063 Mon Sep 17 00:00:00 2001 From: jcoleman Date: Wed, 18 Jan 2023 20:49:42 -0500 Subject: [PATCH v7 3/4] Possible additional checks --- src/backend/optimizer/path/allpaths.c | 32 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index f93c6927b7..58433b762e 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -3019,11 +3019,19 @@ generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows) ListCell *lc; double rows; double *rowsp = NULL; + Relids required_outer = rel->lateral_relids; /* If there are no partial paths, there's nothing to do here. */ if (rel->partial_pathlist == NIL) return; + /* + * Delay gather path creation until the level in the join tree where all + * params used in a worker are generated within that worker. + */ + if (!bms_is_subset(required_outer, rel->relids)) + return; + /* Should we override the rel's rowcount estimate? */ if (override_rows) rowsp = &rows; @@ -3034,12 +3042,16 @@ generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows) * of partial_pathlist because of the way add_partial_path works. */ cheapest_partial_path = linitial(rel->partial_pathlist); - rows = - cheapest_partial_path->rows * cheapest_partial_path->parallel_workers; - simple_gather_path = (Path *) - create_gather_path(root, rel, cheapest_partial_path, rel->reltarget, - rel->lateral_relids, rowsp); - add_path(rel, simple_gather_path); + if (cheapest_partial_path->param_info == NULL || + bms_is_subset(cheapest_partial_path->param_info->ppi_req_outer, rel->relids)) + { + rows = + cheapest_partial_path->rows * cheapest_partial_path->parallel_workers; + simple_gather_path = (Path *) + create_gather_path(root, rel, cheapest_partial_path, rel->reltarget, + rel->lateral_relids, rowsp); + add_path(rel, simple_gather_path); + } /* * For each useful ordering, we can consider an order-preserving Gather @@ -3053,6 +3065,10 @@ generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows) if (subpath->pathkeys == NIL) continue; + if (subpath->param_info != NULL && + !bms_is_subset(subpath->param_info->ppi_req_outer, rel->relids)) + continue; + rows = subpath->rows * subpath->parallel_workers; path = create_gather_merge_path(root, rel, subpath, rel->reltarget, subpath->pathkeys, rel->lateral_relids, rowsp); @@ -3226,6 +3242,10 @@ generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_r (presorted_keys == 0 || !enable_incremental_sort)) continue; + if (subpath->param_info != NULL && + !bms_is_subset(subpath->param_info->ppi_req_outer, rel->relids)) + continue; + /* * Consider regular sort for any path that's not presorted or if * incremental sort is disabled. We've no need to consider both -- 2.32.1 (Apple Git-133)