From b49b600a1c9fa7ed28c2fa3ad86f4c5cf07ec157 Mon Sep 17 00:00:00 2001 From: xianyu-w <707512433@qq.com> Date: Thu, 10 Aug 2023 11:12:38 +0000 Subject: [PATCH] Create a temp CONTEXT when check unique in transformer --- src/sql/rewrite/ob_transform_utils.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/sql/rewrite/ob_transform_utils.cpp b/src/sql/rewrite/ob_transform_utils.cpp index fb09fbd054..fc90f0332d 100644 --- a/src/sql/rewrite/ob_transform_utils.cpp +++ b/src/sql/rewrite/ob_transform_utils.cpp @@ -3946,19 +3946,13 @@ int ObTransformUtils::check_exprs_unique_on_table_items(const ObDMLStmt *stmt, ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpected null", K(ret)); } else { - lib::MemoryContext mem_context = NULL; lib::ContextParam param; param.set_mem_attr(session_info->get_effective_tenant_id(), "CheckUnique", ObCtxIds::DEFAULT_CTX_ID) .set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_page_size(OB_MALLOC_NORMAL_BLOCK_SIZE); - 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 { - ObArenaAllocator &alloc = mem_context->get_arena_allocator(); + CREATE_WITH_TEMP_CONTEXT(param) { + ObArenaAllocator &alloc = CURRENT_CONTEXT->get_arena_allocator(); ObFdItemFactory fd_item_factory(alloc); ObRawExprFactory expr_factory(alloc); UniqueCheckHelper check_helper; @@ -3985,9 +3979,6 @@ int ObTransformUtils::check_exprs_unique_on_table_items(const ObDMLStmt *stmt, LOG_TRACE("get is unique result", K(exprs), K(table_items), K(is_unique)); } } - if (OB_NOT_NULL(mem_context)) { - DESTROY_CONTEXT(mem_context); - } } return ret; } @@ -4076,19 +4067,13 @@ int ObTransformUtils::check_stmt_unique(const ObSelectStmt *stmt, if (OB_FAIL(ret) || is_unique || !need_check) { /*do nothing*/ } else { - lib::MemoryContext mem_context = NULL; lib::ContextParam param; param.set_mem_attr(session_info->get_effective_tenant_id(), "CheckUnique", ObCtxIds::DEFAULT_CTX_ID) .set_properties(lib::USE_TL_PAGE_OPTIONAL) .set_page_size(OB_MALLOC_NORMAL_BLOCK_SIZE); - if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(mem_context, param))) { - LOG_WARN("failed to create memory context", K(ret)); - } else if (OB_ISNULL(mem_context)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("failed to create memory context", K(ret)); - } else { - ObArenaAllocator &alloc = mem_context->get_arena_allocator(); + CREATE_WITH_TEMP_CONTEXT(param) { + ObArenaAllocator &alloc = CURRENT_CONTEXT->get_arena_allocator(); ObFdItemFactory fd_item_factory(alloc); ObRawExprFactory expr_factory(alloc); UniqueCheckHelper check_helper; @@ -4114,9 +4099,6 @@ int ObTransformUtils::check_stmt_unique(const ObSelectStmt *stmt, LOG_TRACE("get is unique result", K(ret), K(is_unique)); } } - if (OB_NOT_NULL(mem_context)) { - DESTROY_CONTEXT(mem_context); - } } return ret; }