[BugFix] Fix partition mv with self joins refresh bug (backport #45876) #45936
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.
Why I'm doing:
What I'm doing:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check:
This is an automatic backport of pull request #45876 done by [Mergify](https://mergify.com). ## Why I'm doing: - If mv contains multiple times for the same table, result may be wrong because of wrong partition pruning. ``` CREATE TABLE `t1` ( `k1` int(11) NULL COMMENT "", `k2` decimal(38, 8) NULL COMMENT "", `k3` decimal(38, 8) NULL COMMENT "", `dt` DATE NULL COMMENT "" ) DUPLICATE KEY(`k1`) PARTITION BY RANGE (dt) ( START ("2023-12-31") END ("2025-01-01") EVERY (INTERVAL 1 DAY) ) DISTRIBUTED BY HASH(`k1`) BUCKETS 3;
CREATE MATERIALIZED VIEW test_mv1
PARTITION BY dt
DISTRIBUTED BY HASH(
k1
) BUCKETS 1PROPERTIES (
"replication_num" = "1",
"partition_refresh_number"="-1"
) REFRESH deferred MANUAL as
select k1,k3,dt from t1;
CREATE MATERIALIZED VIEW test_mv2
PARTITION BY dt
DISTRIBUTED BY HASH(
k1
) BUCKETS 1PROPERTIES (
"replication_num" = "1",
"partition_refresh_number"="-1"
) REFRESH MANUAL as
select t1.k1, t1.k3 t1k3, t4.k3 k4k3, t1.k3-t4.k3 as upyear, t1.dt dt
from t1 left outer join test_mv1 t4
on t1.k1=t4.k1 and t4.dt=substr(date_sub(t1.dt,interval dayofyear(t1.dt) day),1,10);