seawinde opened a new pull request, #29227:
URL: https://github.com/apache/doris/pull/29227

   ## Proposed changes
   
   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;
       """
   
   ```
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at 
[[email protected]](mailto:[email protected]) by explaining why you 
chose the solution you did and what alternatives you considered, etc...
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to