make sure LockRows paths preserve distribution, update plans in xc_for_update
authorTomas Vondra <[email protected]>
Sun, 22 Jan 2017 19:40:00 +0000 (20:40 +0100)
committerTomas Vondra <[email protected]>
Sun, 22 Jan 2017 19:40:00 +0000 (20:40 +0100)
LockRows paths were not preserving the subpath's distribution, so fix
that. Also update minor plan difference (VERBOSE now shows sort key
for the redistribution step).

src/backend/optimizer/util/pathnode.c
src/test/regress/expected/xc_for_update.out

index ae8faf3a2a13d542778e044438f405cdb4b8e46f..7bd784078685b286c6f337e5c1d9addfc092ca7a 100644 (file)
@@ -4350,6 +4350,8 @@ create_lockrows_path(PlannerInfo *root, RelOptInfo *rel,
        pathnode->path.parallel_workers = 0;
        pathnode->path.rows = subpath->rows;
 
+       pathnode->path.distribution = copyObject(subpath->distribution);
+
        /*
         * The result cannot be assumed sorted, since locking might cause the sort
         * key columns to be replaced with new values.
index 5d4476bd2ff6fd86c323cefda39310e346111cde..30a2f073218dd0ba43dc1e83e811d4aa499cbe28 100644 (file)
@@ -218,6 +218,7 @@ explain (costs off, num_nodes off, nodes off, verbose on)  select * from t1 join
          ->  Remote Subquery Scan on all
                Output: t3.val, t3.val2
                Distribute results by H: val2
+               Sort Key: t3.val2
                ->  Sort
                      Output: t3.val, t3.val2
                      Sort Key: t3.val2
@@ -231,6 +232,7 @@ explain (costs off, num_nodes off, nodes off, verbose on)  select * from t1 join
                      ->  Remote Subquery Scan on all
                            Output: t1.val, t1.val2
                            Distribute results by H: val2
+                           Sort Key: t1.val2
                            ->  Sort
                                  Output: t1.val, t1.val2
                                  Sort Key: t1.val2
@@ -241,12 +243,13 @@ explain (costs off, num_nodes off, nodes off, verbose on)  select * from t1 join
                            ->  Remote Subquery Scan on all
                                  Output: t2.val, t2.val2
                                  Distribute results by H: val2
+                                 Sort Key: t2.val2
                                  ->  Sort
                                        Output: t2.val, t2.val2
                                        Sort Key: t2.val2
                                        ->  Seq Scan on public.t2
                                              Output: t2.val, t2.val2
-(36 rows)
+(39 rows)
 
 explain (costs off, num_nodes off, nodes off, verbose on)  select * from t1 join t2 on (t1.val2 = t2.val2) join t3 on (t1.val2 = t3.val2) for update;
 ERROR:  FOR UPDATE is not allowed with joins
@@ -422,8 +425,8 @@ explain (costs off, num_nodes off, nodes off, verbose on)  WITH q1 AS (SELECT *
 select * from p1 order by 1 for update;
   a  |  b  
 -----+-----
-  77 |  88
   55 |  66
+  77 |  88
  111 | 222
  123 | 345
 (4 rows)