starrocks icon indicating copy to clipboard operation
starrocks copied to clipboard

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

Open kaijianding opened this issue 1 year ago • 2 comments

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:

  • [ ] BugFix
  • [ ] Feature
  • [x] Enhancement
  • [ ] Refactor
  • [ ] UT
  • [ ] Doc
  • [ ] Tool

Does this PR entail a change in behavior?

  • [ ] Yes, this PR will result in a change in behavior.
  • [x] No, this PR will not result in a change in behavior.

Checklist:

  • [x] I have added test cases for my bug fix or my new feature
  • [ ] This pr needs user documentation (for new or modified features or behaviors)
    • [ ] I have added documentation for my new feature or new function
  • [ ] This is a backport pr

Bugfix cherry-pick branch check:

  • [x] I have checked the version labels which the pr will be auto-backported to the target branch
    • [x] 3.3
    • [ ] 3.2
    • [ ] 3.1
    • [ ] 3.0
    • [ ] 2.5

kaijianding avatar Jun 28 '24 11:06 kaijianding

[FE Incremental Coverage Report]

:white_check_mark: pass : 21 / 22 (95.45%)

file detail

path covered_line new_line coverage not_covered_line_detail
:large_blue_circle: com/starrocks/sql/optimizer/rule/transformation/materialization/EquationRewriter.java 8 9 88.89% [82]
:large_blue_circle: com/starrocks/sql/optimizer/rule/transformation/materialization/AggregateFunctionRollupUtils.java 9 9 100.00% []
:large_blue_circle: com/starrocks/sql/optimizer/rule/transformation/materialization/AggregatedMaterializedViewRewriter.java 4 4 100.00% []

github-actions[bot] avatar Jul 02 '24 13:07 github-actions[bot]

[BE Incremental Coverage Report]

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

github-actions[bot] avatar Jul 02 '24 13:07 github-actions[bot]

@Mergifyio backport branch-3.3

github-actions[bot] avatar Jul 05 '24 08:07 github-actions[bot]

backport branch-3.3

✅ Backports have been created

mergify[bot] avatar Jul 05 '24 09:07 mergify[bot]