Skip to content

Conversation

@seawinde
Copy link
Contributor

@seawinde seawinde commented Nov 4, 2025

picked from #57343

…r above scan (apache#57343)

### What problem does this PR solve?

Related PR: apache#36056 

Problem Summary:

if mv is defined as following

        CREATE MATERIALIZED VIEW mv_11
        BUILD IMMEDIATE REFRESH COMPLETE 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
            where o_custkey > 1
            group by
            o_orderstatus, o_orderdate, o_orderpriority;
 
there is filter `where o_custkey > 1` in mv, if query is as following,
should be rewritten successfully but fail, because the filter
`o_custkey > 1` is lost compare and could not compensate the filter, the
pr fixed this.

            select o_orderstatus, o_orderpriority,
            grouping_id(o_orderstatus, o_orderpriority),
            grouping_id(o_orderstatus),
            grouping(o_orderstatus),
            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
            where o_custkey > 1
            group by
            ROLLUP (o_orderstatus, o_orderpriority);
@seawinde seawinde requested a review from morrySnow as a code owner November 4, 2025 06:19
@Thearas
Copy link
Contributor

Thearas commented Nov 4, 2025

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@seawinde
Copy link
Contributor Author

seawinde commented Nov 4, 2025

run buildall

@seawinde
Copy link
Contributor Author

seawinde commented Nov 4, 2025

run buildall

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉
Increment coverage report
Complete coverage report

@morrySnow morrySnow changed the title [fix](mtmv) Fix mv rewrite fail when mv contains group sets and filter above scan (#57343) branch-3.1: [fix](mtmv) Fix mv rewrite fail when mv contains group sets and filter above scan #57343 Nov 6, 2025
@morrySnow morrySnow merged commit 346c813 into apache:branch-3.1 Nov 6, 2025
24 checks passed
@morrySnow morrySnow mentioned this pull request Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants