Fix unstable test in select_parallel.sql
authorRichard Guo <rguo@postgresql.org>
Mon, 22 Jul 2024 02:29:21 +0000 (11:29 +0900)
committerRichard Guo <rguo@postgresql.org>
Mon, 22 Jul 2024 02:29:21 +0000 (11:29 +0900)
One test case added in 22d946b0f verifies the plan of a non-parallel
nestloop join.  The planner's choice of join order is arbitrary, and
slight variations in underlying statistics could result in a different
displayed plan.  To stabilize the test result, here we enforce the
join order using a lateral join.

While here, modify the test case to verify that parallel nestloop join
is not generated if the inner path is not parallel-safe, which is what
we wanted to test in 22d946b0f.

Reported-by: Alexander Lakhin as per buildfarm
Author: Richard Guo
Discussion: https://postgr.es/m/7c09a439-e48d-5460-cfa0-a371b1a57066@gmail.com

src/test/regress/expected/select_parallel.out
src/test/regress/sql/select_parallel.sql

index 7487ea0b820c5da5641c9d05b35ff15956809972..5a603f86b7366dbacd18080f8df658f4fcb04a51 100644 (file)
@@ -656,7 +656,7 @@ reset enable_nestloop;
 -- test parallel nestloop join path with materialization of the inner path
 alter table tenk2 set (parallel_workers = 0);
 explain (costs off)
-   select * from tenk1 t1, tenk2 t2 where t1.two > t2.two;
+select * from tenk1 t1, tenk2 t2 where t1.two > t2.two;
                 QUERY PLAN                 
 -------------------------------------------
  Gather
@@ -668,18 +668,23 @@ explain (costs off)
                ->  Seq Scan on tenk2 t2
 (7 rows)
 
--- the joinrel is not parallel-safe due to the OFFSET clause in the subquery
+-- test that parallel nestloop join is not generated if the inner path is
+-- not parallel-safe
 explain (costs off)
-   select * from tenk1 t1, (select * from tenk2 t2 offset 0) t2 where t1.two > t2.two;
+select * from tenk1 t1
+    left join lateral
+      (select t1.unique1 as x, * from tenk2 t2 order by 1) t2
+    on true
+where t1.two > t2.two;
                 QUERY PLAN                 
 -------------------------------------------
  Nested Loop
-   Join Filter: (t1.two > t2.two)
    ->  Gather
          Workers Planned: 4
          ->  Parallel Seq Scan on tenk1 t1
-   ->  Materialize
-         ->  Seq Scan on tenk2 t2
+   ->  Subquery Scan on t2
+         Filter: (t1.two > t2.two)
+         ->  Seq Scan on tenk2 t2_1
 (7 rows)
 
 alter table tenk2 reset (parallel_workers);
index 9b019d31ed71ed1a28f82c89c6f807013f759021..c7df8f775cee90d6975a27239aa2847468cedb32 100644 (file)
@@ -269,11 +269,16 @@ reset enable_nestloop;
 -- test parallel nestloop join path with materialization of the inner path
 alter table tenk2 set (parallel_workers = 0);
 explain (costs off)
-   select * from tenk1 t1, tenk2 t2 where t1.two > t2.two;
+select * from tenk1 t1, tenk2 t2 where t1.two > t2.two;
 
--- the joinrel is not parallel-safe due to the OFFSET clause in the subquery
+-- test that parallel nestloop join is not generated if the inner path is
+-- not parallel-safe
 explain (costs off)
-   select * from tenk1 t1, (select * from tenk2 t2 offset 0) t2 where t1.two > t2.two;
+select * from tenk1 t1
+    left join lateral
+      (select t1.unique1 as x, * from tenk2 t2 order by 1) t2
+    on true
+where t1.two > t2.two;
 alter table tenk2 reset (parallel_workers);
 
 -- test gather merge