fix optimizer trace bug and fix format sql plan bug

This commit is contained in:
zzg19950727
2023-02-07 11:37:22 +08:00
committed by ob-robot
parent 4f31f2a715
commit 9bbe05b4b4
5 changed files with 92 additions and 29 deletions

View File

@ -140,6 +140,40 @@ int ObSqlPlan::store_sql_plan_for_explain(ObLogPlan* plan,
return ret;
}
int ObSqlPlan::print_sql_plan(ObLogPlan* plan,
ExplainType type,
const ObExplainDisplayOpt& option,
ObIArray<common::ObString> &plan_strs)
{
int ret = OB_SUCCESS;
PlanText plan_text;
PlanText out_plan_text;
plan_text.type_ = type;
ObSEArray<ObSqlPlanItem*, 16> sql_plan_infos;
ObSEArray<ObPlanRealInfo, 2> dummy_plan_infos;
if (OB_FAIL(init_buffer(plan_text))) {
LOG_WARN("failed to init buffer", K(ret));
} else if (OB_FAIL(get_sql_plan_infos(plan_text,
plan,
sql_plan_infos))) {
LOG_WARN("failed to get sql plan infos", K(ret));
} else if (OB_FAIL(format_sql_plan(sql_plan_infos,
type,
option,
dummy_plan_infos,
out_plan_text))) {
LOG_WARN("failed to format sql plan", K(ret));
} else if (OB_FAIL(plan_text_to_strings(out_plan_text, plan_strs))) {
LOG_WARN("failed to convert plan text to strings", K(ret));
}
if (OB_FAIL(ret)) {
LOG_WARN("failed to store sql plan", K(ret));
ret = OB_SUCCESS;
}
destroy_buffer(plan_text);
return ret;
}
int ObSqlPlan::get_sql_plan(const ObString &sql_id,
int64_t plan_id,
ExplainType type,
@ -253,7 +287,9 @@ int ObSqlPlan::get_plan_outline_info_one_line(PlanText &plan_text,
plan_text.is_outline_data_ = true;
BUF_PRINT_CONST_STR("/*+BEGIN_OUTLINE_DATA", plan_text);
const ObQueryHint &query_hint = query_ctx->get_query_hint();
if (OB_FAIL(get_plan_tree_outline(plan_text, plan->get_plan_root()))) {
if (OB_FAIL(reset_plan_tree_outline_flag(plan->get_plan_root()))) {
LOG_WARN("failed to reset plan tree outline flag", K(ret));
} else if (OB_FAIL(get_plan_tree_outline(plan_text, plan->get_plan_root()))) {
LOG_WARN("failed to get plan tree outline", K(ret));
} else if (OB_FAIL(query_hint.print_transform_hints(plan_text))) {
LOG_WARN("failed to print all transform hints", K(ret));
@ -528,7 +564,9 @@ int ObSqlPlan::get_plan_outline_info(PlanText &plan_text,
temp_text.pos_ = 0;
BUF_PRINT_CONST_STR("/*+\n BEGIN_OUTLINE_DATA", temp_text);
const ObQueryHint &query_hint = query_ctx->get_query_hint();
if (OB_FAIL(get_plan_tree_outline(temp_text, plan->get_plan_root()))) {
if (OB_FAIL(reset_plan_tree_outline_flag(plan->get_plan_root()))) {
LOG_WARN("failed to reset plan tree outline flag", K(ret));
} else if (OB_FAIL(get_plan_tree_outline(temp_text, plan->get_plan_root()))) {
LOG_WARN("failed to get plan tree outline", K(ret));
} else if (OB_FAIL(query_hint.print_transform_hints(temp_text))) {
LOG_WARN("failed to print all transform hints", K(ret));
@ -544,6 +582,23 @@ int ObSqlPlan::get_plan_outline_info(PlanText &plan_text,
return ret;
}
int ObSqlPlan::reset_plan_tree_outline_flag(ObLogicalOperator* op)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(op) || OB_ISNULL(op->get_plan())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpect null op", K(ret));
} else {
op->get_plan()->reset_outline_print_flags();
}
for (int i = 0; OB_SUCC(ret) && i < op->get_num_of_child(); ++i) {
if (OB_FAIL(SMART_CALL(reset_plan_tree_outline_flag(op->get_child(i))))) {
LOG_WARN("failed to reset child plan tree outline flag", K(ret));
}
}
return ret;
}
int ObSqlPlan::get_plan_tree_outline(PlanText &plan_text,
ObLogicalOperator* op)
{

View File

@ -126,6 +126,11 @@ public:
const ObExplainDisplayOpt& option,
ObIArray<common::ObString> &plan_strs);
int print_sql_plan(ObLogPlan* plan,
ExplainType type,
const ObExplainDisplayOpt& option,
ObIArray<common::ObString> &plan_strs);
int get_sql_plan(const ObString &sql_id,
int64_t plan_id,
ExplainType type,
@ -190,6 +195,8 @@ private:
ObLogPlan* plan,
ObSqlPlanItem* sql_plan_item);
static int reset_plan_tree_outline_flag(ObLogicalOperator* op);
static int get_plan_tree_outline(PlanText &plan_text,
ObLogicalOperator* op);