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 b453ce0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
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
10 changes: 7 additions & 3 deletions test/sql/test_feedback/R/test_feedback
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ None
-- !result
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;
-- result:
[REGEX]Add query into plan advisor in FE.*
Add query into plan advisor in FE(172.17.0.1_9011_1728457174963) successfully.
-- !result
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")
-- 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
Clear all plan advisor in FE(172.17.0.1_9011_1728457174963) successfully. Advisor size: 1
-- !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 b453ce0

Please sign in to comment.