[fix](nereids) Fix query rewrite by mv fail when self join#29227
[fix](nereids) Fix query rewrite by mv fail when self join#29227morrySnow merged 4 commits intoapache:masterfrom
Conversation
|
run buildall |
| } | ||
| Set<Long> sourceTableKeySet = sourceTableRelationIdMap.keySet(); | ||
| List<List<Pair<MappedRelation, MappedRelation>>> mappedRelations = new ArrayList<>(); | ||
| List<List<RelationMapping>> mappedRelations = new ArrayList<>(); |
There was a problem hiding this comment.
May be in the future, you can refactor code by using ImmutableEquivalenceSet here
There was a problem hiding this comment.
i think we should do it right now
There was a problem hiding this comment.
I try to use ImmutableEquivalenceSet, i found that ImmutableEquivalenceSet may be not suit the scene
such as I want to make a relation mapping as
RelationId#1 -> RelationId#2 which should keep the directivity。
after call ImmutableEquivalenceSet.addEqualPair then tryToMap,i found get the result
is
RelationId#2 -> RelationId#1
There was a problem hiding this comment.
I have discard Pair<MappedRelation, MappedRelation> and RelationMapping . And use HashBiMap instead directly. WDYT?
|
PR approved by anyone and no changes requested. |
|
run buildall |
|
(From new machine)TeamCity pipeline, clickbench performance test result: |
|
TPC-H test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G' |
|
run buildall |
|
TPC-H test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G' |
|
(From new machine)TeamCity pipeline, clickbench performance test result: |
|
PR approved by at least one committer and no changes requested. |
) Fix query rewrite by mv fail when self join, after fix query like following can be rewrited def materialized view = """ select a.o_orderkey, count(distinct a.o_orderstatus) num1, SUM(CASE WHEN a.o_orderstatus = 'o' AND a.o_shippriority = 1 AND a.o_orderdate = '2023-12-08' AND b.o_orderdate = '2023-12-09' THEN a.o_shippriority+b.o_custkey ELSE 0 END) num2, SUM(CASE WHEN a.o_orderstatus = 'o' AND a.o_shippriority = 1 AND a.o_orderdate >= '2023-12-01' AND a.o_orderdate <= '2023-12-09' THEN a.o_shippriority+b.o_custkey ELSE 0 END) num3, SUM(CASE WHEN a.o_orderstatus = 'o' AND a.o_shippriority in (1,2) AND a.o_orderdate >= '2023-12-08' AND b.o_orderdate <= '2023-12-09' THEN a.o_shippriority-b.o_custkey ELSE 0 END) num4, AVG(a.o_totalprice) num5, MAX(b.o_totalprice) num6, MIN(a.o_totalprice) num7 from orders a left outer join orders b on a.o_orderkey = b.o_orderkey and a.o_custkey = b.o_custkey group by a.o_orderkey; """ def query = """ select a.o_orderkey, SUM(CASE WHEN a.o_orderstatus = 'o' AND a.o_shippriority = 1 AND a.o_orderdate = '2023-12-08' AND b.o_orderdate = '2023-12-09' THEN a.o_shippriority+b.o_custkey ELSE 0 END) num2, SUM(CASE WHEN a.o_orderstatus = 'o' AND a.o_shippriority = 1 AND a.o_orderdate >= '2023-12-01' AND a.o_orderdate <= '2023-12-09' THEN a.o_shippriority+b.o_custkey ELSE 0 END) num3, SUM(CASE WHEN a.o_orderstatus = 'o' AND a.o_shippriority in (1,2) AND a.o_orderdate >= '2023-12-08' AND b.o_orderdate <= '2023-12-09' THEN a.o_shippriority-b.o_custkey ELSE 0 END) num4, AVG(a.o_totalprice) num5, MAX(b.o_totalprice) num6, MIN(a.o_totalprice) num7 from orders a left outer join orders b on a.o_orderkey = b.o_orderkey and a.o_custkey = b.o_custkey group by a.o_orderkey; """
Proposed changes
Fix query rewrite by mv fail when self join, after fix query like following can be rewrited
Further comments
If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...