Skip to content

Conversation

@zddr
Copy link
Contributor

@zddr zddr commented Nov 19, 2025

zddr and others added 5 commits November 19, 2025 11:03
### What problem does this PR solve?

Currently, a materialized view can only have one PCT table. If the
reference table has multiple partitioned tables and changes occur in
non-PCT tables, even if only some partitions are modified, the
materialized view must be fully refreshed, which is costly.
Therefore, support for multiple PCT tables is needed, but with the
following restrictions:
- Only inner joins and unions (including UNION ALL) are supported.
- In the case of unions, all base tables must be PCT tables; otherwise,
the derivation fails.
- The partition granularity across multiple PCT tables must align.
  For example:
  The following scenario is allowed:
t1 has 2 partitions: [2020-01-01, 2020-01-02), [2020-01-02, 2020-01-03)
t2 has 2 partitions: [2020-01-02, 2020-01-03), [2020-01-03, 2020-01-04)

  The following scenario is not allowed:
t1 has 2 partitions: [2020-01-01, 2020-01-03), [2020-01-03, 2020-01-05)
t2 has 2 partitions: [2020-01-01, 2020-01-02), [2020-01-02, 2020-01-03)

However, if the materialized view uses monthly partition roll-up, the
above scenario is allowed,
because the materialized view only needs to generate one partition:
[2020-01-01, 2020-02-01).

---------

Co-authored-by: seawinde <daydayup005@yeah.net>
Co-authored-by: seawinde <wusi@selectdb.com>
# Conflicts:
#	fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java
#	fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRewriteUtil.java
#	fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java
#	fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVRewriteUtilTest.java
…he#57759)

- Restricting the use of external views to create MTMV
- add case
- fix display of mv_infos
…ew (apache#57958)

### What problem does this PR solve?

Related PR: apache#56423 apache#56958

Problem Summary:

1. Fix partition trace fail when create partition mv with view and
date_trunc
2. Fix err if use data_trunc('day', col) partition column when create
partition materialized view

the mv def sql would be success after this fix

CREATE VIEW lineitem_daily_summary_view AS
SELECT 
    DATE_TRUNC('day', L_SHIPDATE) AS ship_date,
    L_RETURNFLAG,
    L_LINESTATUS,
    COUNT(*) AS order_count,
    SUM(L_QUANTITY) AS total_quantity,
    SUM(L_EXTENDEDPRICE) AS total_price,
    AVG(L_DISCOUNT) AS avg_discount
FROM lineitem
WHERE L_SHIPDATE IS NOT NULL
GROUP BY ship_date, L_RETURNFLAG, L_LINESTATUS;

mv def is as following

SELECT
    ship_date,
    L_RETURNFLAG,
    SUM(order_count) AS total_orders,
    SUM(total_quantity) AS sum_quantity,
    SUM(total_price) AS sum_price,
    AVG(avg_discount) AS average_discount
FROM lineitem_daily_summary_view
GROUP BY ship_date, L_RETURNFLAG
ORDER BY ship_date, L_RETURNFLAG, total_orders, sum_quantity, sum_price;
@zddr zddr requested a review from yiguolei as a code owner November 19, 2025 03:10
@hello-stephen
Copy link
Contributor

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?

@zddr
Copy link
Contributor Author

zddr commented Nov 19, 2025

run buildall

@zddr
Copy link
Contributor Author

zddr commented Nov 19, 2025

run buildall

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 59.95% (675/1126) 🎉
Increment coverage report
Complete coverage report

@zddr
Copy link
Contributor Author

zddr commented Nov 19, 2025

run p0

Copy link
Contributor

@seawinde seawinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zddr
Copy link
Contributor Author

zddr commented Nov 20, 2025

run buildall

@zddr
Copy link
Contributor Author

zddr commented Nov 20, 2025

run buildall

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 59.95% (675/1126) 🎉
Increment coverage report
Complete coverage report

@yiguolei yiguolei merged commit 1d63c19 into apache:branch-4.0 Nov 20, 2025
23 of 24 checks passed
@yiguolei yiguolei mentioned this pull request Dec 2, 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