Skip to content

Commit

Permalink
Add Nestloop and MergeJoin cases.
Browse files Browse the repository at this point in the history
Authored-by: Zhang Mingli [email protected]
  • Loading branch information
avamingli committed Oct 9, 2024
1 parent b454e81 commit 7d5b18e
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/backend/optimizer/path/joinpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,9 @@ consider_parallel_nestloop(PlannerInfo *root,

if (jointype == JOIN_UNIQUE_INNER)
jointype = JOIN_INNER;

if (jointype == JOIN_DEDUP_SEMI || jointype == JOIN_DEDUP_SEMI_REVERSE)
jointype = JOIN_INNER;

foreach(lc1, outerrel->partial_pathlist)
{
Expand Down
140 changes: 140 additions & 0 deletions src/test/regress/expected/cbdb_parallel.out
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,146 @@ select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);
500500
(1 row)

-- Parallel Nestloop DEDUP_SEMI
set local min_parallel_table_scan_size = 0;
set local enable_parallel_semi_join = off;
set local enable_nestloop = on;
set local enable_hashjoin = off;
set local enable_mergejoin = off;
set local enable_parallel_semi_join = off;
set local enable_parallel_dedup_semi_reverse_join = off;
set local enable_parallel_dedup_semi_join = on;
explain (costs off)
select sum(bar.b) from bar where exists (select 1 from foo where foo.a = bar.b);
QUERY PLAN
------------------------------------------------------------------------------------------
Finalize Aggregate
-> Gather Motion 3:1 (slice1; segments: 3)
-> Partial Aggregate
-> HashAggregate
Group Key: (RowIdExpr)
-> Redistribute Motion 3:3 (slice2; segments: 3)
Hash Key: (RowIdExpr)
-> Nested Loop
Join Filter: (bar.b = foo.a)
-> Redistribute Motion 3:3 (slice3; segments: 3)
Hash Key: foo.a
-> Seq Scan on foo
-> Materialize
-> Redistribute Motion 3:3 (slice4; segments: 3)
Hash Key: bar.b
-> Seq Scan on bar
Optimizer: Postgres query optimizer
(17 rows)

select sum(bar.b) from bar where exists (select 1 from foo where foo.a = bar.b);
sum
--------
500500
(1 row)

-- Parallel Nestloop DEDUP_SEMI_REVERSE
set local enable_parallel_dedup_semi_reverse_join = on;
set local enable_parallel_dedup_semi_join = off;
explain (costs off)
select sum(bar.b) from bar where exists (select 1 from foo where foo.a = bar.b);
QUERY PLAN
------------------------------------------------------------------------------------------
Finalize Aggregate
-> Gather Motion 3:1 (slice1; segments: 3)
-> Partial Aggregate
-> HashAggregate
Group Key: (RowIdExpr)
-> Redistribute Motion 3:3 (slice2; segments: 3)
Hash Key: (RowIdExpr)
-> Nested Loop
Join Filter: (bar.b = foo.a)
-> Redistribute Motion 3:3 (slice3; segments: 3)
Hash Key: foo.a
-> Seq Scan on foo
-> Materialize
-> Redistribute Motion 3:3 (slice4; segments: 3)
Hash Key: bar.b
-> Seq Scan on bar
Optimizer: Postgres query optimizer
(17 rows)

select sum(bar.b) from bar where exists (select 1 from foo where foo.a = bar.b);
sum
--------
500500
(1 row)

-- Parallel Mergejoin DEDUP_SEMI
set local enable_parallel_semi_join = off;
set local enable_hashjoin = off;
set local enable_mergejoin = on;
set local enable_nestloop = off;
set local enable_parallel_semi_join = off;
set local enable_parallel_dedup_semi_reverse_join = off;
set local enable_parallel_dedup_semi_join = on;
explain (costs off)
select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);
QUERY PLAN
---------------------------------------------------------------------------------------
Finalize Aggregate
-> Gather Motion 3:1 (slice1; segments: 3)
-> Partial Aggregate
-> HashAggregate
Group Key: (RowIdExpr)
-> Redistribute Motion 3:3 (slice2; segments: 3)
Hash Key: (RowIdExpr)
-> Merge Join
Merge Cond: (foo.a = bar.b)
-> Sort
Sort Key: foo.a
-> Broadcast Motion 6:3 (slice3; segments: 6)
-> Parallel Seq Scan on foo
-> Sort
Sort Key: bar.b
-> Seq Scan on bar
Optimizer: Postgres query optimizer
(17 rows)

select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);
sum
--------
500500
(1 row)

-- Parallel Mergejoin DEDUP_SEMI_REVERSE
set local enable_parallel_dedup_semi_reverse_join = on;
set local enable_parallel_dedup_semi_join = off;
explain (costs off)
select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);
QUERY PLAN
---------------------------------------------------------------------------------------
Finalize Aggregate
-> Gather Motion 6:1 (slice1; segments: 6)
-> Partial Aggregate
-> HashAggregate
Group Key: (RowIdExpr)
-> Redistribute Motion 6:6 (slice2; segments: 6)
Hash Key: (RowIdExpr)
Hash Module: 3
-> Merge Join
Merge Cond: (bar.b = foo.a)
-> Sort
Sort Key: bar.b
-> Parallel Seq Scan on bar
-> Sort
Sort Key: foo.a
-> Broadcast Motion 3:6 (slice3; segments: 3)
-> Seq Scan on foo
Optimizer: Postgres query optimizer
(18 rows)

select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);
sum
--------
500500
(1 row)

abort;
-- CBDB(#131): test parallel_workers during create AO/AOCO table take effect
begin;
Expand Down
40 changes: 40 additions & 0 deletions src/test/regress/sql/cbdb_parallel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,46 @@ set local enable_parallel_dedup_semi_reverse_join = off;
explain (costs off)
select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);
select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);

-- Parallel Nestloop DEDUP_SEMI
set local min_parallel_table_scan_size = 0;
set local enable_parallel_semi_join = off;
set local enable_nestloop = on;
set local enable_hashjoin = off;
set local enable_mergejoin = off;
set local enable_parallel_semi_join = off;
set local enable_parallel_dedup_semi_reverse_join = off;
set local enable_parallel_dedup_semi_join = on;
explain (costs off)
select sum(bar.b) from bar where exists (select 1 from foo where foo.a = bar.b);
select sum(bar.b) from bar where exists (select 1 from foo where foo.a = bar.b);

-- Parallel Nestloop DEDUP_SEMI_REVERSE
set local enable_parallel_dedup_semi_reverse_join = on;
set local enable_parallel_dedup_semi_join = off;
explain (costs off)
select sum(bar.b) from bar where exists (select 1 from foo where foo.a = bar.b);
select sum(bar.b) from bar where exists (select 1 from foo where foo.a = bar.b);

-- Parallel Mergejoin DEDUP_SEMI
set local enable_parallel_semi_join = off;
set local enable_hashjoin = off;
set local enable_mergejoin = on;
set local enable_nestloop = off;
set local enable_parallel_semi_join = off;
set local enable_parallel_dedup_semi_reverse_join = off;
set local enable_parallel_dedup_semi_join = on;
explain (costs off)
select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);
select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);

-- Parallel Mergejoin DEDUP_SEMI_REVERSE
set local enable_parallel_dedup_semi_reverse_join = on;
set local enable_parallel_dedup_semi_join = off;
explain (costs off)
select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);
select sum(foo.a) from foo where exists (select 1 from bar where foo.a = bar.b);

abort;


Expand Down

0 comments on commit 7d5b18e

Please sign in to comment.