Skip to content

Commit

Permalink
[Enhancement] add tuning guides to query profile (backport #53421) (#…
Browse files Browse the repository at this point in the history
…53438)

Co-authored-by: stephen <[email protected]>
  • Loading branch information
mergify[bot] and stephen-shelby authored Dec 3, 2024
1 parent 938920a commit 2b52998
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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 @@ -965,6 +967,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;

0 comments on commit 2b52998

Please sign in to comment.