seawinde opened a new pull request, #35976: URL: https://github.com/apache/doris/pull/35976
## Proposed changes this depends on https://github.com/apache/doris/pull/35897 Support grouping_sets, cube, rollup query rewrite by materialized view, if mv group by fields contains all the group by fields in query. For example as following: **mv def** >CREATE MATERIALIZED VIEW mv_1 BUILD IMMEDIATE REFRESH AUTO ON MANUAL DISTRIBUTED BY RANDOM BUCKETS >2 PROPERTIES ('replication_num' = '1') AS >select > o_orderstatus, > o_orderdate, > o_orderpriority, > sum(o_totalprice) as sum_total, > max(o_totalprice) as max_total, > min(o_totalprice) as min_total, > count(*) as count_all, > bitmap_union( > to_bitmap( > case when o_shippriority > 1 > and o_orderkey IN (1, 3) then o_custkey else null end > ) > ) as bitmap_union_basic >from > orders >group by > o_orderstatus, > o_orderdate, > o_orderpriority; the query following can rewrite successfully by mv above > select o_orderstatus, o_orderdate, o_orderpriority, > grouping_id(o_orderstatus, o_orderdate, o_orderpriority), > grouping_id(o_orderstatus, o_orderdate), > grouping(o_orderdate), > sum(o_totalprice), > max(o_totalprice), > min(o_totalprice), > count(*), > count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end) > from orders > group by > GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderpriority), (o_orderstatus), ()); if query group by fields is sub of mv group by fields, and the query aggregate function extends `RollupTrait` it can also rewrites successfully, for example query as following. this is applicable for `CUBE`, `ROLLUP` > select o_orderstatus, o_orderdate, > grouping_id(o_orderstatus, o_orderdate), > grouping(o_orderdate), > sum(o_totalprice), > max(o_totalprice), > min(o_totalprice), > count(*), > count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end) > from orders > group by > GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderdate),()); -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org