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

[Enhancement] Support query dump for materialized view #26431

Merged
merged 2 commits into from
Jul 10, 2023

Conversation

LiShuMing
Copy link
Contributor

@LiShuMing LiShuMing commented Jul 3, 2023

To support query dump which query's table may contain mv, I did the changes:

  • Add "``" for output columns of Materialized View because mv's column may contain complex expressions (eg, bitmap_union();
  • Only add dump info into QueryDumpInfo only when it's from HTTP query dump or enable_query_dump is true;
  • When adding mv into dump info, optimize the mv again because tables in query may be only a part of mv, and mv may contain other unique/foreign constraints in its properties.
  • Make the tableMap in QueryDumpInfo ordered by the insert time because MV's replay needs the basic tables are created.
  • Mock some places to support MVs with external tables.

To support dump mv on mv queries, I added two invisible session variables:

  • query_excluding_mv_names indicates Query's candidate mvs should exculde.
  • query_including_mv_names indicates Query's candidate mvs should include.

I added three cases:

  • normal SR tables with MV;
    • normal SR tables with MV on MV;
  • external Hive Tables with MV;

What type of PR is this:

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

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr will affect users' behaviors
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function

Bugfix cherry-pick branch check:

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

@@ -243,7 +243,9 @@ public static void analyze(InsertStmt insertStmt, ConnectContext session) {
insertStmt.setTargetTable(table);
insertStmt.setTargetPartitionIds(targetPartitionIds);
insertStmt.setTargetColumns(targetColumns);
session.getDumpInfo().addTable(database.getFullName(), table);
if (session.getDumpInfo() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why check this?
why not check this before ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before queries always put the related tables/views/... into DumpInfo.

I've changed this to only save related infos when it's from HTTP query dump or enable_query_dump is true. I think this is more reasonable.

liuyehcf
liuyehcf previously approved these changes Jul 5, 2023
Signed-off-by: Kevin Li <[email protected]>
@sonarcloud
Copy link

sonarcloud bot commented Jul 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

0.0% 0.0% Coverage
0.8% 0.8% Duplication

@wanpengfei-git
Copy link
Collaborator

[FE PR Coverage Check]

😍 pass : 107 / 127 (84.25%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/connector/hudi/HudiMetadata.java 0 4 00.00% [173, 174, 175, 176]
🔵 com/starrocks/http/rest/QueryDumpAction.java 0 1 00.00% [92]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/MvUtils.java 0 1 00.00% [329]
🔵 com/starrocks/http/HttpServerHandler.java 0 2 00.00% [119, 120]
🔵 com/starrocks/qe/StmtExecutor.java 3 8 37.50% [404, 405, 407, 409, 696]
🔵 com/starrocks/qe/ConnectContext.java 3 7 42.86% [249, 553, 554, 557]
🔵 com/starrocks/qe/SessionVariable.java 6 8 75.00% [2079, 2080]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/MaterializedViewRewriter.java 5 6 83.33% [680]
🔵 com/starrocks/catalog/MaterializedView.java 3 3 100.00% []
🔵 com/starrocks/sql/optimizer/MvRewritePreprocessor.java 23 23 100.00% []
🔵 com/starrocks/connector/hive/HiveMetadata.java 7 7 100.00% []
🔵 com/starrocks/sql/analyzer/InsertAnalyzer.java 2 2 100.00% []
🔵 com/starrocks/sql/optimizer/rewrite/OptExternalPartitionPruner.java 4 4 100.00% []
🔵 com/starrocks/server/CatalogMgr.java 6 6 100.00% []
🔵 com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java 2 2 100.00% []
🔵 com/starrocks/sql/analyzer/QueryAnalyzer.java 17 17 100.00% []
🔵 com/starrocks/sql/optimizer/statistics/StatisticsCalcUtils.java 3 3 100.00% []
🔵 com/starrocks/sql/optimizer/dump/QueryDumpInfo.java 20 20 100.00% []
🔵 com/starrocks/server/GlobalStateMgr.java 1 1 100.00% []
🔵 com/starrocks/sql/optimizer/MaterializedViewOptimizer.java 1 1 100.00% []
🔵 com/starrocks/sql/analyzer/MaterializedViewAnalyzer.java 1 1 100.00% []

@murphyatwork murphyatwork enabled auto-merge (squash) July 10, 2023 02:25
@murphyatwork murphyatwork merged commit 4f6a915 into StarRocks:main Jul 10, 2023
25 of 26 checks passed
@wanpengfei-git
Copy link
Collaborator

@Mergifyio backport branch-3.1

@github-actions github-actions bot removed the 3.1 label Jul 10, 2023
@mergify
Copy link
Contributor

mergify bot commented Jul 10, 2023

backport branch-3.1

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jul 10, 2023
To support query dump which query's table may contain mv, I did the
changes:
- Add "``" for output columns of Materialized View because mv's column
may contain complex expressions (eg, `bitmap_union()`;
- Only add dump info into QueryDumpInfo only when it's from HTTP query
dump or `enable_query_dump` is true;
- When adding mv into dump info, optimize the mv again because tables in
query may be only a part of mv, and mv may contain other unique/foreign
constraints in its properties.
- Make the `tableMap ` in QueryDumpInfo ordered by the insert time
because MV's replay needs the basic tables are created.
- Mock some places to support MVs with external tables.

To support dump mv on mv queries, I added two invisible session
variables:
- query_excluding_mv_names indicates Query's candidate mvs should
exculde.
- query_including_mv_names indicates Query's candidate mvs should
include.

(cherry picked from commit 4f6a915)

# Conflicts:
#	fe/fe-core/src/test/java/com/starrocks/analysis/ShowCreateViewStmtTest.java
silverbullet233 pushed a commit to silverbullet233/starrocks that referenced this pull request Jul 11, 2023
To support query dump which query's table may contain mv, I did the
changes:
- Add "``" for output columns of Materialized View because mv's column
may contain complex expressions (eg, `bitmap_union()`;
- Only add dump info into QueryDumpInfo only when it's from HTTP query
dump or `enable_query_dump` is true;
- When adding mv into dump info, optimize the mv again because tables in
query may be only a part of mv, and mv may contain other unique/foreign
constraints in its properties.
- Make the `tableMap ` in QueryDumpInfo ordered by the insert time
because MV's replay needs the basic tables are created.
- Mock some places to support MVs with external tables.

To support dump mv on mv queries, I added two invisible session
variables:
- query_excluding_mv_names indicates Query's candidate mvs should
exculde.
- query_including_mv_names indicates Query's candidate mvs should
include.

Signed-off-by: silverbullet233 <[email protected]>
LiShuMing added a commit to LiShuMing/starrocks that referenced this pull request Jul 13, 2023
To support query dump which query's table may contain mv, I did the
changes:
- Add "``" for output columns of Materialized View because mv's column
may contain complex expressions (eg, `bitmap_union()`;
- Only add dump info into QueryDumpInfo only when it's from HTTP query
dump or `enable_query_dump` is true;
- When adding mv into dump info, optimize the mv again because tables in
query may be only a part of mv, and mv may contain other unique/foreign
constraints in its properties.
- Make the `tableMap ` in QueryDumpInfo ordered by the insert time
because MV's replay needs the basic tables are created.
- Mock some places to support MVs with external tables.

To support dump mv on mv queries, I added two invisible session
variables:
- query_excluding_mv_names indicates Query's candidate mvs should
exculde.
- query_including_mv_names indicates Query's candidate mvs should
include.
LiShuMing added a commit to LiShuMing/starrocks that referenced this pull request Jul 13, 2023
To support query dump which query's table may contain mv, I did the
changes:
- Add "``" for output columns of Materialized View because mv's column
may contain complex expressions (eg, `bitmap_union()`;
- Only add dump info into QueryDumpInfo only when it's from HTTP query
dump or `enable_query_dump` is true;
- When adding mv into dump info, optimize the mv again because tables in
query may be only a part of mv, and mv may contain other unique/foreign
constraints in its properties.
- Make the `tableMap ` in QueryDumpInfo ordered by the insert time
because MV's replay needs the basic tables are created.
- Mock some places to support MVs with external tables.

To support dump mv on mv queries, I added two invisible session
variables:
- query_excluding_mv_names indicates Query's candidate mvs should
exculde.
- query_including_mv_names indicates Query's candidate mvs should
include.

Signed-off-by: Kevin Li <[email protected]>
murphyatwork pushed a commit that referenced this pull request Jul 14, 2023
…) (#27154)

To support dump mv on mv queries, I added two invisible session
variables:
- query_excluding_mv_names indicates Query's candidate mvs should
exculde.
- query_including_mv_names indicates Query's candidate mvs should
include.
LiShuMing added a commit to LiShuMing/starrocks that referenced this pull request Jul 25, 2023
…Rocks#26431) (StarRocks#27154)

To support dump mv on mv queries, I added two invisible session
variables:
- query_excluding_mv_names indicates Query's candidate mvs should
exculde.
- query_including_mv_names indicates Query's candidate mvs should
include.

Signed-off-by: Kevin Li <[email protected]>
LiShuMing added a commit to LiShuMing/starrocks that referenced this pull request Jul 25, 2023
…Rocks#26431) (StarRocks#27154)

To support dump mv on mv queries, I added two invisible session
variables:
- query_excluding_mv_names indicates Query's candidate mvs should
exculde.
- query_including_mv_names indicates Query's candidate mvs should
include.

Signed-off-by: Kevin Li <[email protected]>
LiShuMing added a commit to LiShuMing/starrocks that referenced this pull request Jul 25, 2023
…Rocks#26431) (StarRocks#27154)

To support dump mv on mv queries, I added two invisible session
variables:
- query_excluding_mv_names indicates Query's candidate mvs should
exculde.
- query_including_mv_names indicates Query's candidate mvs should
include.

Signed-off-by: Kevin Li <[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.

4 participants