Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] (MV For TimeSeries Scene: Part 3) Add AggregateTimeSeriesRule rule to support time series split in mv rewrite #51713

Merged
merged 6 commits into from
Oct 18, 2024

Conversation

LiShuMing
Copy link
Contributor

@LiShuMing LiShuMing commented Oct 10, 2024

Why I'm doing:

how can we use MV to speed up query's performance by using hourly/daily/monthly mvs?

CREATE TABLE t0(
 ts datetime,
 v1 INT,
 v2 INT)
 DUPLICATE KEY(ts)
 PARTITION BY RANGE(ts)
 (
   PARTITION p1 VALUES LESS THAN ('2024-01-01'),
   PARTITION p2 VALUES LESS THAN ('2024-01-02'),
   PARTITION p3 VALUES LESS THAN ('2024-01-03'),
   PARTITION p4 VALUES LESS THAN ('2024-02-03'),
   PARTITION p5 VALUES LESS THAN ('2024-03-03')
)
DISTRIBUTED BY HASH(k1);

create MATERIALIZED VIEW test_hourly_mv
PARTITION BY (dt)
DISTRIBUTED BY RANDOM
PROPERTIES (
"replication_num" = "1"
) as select date_trunc('hour', ts) as dt, sum(v1) as sum_v1, sum(v2) as sum_v2
from t0 group by date_trunc('hour', k1);

create MATERIALIZED VIEW test_daily_mv
PARTITION BY (dt)
DISTRIBUTED BY RANDOM
PROPERTIES (
"replication_num" = "1"
) as select date_trunc('day', dt) as dt, sum(sum_v1) as sum_v1, sum(sum_v2) as sum_v2
from t0 group by date_trunc('day', dt);

create MATERIALIZED VIEW test_monthly_mv
PARTITION BY (dt)
DISTRIBUTED BY RANDOM
PROPERTIES (
"replication_num" = "1"
) as select date_trunc('month', dt) as dt, sum(sum_v1) as sum_v1, sum(sum_v2) as sum_v2
from t0 group by date_trunc('month', dt);

-- query
SELECT SUM(v1) FROM t0
WHERE dt BETWEEN '2024-08-01 01:00' AND '2024-10-25 01:00';

What I'm doing:

  • Add AggregateTimeSeriesRule rule to support time series split in mv rewrite
  • Add enable_materialized_view_timeseries_agg_pushdown_rewrite(default true) to control it;

Fixes #51446

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

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

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • 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:

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

@LiShuMing LiShuMing requested a review from a team as a code owner October 10, 2024 08:59
@LiShuMing LiShuMing requested a review from a team as a code owner October 14, 2024 06:03
@LiShuMing LiShuMing force-pushed the fix/main/fix_time_series_rollup.v1 branch from 511ec41 to a71acc1 Compare October 14, 2024 06:13
Signed-off-by: shuming.li <[email protected]>
Signed-off-by: shuming.li <[email protected]>
Signed-off-by: shuming.li <[email protected]>
Signed-off-by: shuming.li <[email protected]>
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 423 / 503 (84.10%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/equivalent/CountRewriteEquivalent.java 1 2 50.00% [86]
🔵 com/starrocks/qe/SessionVariable.java 2 4 50.00% [3678, 3679]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/equivalent/DateTruncEquivalent.java 1 2 50.00% [62]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/common/AggregatePushDownUtils.java 12 16 75.00% [253, 254, 257, 258]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/AggregatedTimeSeriesRewriter.java 304 370 82.16% [120, 128, 134, 138, 142, 149, 154, 159, 161, 162, 168, 174, 178, 189, 190, 200, 206, 216, 263, 272, 293, 294, 318, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 351, 374, 375, 376, 388, 463, 464, 513, 585, 590, 603, 609, 620, 644, 648, 660, 673, 674, 676, 677, 679, 680, 685, 686, 688, 689, 691, 692, 694, 695, 697]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/AndRangePredicate.java 5 6 83.33% [60]
🔵 com/starrocks/catalog/MaterializedView.java 29 32 90.62% [1798, 1820, 1823]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/equivalent/RewriteEquivalent.java 9 10 90.00% [69]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/rule/AggregateTimeSeriesRule.java 11 12 91.67% [45]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/PredicateExtractor.java 3 3 100.00% []
🔵 com/starrocks/sql/optimizer/rule/RuleSet.java 1 1 100.00% []
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/ColumnRangePredicate.java 16 16 100.00% []
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/common/AggregateFunctionRollupUtils.java 18 18 100.00% []
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/AggregateFunctionRewriter.java 1 1 100.00% []
🔵 com/starrocks/sql/optimizer/rule/RuleType.java 1 1 100.00% []
🔵 com/starrocks/sql/optimizer/property/ReplaceShuttle.java 5 5 100.00% []
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/AggregatedMaterializedViewPushDownRewriter.java 1 1 100.00% []
🔵 com/starrocks/sql/optimizer/rule/tree/pdagg/AggregatePushDownContext.java 3 3 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@Seaven Seaven enabled auto-merge (squash) October 18, 2024 06:23
@Seaven Seaven merged commit 2b3d80a into StarRocks:main Oct 18, 2024
55 of 56 checks passed
ZiheLiu pushed a commit to ZiheLiu/starrocks that referenced this pull request Oct 31, 2024
…le rule to support time series split in mv rewrite (StarRocks#51713)

Signed-off-by: shuming.li <[email protected]>
renzhimin7 pushed a commit to renzhimin7/starrocks that referenced this pull request Nov 7, 2024
…le rule to support time series split in mv rewrite (StarRocks#51713)

Signed-off-by: shuming.li <[email protected]>
Signed-off-by: zhiminr.ren <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance materialized view rewrite in TimeSeries Scene
4 participants