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] add tuning guides to query profile #53421

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public OptimizedRecord(OperatorTuningGuides operatorTuningGuides, List<TuningGui
public OperatorTuningGuides getOperatorTuningGuides() {
return operatorTuningGuides;
}

public String getExplainString() {
StringBuilder sb = new StringBuilder();
sb.append("Plan had been tuned by Plan Advisor.").append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public OperatorTuningGuides getOperatorTuningGuides(UUID queryId) {
}

public OperatorTuningGuides.OptimizedRecord getOptimizedRecord(UUID queryId) {
if (queryId == null) {
return null;
}
return optimizedQueryRecords.get(queryId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.starrocks.common.profile.Tracers;
import com.starrocks.qe.ConnectContext;
import com.starrocks.qe.SessionVariable;
import com.starrocks.qe.feedback.OperatorTuningGuides;
import com.starrocks.qe.feedback.PlanTuningAdvisor;
import com.starrocks.sql.Explain;
import com.starrocks.sql.ast.StatementBase;
import com.starrocks.sql.optimizer.base.ColumnRefFactory;
Expand Down Expand Up @@ -962,6 +964,12 @@ private OptExpression dynamicRewrite(ConnectContext connectContext, TaskContext
// if we can change the distribution to adjust the plan because of skew data, bad statistics or something else.
result = new MarkParentRequiredDistributionRule().rewrite(result, rootTaskContext);
result = new ApplyTuningGuideRule(connectContext).rewrite(result, rootTaskContext);

OperatorTuningGuides.OptimizedRecord optimizedRecord = PlanTuningAdvisor.getInstance()
.getOptimizedRecord(context.getQueryId());
if (optimizedRecord != null) {
Tracers.record(Tracers.Module.BASE, "DynamicTuningGuides", optimizedRecord.getExplainString());
}
return result;
}

Expand Down
6 changes: 5 additions & 1 deletion test/sql/test_feedback/R/test_feedback
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ function: assert_explain_contains("select count(*) from (select * from c1_skew t
-- result:
None
-- !result
function: assert_trace_values_contains("select count(*) from (select * from c1_skew t1 join (select * from c1_skew where c1 = 'f') t2 on t1.c2 = t2.c2) t", "RightChildEstimationErrorTuningGuide")
-- result:
None
-- !result
clear plan advisor;
-- result:
[REGEX]Clear all plan advisor in FE.*
-- !result
-- !result
2 changes: 2 additions & 0 deletions test/sql/test_feedback/T/test_feedback
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ set enable_global_runtime_filter = false;
function: assert_explain_not_contains("select count(*) from (select * from c1_skew t1 join (select * from c1_skew where c1 = 'f') t2 on t1.c2 = t2.c2) t", "RightChildEstimationErrorTuningGuide")
add into plan advisor select count(*) from (select * from c1_skew t1 join (select * from c1_skew where c1 = 'f') t2 on t1.c2 = t2.c2) t;
function: assert_explain_contains("select count(*) from (select * from c1_skew t1 join (select * from c1_skew where c1 = 'f') t2 on t1.c2 = t2.c2) t", "RightChildEstimationErrorTuningGuide")
function: assert_trace_values_contains("select count(*) from (select * from c1_skew t1 join (select * from c1_skew where c1 = 'f') t2 on t1.c2 = t2.c2) t", "RightChildEstimationErrorTuningGuide")

clear plan advisor;
Loading