From e8e621dd34f8600d7219e450de6a501d0ab4c0e8 Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Sat, 18 Mar 2017 20:27:08 +0100 Subject: [PATCH] produce the same plans on replicated tables as XL 9.5 Due to a small difference in adjust_path_distribution(), 9.6 updated the root distribution (to path distribution) whenever it was NULL, unlike XL 9.5. Due to this, adjust_subplan_distribution() skipped the block that restricts the execution on replicated tables to a single node if (subd && !equal(subd, pathd)) { if (IsLocatorReplicated(subd->distributionType) && bms_num_members(subd->restrictNodes) != 1) { ... } } which changed the generated plans from QUERY PLAN --------------------------------------------------------------------------- Remote Subquery Scan on any -> Insert on base_tbl b -> Result SubPlan 1 -> Remote Subquery Scan on all -> Index Only Scan using ref_tbl_pkey on ref_tbl r Index Cond: (a = b.a) (7 rows) to QUERY PLAN --------------------------------------------------------------------------- Remote Subquery Scan on any -> Insert on base_tbl b -> Result SubPlan 1 -> Remote Subquery Scan on any -> Index Only Scan using ref_tbl_pkey on ref_tbl r Index Cond: (a = b.a) (7 rows) While this plan change is mostly harmless (it merely postpones the node selection to from planning to execution time), it generated a lot of regression test failures. --- src/backend/optimizer/plan/planner.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index fffcddd0ff..6bd699310b 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -6236,14 +6236,9 @@ equal_distributions(PlannerInfo *root, Distribution *dst1, static Path * adjust_path_distribution(PlannerInfo *root, Query *parse, Path *path) { - if (!root->distribution) - { - /* - * Inform caller about distribution of the subplan - */ - root->distribution = path->distribution; + /* don't touch paths without distribution attached (catalogs etc.) */ + if ((path->distribution == NULL) && (root->distribution == NULL)) return path; - } if (equal_distributions(root, root->distribution, path->distribution)) { -- 2.39.5