diff --git a/src/sql/monitor/ob_sql_plan.cpp b/src/sql/monitor/ob_sql_plan.cpp index 24e2c82abf..5cffb9df8f 100644 --- a/src/sql/monitor/ob_sql_plan.cpp +++ b/src/sql/monitor/ob_sql_plan.cpp @@ -122,6 +122,7 @@ int ObSqlPlan::store_sql_plan_for_explain(ObExecContext *ctx, PlanText out_plan_text; plan_text.type_ = type; ObSEArray sql_plan_infos; + bool allocate_mem_failed = false; 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, @@ -129,12 +130,14 @@ int ObSqlPlan::store_sql_plan_for_explain(ObExecContext *ctx, sql_plan_infos))) { LOG_WARN("failed to get sql plan infos", K(ret)); } + allocate_mem_failed |= OB_ALLOCATE_MEMORY_FAILED == ret; if (OB_FAIL(format_sql_plan(sql_plan_infos, type, option, out_plan_text))) { LOG_WARN("failed to format sql plan", K(ret)); } + allocate_mem_failed |= OB_ALLOCATE_MEMORY_FAILED == ret; if (OB_FAIL(plan_text_to_strings(out_plan_text, plan_strs))) { LOG_WARN("failed to convert plan text to strings", K(ret)); } else if (OB_FAIL(inner_store_sql_plan_for_explain(ctx, @@ -147,6 +150,16 @@ int ObSqlPlan::store_sql_plan_for_explain(ObExecContext *ctx, ret = OB_SUCCESS; } } + if (OB_SUCC(ret)) { + if (allocate_mem_failed) { + if (OB_FAIL(plan_strs.push_back("Plan truncated due to insufficient memory!"))) { + LOG_WARN("failed to push back string", K(ret)); + } + } else if (plan_strs.empty()) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("failed to generate plan", K(ret)); + } + } destroy_buffer(plan_text); return ret; } diff --git a/src/sql/ob_optimizer_trace_impl.cpp b/src/sql/ob_optimizer_trace_impl.cpp index 7dca0cfcf2..5caaaeb62b 100644 --- a/src/sql/ob_optimizer_trace_impl.cpp +++ b/src/sql/ob_optimizer_trace_impl.cpp @@ -270,8 +270,9 @@ int ObOptimizerTraceImpl::append_lower(const char* msg) int ret = OB_SUCCESS; char *buf = NULL; int64_t buf_len = strlen(msg); + common::ObArenaAllocator allocator("OptimizerTrace"); if (buf_len <= 0) { - } else if (OB_ISNULL(buf = static_cast(allocator_.alloc(buf_len)))) { + } else if (OB_ISNULL(buf = static_cast(allocator.alloc(buf_len)))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_ERROR("Failed to allocate buffer", "buffer size", buf_len, K(ret)); } else { diff --git a/src/sql/ob_optimizer_trace_impl.h b/src/sql/ob_optimizer_trace_impl.h index 853721e670..19c5ba722c 100644 --- a/src/sql/ob_optimizer_trace_impl.h +++ b/src/sql/ob_optimizer_trace_impl.h @@ -322,7 +322,8 @@ ObOptimizerTraceImpl::append(const T* expr) char *buf = NULL; int64_t buf_len = OB_MAX_SQL_LENGTH; int64_t pos = 0; - if (OB_ISNULL(buf = (char*)allocator_.alloc(buf_len))) { + common::ObArenaAllocator allocator("OptimizerTrace"); + if (OB_ISNULL(buf = (char*)allocator.alloc(buf_len))) { ret = OB_ERR_UNEXPECTED; //LOG_WARN("failed to alloc buffer", K(ret)); } else if (OB_NOT_NULL(expr)) { @@ -346,8 +347,9 @@ ObOptimizerTraceImpl::append(const T* value) int ret = OB_SUCCESS; ObString sql; ObObjPrintParams print_params; + common::ObArenaAllocator allocator("OptimizerTrace"); // TODO: @zhenling, use a valid schema guard in each query - if (OB_FAIL(ObSQLUtils::reconstruct_sql(allocator_, + if (OB_FAIL(ObSQLUtils::reconstruct_sql(allocator, value, sql, NULL, diff --git a/src/sql/optimizer/ob_dynamic_sampling.cpp b/src/sql/optimizer/ob_dynamic_sampling.cpp index a73c51868b..8ae2989ec6 100644 --- a/src/sql/optimizer/ob_dynamic_sampling.cpp +++ b/src/sql/optimizer/ob_dynamic_sampling.cpp @@ -520,9 +520,12 @@ int ObDynamicSampling::estimte_rowcount(int64_t max_ds_timeout, need_restore_session = true; } if (OB_SUCC(ret)) { + //do not trace dynamic sample sql execute + STOP_OPT_TRACE; if (OB_FAIL(do_estimate_rowcount(session_info, raw_sql_str))) { LOG_WARN("failed to do estimate rowcount", K(ret)); } + RESUME_OPT_TRACE; } //regardless of whether the above behavior is successful or not, we need to restore session. if (need_restore_session) { diff --git a/src/sql/optimizer/ob_log_plan.cpp b/src/sql/optimizer/ob_log_plan.cpp index 45daa282de..4305eedda4 100644 --- a/src/sql/optimizer/ob_log_plan.cpp +++ b/src/sql/optimizer/ob_log_plan.cpp @@ -3180,6 +3180,8 @@ int ObLogPlan::generate_single_join_level_with_DP(ObIArray &join LOG_TRACE("succeed to generate join order", K(left_tree->get_tables()), K(right_tree->get_tables()), K(is_valid_join), K(abort_type)); } + OPT_TRACE_TIME_USED; + OPT_TRACE_MEM_USED; } OPT_TRACE_END_SECTION; }