[feat](mtmv) Support grouping_sets rewrite when query rewrite by materialized view (#36056)#37436
Merged
morrySnow merged 1 commit intoapache:branch-2.1from Jul 8, 2024
Conversation
…rialized view (apache#36056) 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: 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),());
|
Thank you for your contribution to Apache Doris. Since 2024-03-18, the Document has been moved to doris-website. |
Contributor
Author
|
run buildall |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
cherry pick to 2.1
pr: #36056
commitId: 569c977