Skip to content

Commit

Permalink
[Enhancement] add tuning guides to query profile
Browse files Browse the repository at this point in the history
Signed-off-by: stephen <[email protected]>
  • Loading branch information
stephen-shelby committed Dec 2, 2024
1 parent decea07 commit 5c73aea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
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 @@ -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;

0 comments on commit 5c73aea

Please sign in to comment.