From: Pavan Deolasee Date: Tue, 21 Jun 2016 12:56:34 +0000 (+0530) Subject: Avoid pushing down evaluation of VALUES clause to a datanode for replicated X-Git-Tag: XL9_5_R1_2~36 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=2bc7c4d4921b57dcab5014fc4ee8c6860ff19de9;p=postgres-xl.git Avoid pushing down evaluation of VALUES clause to a datanode for replicated tables, unless it contains volatile function(s) --- diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 6470f449d1..c5ba9d8dee 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -2718,7 +2718,10 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) } else if (!(IsA(result_plan, Result) && result_plan->lefttree == NULL && - bms_num_members(root->distribution->restrictNodes) == 1)) + ((root->distribution->distributionType == 'H' && + bms_num_members(root->distribution->restrictNodes) == 1) || + (root->distribution->distributionType == 'R' && + !contain_mutable_functions(result_plan->targetlist))))) result_plan = (Plan *) make_remotesubplan(root, result_plan, root->distribution, diff --git a/src/test/regress/expected/updatable_views.out b/src/test/regress/expected/updatable_views.out index 2b7356be8d..efb875c21f 100644 --- a/src/test/regress/expected/updatable_views.out +++ b/src/test/regress/expected/updatable_views.out @@ -1657,14 +1657,12 @@ EXPLAIN (costs off, nodes off) INSERT INTO rw_view1 VALUES (5); --------------------------------------------------------------------------- Remote Subquery Scan on any -> Insert on base_tbl b - -> Remote Subquery Scan on all - Distribute results by R - -> Result + -> Result SubPlan 1 -> Remote Subquery Scan on all -> Index Only Scan using ref_tbl_pkey on ref_tbl r Index Cond: (a = b.a) -(9 rows) +(7 rows) EXPLAIN (costs off, nodes off) UPDATE rw_view1 SET a = a + 5; QUERY PLAN @@ -2027,10 +2025,8 @@ EXPLAIN (costs off, nodes off) INSERT INTO rw_view1 VALUES (2, 'New row 2'); -> Remote Subquery Scan on all -> Index Only Scan using base_tbl_pkey on base_tbl t Index Cond: (id = 2) - -> Remote Subquery Scan on all - Distribute results by R - -> Result - One-Time Filter: ($0 IS NOT TRUE) + -> Result + One-Time Filter: ($0 IS NOT TRUE) Remote Subquery Scan on any -> Update on base_tbl @@ -2042,7 +2038,7 @@ EXPLAIN (costs off, nodes off) INSERT INTO rw_view1 VALUES (2, 'New row 2'); One-Time Filter: $0 -> Index Scan using base_tbl_pkey on base_tbl Index Cond: (id = 2) -(21 rows) +(19 rows) INSERT INTO rw_view1 VALUES (2, 'New row 2'); SELECT * FROM base_tbl; diff --git a/src/test/regress/expected/xc_alter_table.out b/src/test/regress/expected/xc_alter_table.out index 724a6537d5..a12a118919 100644 --- a/src/test/regress/expected/xc_alter_table.out +++ b/src/test/regress/expected/xc_alter_table.out @@ -127,16 +127,13 @@ ALTER TABLE xc_alter_table_2 DROP COLUMN d; ALTER TABLE xc_alter_table_2 DROP COLUMN e; -- Check for query generation of remote INSERT EXPLAIN (VERBOSE true, COSTS false, NODES false) INSERT INTO xc_alter_table_2 VALUES ('Kodek', false); - QUERY PLAN ----------------------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------------------- Remote Subquery Scan on any -> Insert on public.xc_alter_table_2 - -> Remote Subquery Scan on all + -> Result Output: NULL::integer, 'Kodek'::character varying(20), false, NULL::integer, NULL::integer - Distribute results by R - -> Result - Output: NULL::integer, 'Kodek'::character varying(20), false, NULL::integer, NULL::integer -(7 rows) +(4 rows) INSERT INTO xc_alter_table_2 VALUES ('Kodek', false); SELECT b, c FROM xc_alter_table_2 ORDER BY b; @@ -174,16 +171,13 @@ ALTER TABLE xc_alter_table_2 ADD COLUMN a int; ALTER TABLE xc_alter_table_2 ADD COLUMN a2 varchar(20); -- Check for query generation of remote INSERT EXPLAIN (VERBOSE true, COSTS false, NODES false) INSERT INTO xc_alter_table_2 (a, a2, b, c) VALUES (100, 'CEO', 'Gordon', true); - QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------------------------------- Remote Subquery Scan on any -> Insert on public.xc_alter_table_2 - -> Remote Subquery Scan on all + -> Result Output: NULL::integer, 'Gordon'::character varying(20), true, NULL::integer, NULL::integer, 100, 'CEO'::character varying(20) - Distribute results by R - -> Result - Output: NULL::integer, 'Gordon'::character varying(20), true, NULL::integer, NULL::integer, 100, 'CEO'::character varying(20) -(7 rows) +(4 rows) INSERT INTO xc_alter_table_2 (a, a2, b, c) VALUES (100, 'CEO', 'Gordon', true); SELECT a, a2, b, c FROM xc_alter_table_2 ORDER BY b;