StarRocks / starrocks

StarRocks, a Linux Foundation project, is a next-generation sub-second MPP OLAP database for full analytics scenarios, including multi-dimensional analytics, real-time analytics, and ad-hoc queries.
https://starrocks.io
Apache License 2.0
8.26k stars 1.67k forks source link

[Enhancement] Support mv rewrite when select only with mv's group by key #47648

Open kaijianding opened 3 days ago

kaijianding commented 3 days ago

Why I'm doing:

CREATE TABLE `test_pt` (
  `id` int(11) NULL COMMENT "id",
  `pt` date NOT NULL COMMENT "",
  `gmv` int(11) NULL COMMENT "gmv"
) ENGINE=OLAP
DUPLICATE KEY(`id`)
COMMENT "OLAP"
PARTITION BY date_trunc('day', pt)
DISTRIBUTED BY HASH(`pt`)
PROPERTIES (
"replication_num" = "1"
);

insert into test_pt values(1,'2024-06-28', 10);

CREATE MATERIALIZED VIEW `test_pt_mv` 
PARTITION BY (`pt`)
DISTRIBUTED BY RANDOM
REFRESH ASYNC START("2024-03-08 03:00:00") EVERY(INTERVAL 1 MINUTE)
PROPERTIES (
"replication_num" = "1"
)
AS SELECT pt, id, sum(gmv) AS sum_gmv
FROM test_pt
GROUP BY pt,id;

explain select pt,max(id),sum(gmv) from test_pt group by pt;

select pt,max(id),sum(gmv) from test_pt group by pt should be rewritten by test_pt_mv

What I'm doing:

What type of PR is this:

Does this PR entail a change in behavior?

Checklist:

Bugfix cherry-pick branch check:

sonarcloud[bot] commented 2 hours ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

github-actions[bot] commented 2 hours ago

[BE Incremental Coverage Report]

:white_check_mark: pass : 0 / 0 (0%)