Skip to content

Commit 0cd5c60

Browse files
committed
Fix NULL locus of Shared Scan.
The shared scan needs its locus type and parallel number to be explicitly set when `gp_cte_sharing` is used, even without parallelism. Failing to do so resulted in an incorrect NULL locus appearing in the query plan. Fix #1376 Authored-by: Zhang Mingli avamingli@gmail.com
1 parent 1ca7a64 commit 0cd5c60

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

src/backend/optimizer/plan/planshare.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ make_shareinputscan(PlannerInfo *root, Plan *inputplan)
5252
sisc->scan.plan.plan_rows = inputplan->plan_rows;
5353
sisc->scan.plan.plan_width = inputplan->plan_width;
5454

55+
sisc->scan.plan.locustype = inputplan->locustype;
56+
sisc->scan.plan.parallel = 0; /* No parallel ShareInputScan */
57+
5558
return sisc;
5659
}
5760

src/test/regress/expected/cbdb_parallel.out

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3516,7 +3516,59 @@ WHERE e.salary > (
35163516
David
35173517
(2 rows)
35183518

3519-
3519+
--
3520+
-- Test https://github.com/apache/cloudberry/issues/1376
3521+
--
3522+
create table t1(a int, b int);
3523+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table.
3524+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
3525+
create table t2 (like t1);
3526+
NOTICE: table doesn't have 'DISTRIBUTED BY' clause, defaulting to distribution columns from LIKE table
3527+
set gp_cte_sharing = on;
3528+
explain(locus, costs off) with x as
3529+
(select a, count(*) as b from t1 group by a union all
3530+
select a, count(*) as b from t2 group by a)
3531+
select count(*) from x a join x b on a.a = b.b;
3532+
QUERY PLAN
3533+
------------------------------------------------------------------------
3534+
Finalize Aggregate
3535+
Locus: Entry
3536+
-> Gather Motion 3:1 (slice1; segments: 3)
3537+
Locus: Entry
3538+
-> Partial Aggregate
3539+
Locus: Hashed
3540+
-> Hash Join
3541+
Locus: Hashed
3542+
Hash Cond: (b.b = a.a)
3543+
-> Redistribute Motion 3:3 (slice2; segments: 3)
3544+
Locus: Hashed
3545+
Hash Key: b.b
3546+
-> Subquery Scan on b
3547+
Locus: Strewn
3548+
-> Shared Scan (share slice:id 2:0)
3549+
Locus: Hashed
3550+
-> Hash
3551+
Locus: Hashed
3552+
-> Subquery Scan on a
3553+
Locus: Hashed
3554+
-> Shared Scan (share slice:id 1:0)
3555+
Locus: Hashed
3556+
-> Append
3557+
Locus: Hashed
3558+
-> HashAggregate
3559+
Locus: Hashed
3560+
Group Key: t1.a
3561+
-> Seq Scan on t1
3562+
Locus: Hashed
3563+
-> HashAggregate
3564+
Locus: Hashed
3565+
Group Key: t2.a
3566+
-> Seq Scan on t2
3567+
Locus: Hashed
3568+
Optimizer: Postgres query optimizer
3569+
(35 rows)
3570+
3571+
reset gp_cte_sharing;
35203572
reset enable_parallel;
35213573
reset min_parallel_table_scan_size;
35223574
-- start_ignore

src/test/regress/sql/cbdb_parallel.sql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,20 @@ WHERE e.salary > (
11321132
SELECT AVG(salary)
11331133
FROM employees
11341134
WHERE department_id = e.department_id);
1135-
1135+
1136+
--
1137+
-- Test https://github.com/apache/cloudberry/issues/1376
1138+
--
1139+
create table t1(a int, b int);
1140+
create table t2 (like t1);
1141+
set gp_cte_sharing = on;
1142+
1143+
explain(locus, costs off) with x as
1144+
(select a, count(*) as b from t1 group by a union all
1145+
select a, count(*) as b from t2 group by a)
1146+
select count(*) from x a join x b on a.a = b.b;
1147+
1148+
reset gp_cte_sharing;
11361149
reset enable_parallel;
11371150
reset min_parallel_table_scan_size;
11381151

0 commit comments

Comments
 (0)