diff --git a/src/sql/code_generator/ob_static_engine_cg.cpp b/src/sql/code_generator/ob_static_engine_cg.cpp index 106fb314a..33e0617e4 100644 --- a/src/sql/code_generator/ob_static_engine_cg.cpp +++ b/src/sql/code_generator/ob_static_engine_cg.cpp @@ -7982,6 +7982,7 @@ int ObStaticEngineCG::set_other_properties(const ObLogPlan &log_plan, ObPhysical } 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_); + phy_plan_->set_udf_has_dml_stmt(log_plan.get_stmt()->get_query_ctx()->udf_has_dml_stmt_); } } if (OB_SUCC(ret)) { diff --git a/src/sql/engine/ob_physical_plan.cpp b/src/sql/engine/ob_physical_plan.cpp index 8d693fae6..a8f336da1 100644 --- a/src/sql/engine/ob_physical_plan.cpp +++ b/src/sql/engine/ob_physical_plan.cpp @@ -136,7 +136,8 @@ ObPhysicalPlan::ObPhysicalPlan(MemoryContext &mem_context /* = CURRENT_CONTEXT * use_rich_format_(false), subschema_ctx_(allocator_), disable_auto_memory_mgr_(false), - all_local_session_vars_(&allocator_) + all_local_session_vars_(&allocator_), + udf_has_dml_stmt_(false) { } @@ -234,6 +235,7 @@ void ObPhysicalPlan::reset() is_enable_px_fast_reclaim_ = false; subschema_ctx_.reset(); all_local_session_vars_.reset(); + udf_has_dml_stmt_ = false; } void ObPhysicalPlan::destroy() @@ -793,7 +795,8 @@ OB_SERIALIZE_MEMBER(ObPhysicalPlan, gtt_trans_scope_ids_, subschema_ctx_, use_rich_format_, - disable_auto_memory_mgr_); + disable_auto_memory_mgr_, + udf_has_dml_stmt_); int ObPhysicalPlan::set_table_locations(const ObTablePartitionInfoArray &infos, ObSchemaGetterGuard &schema_guard) @@ -1122,7 +1125,7 @@ void ObPhysicalPlan::calc_whether_need_trans() } } // mysql允许select udf中有dml,需要保证select 整体原子性 - if (!bool_ret && contain_pl_udf_or_trigger() && lib::is_mysql_mode() && stmt::T_EXPLAIN != stmt_type_) { + if (!bool_ret && contain_pl_udf_or_trigger() && udf_has_dml_stmt() && lib::is_mysql_mode() && stmt::T_EXPLAIN != stmt_type_) { bool_ret = true; } is_need_trans_ = bool_ret; diff --git a/src/sql/engine/ob_physical_plan.h b/src/sql/engine/ob_physical_plan.h index 625d72453..ed22086ea 100644 --- a/src/sql/engine/ob_physical_plan.h +++ b/src/sql/engine/ob_physical_plan.h @@ -439,7 +439,7 @@ public: } inline bool is_plain_select() const { - return stmt::T_SELECT == stmt_type_ && !has_for_update() && !contain_pl_udf_or_trigger_; + return stmt::T_SELECT == stmt_type_ && !has_for_update() && !(contain_pl_udf_or_trigger_ && udf_has_dml_stmt_); } inline bool contain_paramed_column_field() const { return contain_paramed_column_field_; } @@ -461,7 +461,8 @@ public: void set_need_serial_exec(bool need_serial_exec) { need_serial_exec_ = need_serial_exec; } bool get_need_serial_exec() const { return need_serial_exec_; } - + void set_udf_has_dml_stmt(bool v) { udf_has_dml_stmt_ = v; } + bool udf_has_dml_stmt() { return udf_has_dml_stmt_; } void set_contain_pl_udf_or_trigger(bool v) { contain_pl_udf_or_trigger_ = v; } bool contain_pl_udf_or_trigger() { return contain_pl_udf_or_trigger_; } bool contain_pl_udf_or_trigger() const { return contain_pl_udf_or_trigger_; } @@ -671,6 +672,9 @@ public: bool disable_auto_memory_mgr_; private: common::ObFixedArray all_local_session_vars_; + +public: + bool udf_has_dml_stmt_; }; inline void ObPhysicalPlan::set_affected_last_insert_id(bool affected_last_insert_id) diff --git a/src/sql/ob_sql_context.h b/src/sql/ob_sql_context.h index 0980ebab4..70cbc16f2 100644 --- a/src/sql/ob_sql_context.h +++ b/src/sql/ob_sql_context.h @@ -686,9 +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), - has_pl_udf_(false), - optimizer_features_enable_version_(0) + optimizer_features_enable_version_(0), + udf_flag_(0) { } TO_STRING_KV(N_PARAM_NUM, question_marks_count_, @@ -732,8 +731,7 @@ 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; - has_pl_udf_ = false; + udf_flag_ = 0; optimizer_features_enable_version_ = 0; } @@ -817,9 +815,16 @@ public: uint64_t res_map_rule_id_; 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 uint64_t optimizer_features_enable_version_; + union { + int8_t udf_flag_; + struct { + int8_t has_pl_udf_ : 1; // used to mark sql contain pl udf + int8_t udf_has_select_stmt_ : 1; // udf has select stmt, not contain other dml stmt + int8_t udf_has_dml_stmt_ : 1; // udf has dml stmt + int8_t reserved_:5; + }; + }; }; } /* 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 4ee1972aa..b9c59dc12 100755 --- a/src/sql/resolver/dml/ob_dml_resolver.cpp +++ b/src/sql/resolver/dml/ob_dml_resolver.cpp @@ -11361,7 +11361,7 @@ int ObDMLResolver::collect_schema_version(ObRawExpr *expr) OZ (ObResolverUtils::set_parallel_info(*params_.session_info_, *params_.schema_checker_->get_schema_guard(), *expr, - stmt_->get_query_ctx()->udf_has_select_stmt_)); + *stmt_->get_query_ctx())); 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) && diff --git a/src/sql/resolver/ob_resolver_utils.cpp b/src/sql/resolver/ob_resolver_utils.cpp index e8e926bab..c09bc2110 100644 --- a/src/sql/resolver/ob_resolver_utils.cpp +++ b/src/sql/resolver/ob_resolver_utils.cpp @@ -6881,7 +6881,7 @@ int ObResolverUtils::resolve_string(const ParseNode *node, ObString &string) int ObResolverUtils::set_parallel_info(sql::ObSQLSessionInfo &session_info, share::schema::ObSchemaGetterGuard &schema_guard, ObRawExpr &expr, - bool &contain_select_stmt) + ObQueryCtx &ctx) { int ret = OB_SUCCESS; const ObRoutineInfo *routine_info = NULL; @@ -6918,7 +6918,10 @@ int ObResolverUtils::set_parallel_info(sql::ObSQLSessionInfo &session_info, enable_parallel = false; } if (routine_info->is_reads_sql_data()) { - contain_select_stmt = true; + ctx.udf_has_select_stmt_ = true; + } + if (routine_info->is_modifies_sql_data()) { + ctx.udf_has_dml_stmt_ = true; } OX (udf_raw_expr.set_parallel_enable(enable_parallel)); } diff --git a/src/sql/resolver/ob_resolver_utils.h b/src/sql/resolver/ob_resolver_utils.h index 06534b7e5..6940883ac 100644 --- a/src/sql/resolver/ob_resolver_utils.h +++ b/src/sql/resolver/ob_resolver_utils.h @@ -289,7 +289,7 @@ public: static int set_parallel_info(sql::ObSQLSessionInfo &session_info, share::schema::ObSchemaGetterGuard &schema_guard, ObRawExpr &expr, - bool &contain_select_stmt); + ObQueryCtx &ctx); static int resolve_external_symbol(common::ObIAllocator &allocator, sql::ObRawExprFactory &expr_factory,