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

   ## Proposed changes
   
   Support to query rewrite by materialized view when join input has aggregate, 
the aggregate should be simple
   For example as following:
   The materialized view def is 
   >            select
   >            l_linenumber,
   >            count(distinct l_orderkey),
   >           sum(case when l_orderkey in (1,2,3) then l_suppkey * 
l_linenumber else 0 end),
   >            max(case when l_orderkey in (4, 5) then (l_quantity *2 + 
part_supp_a.qty_max) * 0.88 else 100 end),
   >            avg(case when l_partkey in (2, 3, 4) then l_discount + 
o_totalprice + part_supp_a.qty_sum else 50 end)
   >            from lineitem
   >            left join orders on l_orderkey = o_orderkey
   >            left join 
    >           (select ps_partkey, ps_suppkey, sum(ps_availqty) qty_sum, 
max(ps_availqty) qty_max,
    >               min(ps_availqty) qty_min,
    >               avg(ps_supplycost) cost_avg
    >               from partsupp
    >               group by ps_partkey,ps_suppkey) part_supp_a
    >           on l_partkey = part_supp_a.ps_partkey
    >           and l_suppkey = part_supp_a.ps_suppkey
    >           group by l_linenumber;
   
   when query is like following, it can be rewritten by mv above
   >                        select
   >            l_linenumber,
   >            sum(case when l_orderkey in (1,2,3) then l_suppkey * 
l_linenumber else 0 end),
   >            avg(case when l_partkey in (2, 3, 4) then l_discount + 
o_totalprice + part_supp_a.qty_sum else 50 end)
   >            from lineitem
   >            left join orders on l_orderkey = o_orderkey
   >            left join 
   >            (select ps_partkey, ps_suppkey, sum(ps_availqty) qty_sum, 
max(ps_availqty) qty_max,
   >                min(ps_availqty) qty_min,
   >                avg(ps_supplycost) cost_avg
   >                from partsupp
   >                group by ps_partkey,ps_suppkey) part_supp_a
   >            on l_partkey = part_supp_a.ps_partkey
   >            and l_suppkey = part_supp_a.ps_suppkey
   >            group by l_linenumber;
   
   
   ## 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