Avoid pushing down evaluation of VALUES clause to a datanode for replicated
authorPavan Deolasee <[email protected]>
Tue, 21 Jun 2016 12:56:34 +0000 (18:26 +0530)
committerPavan Deolasee <[email protected]>
Tue, 21 Jun 2016 12:56:34 +0000 (18:26 +0530)
tables, unless it contains volatile function(s)

src/backend/optimizer/plan/planner.c
src/test/regress/expected/updatable_views.out
src/test/regress/expected/xc_alter_table.out

index 6470f449d1d7960fae41f142bfdf7cf9ebec101b..c5ba9d8deedfa7ddc4a96052e337e1fe1fda209f 100644 (file)
@@ -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,
index 2b7356be8d56f262f4caddd4bf8072feae5507cb..efb875c21f2382577a862ed862893f2492acdb21 100644 (file)
@@ -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;
index 724a6537d5a6c61ea13a0e41a643f9d495e111ce..a12a11891908a30048e9ba9e6b4e16c4fcfd32d4 100644 (file)
@@ -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;