-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BugFix] Fix star count return null rather zero bug for mv rewrite (#…
…49288) Signed-off-by: shuming.li <[email protected]> (cherry picked from commit b5a9d75) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/transformation/materialization/AggregatedMaterializedViewRewriter.java # fe/fe-core/src/test/java/com/starrocks/sql/plan/ReplayWithMVFromDumpTest.java
- Loading branch information
1 parent
00fcaf4
commit 712806a
Showing
6 changed files
with
249 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
34 changes: 34 additions & 0 deletions
34
fe/fe-core/src/test/resources/sql/query_dump/materialized-view/count_star_rewrite.json
Large diffs are not rendered by default.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
test/sql/test_materialized_view_rewrite/R/test_mv_rewrite_with_count_star
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
-- name: test_mv_rewrite_with_count_star | ||
create database db_${uuid0}; | ||
-- result: | ||
-- !result | ||
use db_${uuid0}; | ||
-- result: | ||
-- !result | ||
CREATE TABLE `t1` ( | ||
`k1` date not null, | ||
`k2` datetime not null, | ||
`k3` char(20), | ||
`k4` varchar(20), | ||
`k5` boolean, | ||
`k6` tinyint, | ||
`k7` smallint, | ||
`k8` int, | ||
`k9` bigint, | ||
`k10` largeint, | ||
`k11` float, | ||
`k12` double, | ||
`k13` decimal(27,9) ) | ||
DUPLICATE KEY(`k1`, `k2`, `k3`, `k4`, `k5`) | ||
PARTITION BY RANGE(`k1`) | ||
( | ||
PARTITION p20201022 VALUES [("2020-10-22"), ("2020-10-23")), | ||
PARTITION p20201023 VALUES [("2020-10-23"), ("2020-10-24")), | ||
PARTITION p20201024 VALUES [("2020-10-24"), ("2020-10-25")) | ||
) | ||
DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 3 | ||
PROPERTIES ( | ||
"replication_num" = "1" | ||
) ; | ||
-- result: | ||
-- !result | ||
INSERT INTO t1 VALUES ('2020-10-22','2020-10-23 12:12:12','k3','k4',0,1,2,3,4,5,1.1,1.12,2.889); | ||
-- result: | ||
-- !result | ||
CREATE MATERIALIZED VIEW IF NOT EXISTS test_mv1 | ||
PARTITION BY `k1` | ||
DISTRIBUTED BY HASH(`k1`) | ||
REFRESH DEFERRED ASYNC | ||
as | ||
select k1, k2, sum(k6), sum(k7), sum(k8), count(1) as cnt from t1 group by k1, k2; | ||
-- result: | ||
-- !result | ||
CREATE MATERIALIZED VIEW IF NOT EXISTS test_mv2 | ||
PARTITION BY `k1` | ||
DISTRIBUTED BY HASH(`k1`) | ||
REFRESH DEFERRED ASYNC | ||
as | ||
select k1, k2, sum(cnt) as sum_cnt from test_mv1 group by k1, k2; | ||
-- result: | ||
-- !result | ||
refresh materialized view test_mv1 with sync mode; | ||
refresh materialized view test_mv2 with sync mode; | ||
function: print_hit_materialized_view("select count(*) from t1 where k1 = '2020-10-22';", "test_mv2") | ||
-- result: | ||
True | ||
-- !result | ||
function: print_hit_materialized_view("select count(*) from t1 where k1 = '2024-10-22';", "test_mv2") | ||
-- result: | ||
False | ||
-- !result | ||
function: print_hit_materialized_view("select count(*) from t1 where k2 = '2020-10-22';", "test_mv2") | ||
-- result: | ||
True | ||
-- !result | ||
function: print_hit_materialized_view("select count(*) from t1 where k2 = '2024-10-22';", "test_mv2") | ||
-- result: | ||
True | ||
-- !result | ||
select count(*) from t1 where k1 = '2020-10-22'; | ||
-- result: | ||
1 | ||
-- !result | ||
select count(*) from t1 where k1 = '2024-10-24'; | ||
-- result: | ||
0 | ||
-- !result | ||
select count(*) from t1 where k2 = '2020-10-22'; | ||
-- result: | ||
0 | ||
-- !result | ||
select count(*) from t1 where k2 = '2024-10-24'; | ||
-- result: | ||
0 | ||
-- !result | ||
drop materialized view test_mv1; | ||
-- result: | ||
-- !result | ||
drop materialized view test_mv2; | ||
-- result: | ||
-- !result | ||
drop table t1; | ||
-- result: | ||
-- !result |
59 changes: 59 additions & 0 deletions
59
test/sql/test_materialized_view_rewrite/T/test_mv_rewrite_with_count_star
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
-- name: test_mv_rewrite_with_count_star | ||
|
||
create database db_${uuid0}; | ||
use db_${uuid0}; | ||
CREATE TABLE `t1` ( | ||
`k1` date not null, | ||
`k2` datetime not null, | ||
`k3` char(20), | ||
`k4` varchar(20), | ||
`k5` boolean, | ||
`k6` tinyint, | ||
`k7` smallint, | ||
`k8` int, | ||
`k9` bigint, | ||
`k10` largeint, | ||
`k11` float, | ||
`k12` double, | ||
`k13` decimal(27,9) ) | ||
DUPLICATE KEY(`k1`, `k2`, `k3`, `k4`, `k5`) | ||
PARTITION BY RANGE(`k1`) | ||
( | ||
PARTITION p20201022 VALUES [("2020-10-22"), ("2020-10-23")), | ||
PARTITION p20201023 VALUES [("2020-10-23"), ("2020-10-24")), | ||
PARTITION p20201024 VALUES [("2020-10-24"), ("2020-10-25")) | ||
) | ||
DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 3 | ||
PROPERTIES ( | ||
"replication_num" = "1" | ||
) ; | ||
|
||
INSERT INTO t1 VALUES ('2020-10-22','2020-10-23 12:12:12','k3','k4',0,1,2,3,4,5,1.1,1.12,2.889); | ||
CREATE MATERIALIZED VIEW IF NOT EXISTS test_mv1 | ||
PARTITION BY `k1` | ||
DISTRIBUTED BY HASH(`k1`) | ||
REFRESH DEFERRED ASYNC | ||
as | ||
select k1, k2, sum(k6), sum(k7), sum(k8), count(1) as cnt from t1 group by k1, k2; | ||
|
||
CREATE MATERIALIZED VIEW IF NOT EXISTS test_mv2 | ||
PARTITION BY `k1` | ||
DISTRIBUTED BY HASH(`k1`) | ||
REFRESH DEFERRED ASYNC | ||
as | ||
select k1, k2, sum(cnt) as sum_cnt from test_mv1 group by k1, k2; | ||
|
||
refresh materialized view test_mv1 with sync mode; | ||
refresh materialized view test_mv2 with sync mode; | ||
function: print_hit_materialized_view("select count(*) from t1 where k1 = '2020-10-22';", "test_mv2") | ||
function: print_hit_materialized_view("select count(*) from t1 where k1 = '2024-10-22';", "test_mv2") | ||
function: print_hit_materialized_view("select count(*) from t1 where k2 = '2020-10-22';", "test_mv2") | ||
function: print_hit_materialized_view("select count(*) from t1 where k2 = '2024-10-22';", "test_mv2") | ||
select count(*) from t1 where k1 = '2020-10-22'; | ||
select count(*) from t1 where k1 = '2024-10-24'; | ||
select count(*) from t1 where k2 = '2020-10-22'; | ||
select count(*) from t1 where k2 = '2024-10-24'; | ||
|
||
drop materialized view test_mv1; | ||
drop materialized view test_mv2; | ||
drop table t1; |