From 88c8c6cb08253b91510207661b6db53bb62b5519 Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 8 Feb 2023 15:36:38 +0800 Subject: [PATCH] to issue<38555062>:fix nested sql bug when using execute immediate stmt to exexute anonymous block --- src/sql/ob_sql_utils.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/sql/ob_sql_utils.cpp b/src/sql/ob_sql_utils.cpp index 0cc852202f..c2522186fa 100644 --- a/src/sql/ob_sql_utils.cpp +++ b/src/sql/ob_sql_utils.cpp @@ -4281,10 +4281,29 @@ bool ObSQLUtils::is_pl_nested_sql(ObExecContext *cur_ctx) ObExecContext *parent_ctx = cur_ctx->get_parent_ctx(); //parent_sql = is_dml_stmt means this sql is triggered by a sql, not pl procedure if (OB_NOT_NULL(parent_ctx->get_sql_ctx()) - && ObStmt::is_dml_stmt(parent_ctx->get_sql_ctx()->stmt_type_) && parent_ctx->get_pl_stack_ctx() != nullptr && !parent_ctx->get_pl_stack_ctx()->in_autonomous()) { - bret = true; + if (ObStmt::is_dml_stmt(parent_ctx->get_sql_ctx()->stmt_type_)) { + bret = true; + } else if (stmt::T_ANONYMOUS_BLOCK == parent_ctx->get_sql_ctx()->stmt_type_) { + /* anonymous block in a store procedure will be send to sql engine as sql, which will make new obexeccontext. + consider follow scene: + dml1(exec_ctx1)->udf/trigger->procedure->anonymous block(exec_ctx2)->dml2 + outer dml1 and inner dml2 form a nested scene. bug current code logic cannot identify this scene. + so it need to skip anonymous block obexeccontext */ + do { + parent_ctx = parent_ctx->get_parent_ctx(); + } while (OB_NOT_NULL(parent_ctx) && OB_NOT_NULL(parent_ctx->get_sql_ctx()) && + (stmt::T_ANONYMOUS_BLOCK == parent_ctx->get_sql_ctx()->stmt_type_)); + + if (OB_NOT_NULL(parent_ctx) && + OB_NOT_NULL(parent_ctx->get_sql_ctx()) && + OB_NOT_NULL(parent_ctx->get_pl_stack_ctx()) && + ObStmt::is_dml_stmt(parent_ctx->get_sql_ctx()->stmt_type_) && + !parent_ctx->get_pl_stack_ctx()->in_autonomous()) { + bret = true; + } + } } } return bret;