Fix dynamic leak in cost based rewrite

This commit is contained in:
xianyu-w
2023-07-21 08:12:44 +00:00
committed by ob-robot
parent 145e1ce044
commit c76d1f3c71

View File

@ -381,7 +381,6 @@ int ObTransformRule::evaluate_cost(common::ObIArray<ObParentDMLStmt> &parent_stm
ctx_->eval_cost_ = true; ctx_->eval_cost_ = true;
ParamStore &param_store = ctx_->exec_ctx_->get_physical_plan_ctx()->get_param_store_for_update(); ParamStore &param_store = ctx_->exec_ctx_->get_physical_plan_ctx()->get_param_store_for_update();
ObDMLStmt *root_stmt = NULL; ObDMLStmt *root_stmt = NULL;
lib::MemoryContext mem_context = nullptr;
lib::ContextParam param; lib::ContextParam param;
ObTransformerImpl trans(ctx_); ObTransformerImpl trans(ctx_);
param.set_mem_attr(ctx_->session_info_->get_effective_tenant_id(), param.set_mem_attr(ctx_->session_info_->get_effective_tenant_id(),
@ -393,48 +392,43 @@ int ObTransformRule::evaluate_cost(common::ObIArray<ObParentDMLStmt> &parent_stm
LOG_WARN("failed to prepare eval cost stmt", K(ret)); LOG_WARN("failed to prepare eval cost stmt", K(ret));
} else if (OB_FAIL(trans.transform_heuristic_rule(reinterpret_cast<ObDMLStmt*&>(root_stmt)))) { } else if (OB_FAIL(trans.transform_heuristic_rule(reinterpret_cast<ObDMLStmt*&>(root_stmt)))) {
LOG_WARN("failed to transform heuristic rule", K(ret)); LOG_WARN("failed to transform heuristic rule", K(ret));
} else if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context, param))) {
LOG_WARN("failed to create memory entity", K(ret));
} else if (OB_ISNULL(mem_context)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to create memory entity", K(ret));
} else { } else {
LOG_DEBUG("get transformed heuristic rule stmt when evaluate_cost", K(*root_stmt)); LOG_DEBUG("get transformed heuristic rule stmt when evaluate_cost", K(*root_stmt));
HEAP_VAR(ObOptimizerContext, optctx, CREATE_WITH_TEMP_CONTEXT(param) {
ctx_->session_info_, HEAP_VAR(ObOptimizerContext, optctx,
ctx_->exec_ctx_, ctx_->session_info_,
ctx_->sql_schema_guard_, ctx_->exec_ctx_,
ctx_->opt_stat_mgr_, ctx_->sql_schema_guard_,
mem_context->get_arena_allocator(), ctx_->opt_stat_mgr_,
&ctx_->exec_ctx_->get_physical_plan_ctx()->get_param_store(), CURRENT_CONTEXT->get_arena_allocator(),
*ctx_->self_addr_, &ctx_->exec_ctx_->get_physical_plan_ctx()->get_param_store(),
GCTX.srv_rpc_proxy_, *ctx_->self_addr_,
stmt->get_query_ctx()->get_global_hint(), GCTX.srv_rpc_proxy_,
*ctx_->expr_factory_, stmt->get_query_ctx()->get_global_hint(),
root_stmt, *ctx_->expr_factory_,
false, root_stmt,
ctx_->exec_ctx_->get_stmt_factory()->get_query_ctx()) { false,
//optctx.set_only_ds_basic_stat(true); ctx_->exec_ctx_->get_stmt_factory()->get_query_ctx()) {
ObOptimizer optimizer(optctx); //optctx.set_only_ds_basic_stat(true);
ObLogPlan *plan = NULL; ObOptimizer optimizer(optctx);
if (OB_FAIL(optimizer.get_optimization_cost(*root_stmt, plan, plan_cost))) { ObLogPlan *plan = NULL;
LOG_WARN("failed to get optimization cost", K(ret)); if (OB_FAIL(optimizer.get_optimization_cost(*root_stmt, plan, plan_cost))) {
} else if (NULL == check_ctx) { LOG_WARN("failed to get optimization cost", K(ret));
// do nothing } else if (NULL == check_ctx) {
} else if (OB_FAIL(is_expected_plan(plan, check_ctx, is_trans_stmt, is_expected))) { // do nothing
LOG_WARN("failed to check transformed plan", K(ret)); } else if (OB_FAIL(is_expected_plan(plan, check_ctx, is_trans_stmt, is_expected))) {
LOG_WARN("failed to check transformed plan", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(eval_cost_helper.recover_context(*ctx_->exec_ctx_->get_physical_plan_ctx(),
*ctx_->exec_ctx_->get_stmt_factory()->get_query_ctx(),
*ctx_))) {
LOG_WARN("failed to recover context", K(ret));
} else if (OB_FAIL(ObTransformUtils::free_stmt(*ctx_->stmt_factory_, root_stmt))) {
LOG_WARN("failed to free stmt", K(ret));
}
} }
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(eval_cost_helper.recover_context(*ctx_->exec_ctx_->get_physical_plan_ctx(),
*ctx_->exec_ctx_->get_stmt_factory()->get_query_ctx(),
*ctx_))) {
LOG_WARN("failed to recover context", K(ret));
} else if (OB_FAIL(ObTransformUtils::free_stmt(*ctx_->stmt_factory_, root_stmt))) {
LOG_WARN("failed to free stmt", K(ret));
} else {
DESTROY_CONTEXT(mem_context);
} }
} }
} }