gpdb
gpdb copied to clipboard
Correct locus type for subquery
trafficstars
=====================================================================
When the subplan's locusType is CdbLocusType_HashedOJ, cdbpathlocus_from_subquery
will create an incorrect locus with locusType of CdbLocusType_Hashed. This will
cause distributed motion node not to be added on top of the subquery node during
insert operation, resulting in incorrect data distribution.
This issue doesn't occur on the main branch, but there's no separate commit in
the main branch that fixes this issue, so I fixed the issue on 6X_STABLE with
this commit.
Setup:
======
```
CREATE OR REPLACE FUNCTION nvl(p1 in text, p2 in text) RETURNS text AS $$
DECLARE
BEGIN
return COALESCE(p1, p2);
END;
$$ LANGUAGE plpgsql;
create table t1(a varchar(2), b varchar(2)) distributed by (a);
create table t2(a varchar(2), b varchar(2)) distributed by (a);
create table tr(a varchar(2), b varchar(2)) distributed by (a);
```
Current Behaviour:
==================
```
explain (costs off) insert into tr select t1.a, nvl(t1.b, '') from t1 full join t2 on t1.a = t2.a;
QUERY PLAN
--------------------------------------------------------
Insert on tr
-> Subquery Scan on "*SELECT*"
-> Hash Full Join
Hash Cond: ((t1.a)::text = (t2.a)::text)
-> Seq Scan on t1
-> Hash
-> Seq Scan on t2
Optimizer: Postgres query optimizer
(8 rows)
After Fix:
==========
```
explain (costs off) insert into tr select t1.a, nvl(t1.b, '') from t1 full join t2 on t1.a = t2.a;
QUERY PLAN
--------------------------------------------------------------
Insert on tr
-> Redistribute Motion 3:3 (slice1; segments: 3)
Hash Key: "*SELECT*".a
-> Subquery Scan on "*SELECT*"
-> Hash Full Join
Hash Cond: ((t1.a)::text = (t2.a)::text)
-> Seq Scan on t1
-> Hash
-> Seq Scan on t2
Optimizer: Postgres query optimizer (10 rows)
## Here are some reminders before you submit the pull request
- [ ] Add tests for the change
- [ ] Document changes
- [ ] Communicate in the mailing list if needed
- [ ] Pass `make installcheck`
- [ ] Review a PR in return to support the community