diff --git a/src/sql/code_generator/ob_static_engine_cg.cpp b/src/sql/code_generator/ob_static_engine_cg.cpp index 84ee2687b9..fa5823ab06 100644 --- a/src/sql/code_generator/ob_static_engine_cg.cpp +++ b/src/sql/code_generator/ob_static_engine_cg.cpp @@ -7181,9 +7181,11 @@ int ObStaticEngineCG::set_other_properties(const ObLogPlan &log_plan, ObPhysical //为了支持触发器/UDF支持异常捕获,要求含有pl udf的涉及修改表数据的dml串行执行 phy_plan_->set_need_serial_exec(true); } - phy_plan_->set_contain_pl_udf_or_trigger(true); phy_plan_->set_has_nested_sql(true); } else {/*do nothing*/} + if (OB_SUCC(ret)) { + phy_plan_->set_contain_pl_udf_or_trigger(log_plan.get_stmt()->get_query_ctx()->has_pl_udf_); + } } if (OB_SUCC(ret)) { phy_plan_->calc_whether_need_trans(); diff --git a/src/sql/ob_sql_context.h b/src/sql/ob_sql_context.h index 75e2b91869..c5fc4ec94e 100644 --- a/src/sql/ob_sql_context.h +++ b/src/sql/ob_sql_context.h @@ -686,7 +686,8 @@ public: res_map_rule_id_(common::OB_INVALID_ID), res_map_rule_param_idx_(common::OB_INVALID_INDEX), root_stmt_(NULL), - udf_has_select_stmt_(false) + udf_has_select_stmt_(false), + has_pl_udf_(false) { } TO_STRING_KV(N_PARAM_NUM, question_marks_count_, @@ -731,6 +732,7 @@ public: res_map_rule_param_idx_ = common::OB_INVALID_INDEX; root_stmt_ = NULL; udf_has_select_stmt_ = false; + has_pl_udf_ = false; } int64_t get_new_stmt_id() { return stmt_count_++; } @@ -814,6 +816,7 @@ public: int64_t res_map_rule_param_idx_; ObDMLStmt *root_stmt_; bool udf_has_select_stmt_; // udf has select stmt, not contain other dml stmt + bool has_pl_udf_; // used to mark sql contain pl udf }; } /* ns sql*/ } /* ns oceanbase */ diff --git a/src/sql/resolver/dml/ob_dml_resolver.cpp b/src/sql/resolver/dml/ob_dml_resolver.cpp index 1fb575c71b..9e471b84a9 100755 --- a/src/sql/resolver/dml/ob_dml_resolver.cpp +++ b/src/sql/resolver/dml/ob_dml_resolver.cpp @@ -2666,6 +2666,7 @@ int ObDMLResolver::resolve_qualified_identifier(ObQualifiedName &q_name, ret = OB_ERR_PRIVATE_UDF_USE_IN_SQL; LOG_WARN("function 'string' may not be used in SQL", K(ret), KPC(udf)); } else { + OX (stmt_->get_query_ctx()->has_pl_udf_ = true); OX (stmt_->get_query_ctx()->disable_udf_parallel_ |= !udf->is_parallel_enable()); } } else if (T_FUN_PL_COLLECTION_CONSTRUCT == real_ref_expr->get_expr_type()) { @@ -2803,6 +2804,7 @@ int ObDMLResolver::resolve_qualified_identifier(ObQualifiedName &q_name, ret = OB_ERR_UNEXPECTED; LOG_WARN("failed cast udf raw expr", K(ret)); } else { + stmt_->get_query_ctx()->has_pl_udf_ = true; stmt_->get_query_ctx()->disable_udf_parallel_ |= !udf->is_parallel_enable(); } } @@ -4753,6 +4755,7 @@ int ObDMLResolver::resolve_function_table_item(const ParseNode &parse_tree, OZ (stmt->add_ref_obj_version(dep_obj_id, dep_db_id, ObObjectType::VIEW, table_version, *allocator_)); } } + OX (stmt_->get_query_ctx()->has_pl_udf_ = true); OX (stmt_->get_query_ctx()->disable_udf_parallel_ |= !udf->is_parallel_enable()); } else if (OB_SUCC(ret) && function_table_expr->is_sys_func_expr()) { // xxx @@ -11303,6 +11306,7 @@ int ObDMLResolver::collect_schema_version(ObRawExpr *expr) *expr, stmt_->get_query_ctx()->udf_has_select_stmt_)); OX (stmt_->get_query_ctx()->disable_udf_parallel_ |= !udf_expr->is_parallel_enable()); + OX (stmt_->get_query_ctx()->has_pl_udf_ = true); if (OB_SUCC(ret) && T_FIELD_LIST_SCOPE == current_scope_ && udf_expr->get_result_type().is_ext() && diff --git a/src/sql/session/ob_basic_session_info.cpp b/src/sql/session/ob_basic_session_info.cpp index e3e6a3c24d..2886fe1958 100644 --- a/src/sql/session/ob_basic_session_info.cpp +++ b/src/sql/session/ob_basic_session_info.cpp @@ -4100,6 +4100,21 @@ int ObBasicSessionInfo::calc_need_serialize_vars(ObIArray &sy } } + if (OB_SUCC(ret) && OB_NOT_NULL(cur_phy_plan_) && cur_phy_plan_->contain_pl_udf_or_trigger()) { + // 如果该语句包含PL UDF/TRIGGER, 将该Sesssion上变化的Package变量进行同步 + // TODO: 当前做的不够精细, 后续应该做到仅同步需要的变量 + ObSessionValMap::VarNameValMap::const_iterator iter = user_var_val_map_.get_val_map().begin(); + for (; OB_SUCC(ret) && iter != user_var_val_map_.get_val_map().end(); ++iter) { + const ObString name = iter->first; + if (name.prefix_match("pkg.")) { + if (OB_FAIL(user_var_names.push_back(name))) { + LOG_WARN("failed push back package var name", K(name)); + } + } + } + LOG_DEBUG("sync package variables", K(user_var_names), K(cur_phy_plan_), K(lbt())); + } + if (OB_SUCC(ret) && cur_phy_plan_ != nullptr) { // 处理该语句用到的需要序列化的用户变量和系统变量 const ObIArray &extra_serialize_vars = cur_phy_plan_->get_vars();