seawinde opened a new pull request, #56266:
URL: https://github.com/apache/doris/pull/56266
### What problem does this PR solve?
Support materialized view query rewriting by join eliminate when mv use more
table than query
Such as mv def is as following
```sql
CREATE MATERIALIZED VIEW mv_test
BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES ('replication_num' = '1')
AS
select l_shipdate, l_linenumber, l_partkey, l_orderkey, o_orderkey,
o_partkey, o_suppkey, o_custkey, ps_partkey, ps_suppkey, ps_availqty,
ps_supplycost from lineitem_1
left join orders_1
on o_orderkey = l_orderkey
left join partsupp_1
on ps_partkey = l_partkey and ps_suppkey = l_suppkey
```
if query is as following, it can be rewritten successfully by mv above
though query has less tables than materialized view `mv_test`.
```sql
select l_shipdate, l_linenumber, l_partkey, l_orderkey
from lineitem_1
left join partsupp_1
on ps_partkey = l_partkey and ps_suppkey = l_suppkey
```
Because the materialized view `mv_testis` built on base tables that have
specific primary key and foreign key constraints, the `orders_1` table can be
eliminated (through join elimination) without causing incorrect query results.
Therefore, the aforementioned query can be transparently rewritten using
`mv_test`. This mechanism and rule for join elimination are consistent with the
principles of ELIMINATE_JOIN_BY_FK(Eliminate Join by Foreign Key) and
ELIMINATE_JOIN_BY_UK(Eliminate Join by Unique Key)
```sql
alter table orders_1 add constraint pk primary key(o_orderkey)
alter table lineitem_1 add constraint fk foreign key (l_orderkey) references
orders_1(o_orderkey)
```
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [x] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR should
merge into -->
--
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]