to issue<54750206>:select udf donot open transaction if udf has no dml stmt

This commit is contained in:
hanr881 2024-02-19 13:46:54 +00:00 committed by ob-robot
parent b6cdfaef1c
commit eb4ce0dc71
7 changed files with 32 additions and 16 deletions

View File

@ -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)) {

View File

@ -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;

View File

@ -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<ObLocalSessionVar, common::ObIAllocator> all_local_session_vars_;
public:
bool udf_has_dml_stmt_;
};
inline void ObPhysicalPlan::set_affected_last_insert_id(bool affected_last_insert_id)

View File

@ -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 */

View File

@ -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) &&

View File

@ -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));
}

View File

@ -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,