[CP] [to #53512507]fixed cursor exec param in process_record

This commit is contained in:
LiuYoung00 2024-02-07 18:04:20 +00:00 committed by ob-robot
parent 39cff7c1f2
commit 1e40b820b0
4 changed files with 53 additions and 14 deletions

View File

@ -516,7 +516,8 @@ int ObInnerSQLConnection::process_record(sql::ObResultSet &result_set,
ObExecTimestamp &exec_timestamp,
bool has_tenant_resource,
const ObString &ps_sql,
bool is_from_pl)
bool is_from_pl,
ObString *pl_exec_params)
{
int ret = OB_SUCCESS;
const bool enable_perf_event = lib::is_diagnose_info_enabled();
@ -545,10 +546,9 @@ int ObInnerSQLConnection::process_record(sql::ObResultSet &result_set,
if (enable_sql_audit) {
ret = process_audit_record(result_set, sql_ctx, session, last_ret, execution_id,
ps_stmt_id, has_tenant_resource, ps_sql, is_from_pl);
if (is_from_pl && NULL != result_set.get_exec_context().get_physical_plan_ctx()) {
ObMPStmtExecute::store_params_value_to_str(alloc, session,
&result_set.get_exec_context().get_physical_plan_ctx()->get_param_store_for_update(),
audit_record.params_value_, audit_record.params_value_len_);
if (NULL != pl_exec_params) {
audit_record.params_value_ = pl_exec_params->ptr();
audit_record.params_value_len_ = pl_exec_params->length();
}
}
ObSQLUtils::handle_audit_record(false, sql::PSCursor == audit_record.exec_timestamp_.exec_type_

View File

@ -286,7 +286,8 @@ public:
sql::ObExecTimestamp &exec_timestamp,
bool has_tenant_resource,
const ObString &ps_sql,
bool is_from_pl = false);
bool is_from_pl = false,
ObString *pl_exec_params = NULL);
static int process_audit_record(sql::ObResultSet &result_set,
sql::ObSqlCtx &sql_ctx,
sql::ObSQLSessionInfo &session,

View File

@ -21,6 +21,7 @@
#include "observer/ob_server_struct.h"
#include "observer/mysql/ob_query_retry_ctrl.h"
#include "observer/mysql/ob_sync_cmd_driver.h"
#include "observer/mysql/obmp_stmt_execute.h"
#include "sql/parser/ob_parser.h"
#include "sql/resolver/expr/ob_raw_expr_util.h"
#include "sql/resolver/ob_stmt_resolver.h"
@ -1728,7 +1729,8 @@ int ObSPIService::spi_inner_execute(ObPLExecCtx *ctx,
exec_timestamp,
true,
sql != NULL ? sql : ps_sql,
true);
true,
spi_result.get_exec_params_str_ptr());
session_info->get_raw_audit_record().exec_record_ = record_bk;
session_info->get_raw_audit_record().try_cnt_ = try_cnt;
} else {
@ -1952,7 +1954,8 @@ int ObSPIService::dbms_cursor_execute(ObPLExecCtx *ctx,
exec_timestamp,
true,
ps_sql,
true);
true,
spi_result.get_exec_params_str_ptr());
} else {
LOG_DEBUG("result set is not inited, do not process record",
K(ret), K(ps_sql), K(sql_stmt), K(stmt_type));
@ -2928,7 +2931,8 @@ int ObSPIService::spi_execute_immediate(ObPLExecCtx *ctx,
exec_timestamp,
true,
0 == param_count ? sql_str.string() : ps_sql,
true);
true,
spi_result.get_exec_params_str_ptr());
session->get_raw_audit_record().exec_record_ = record_bk;
session->get_raw_audit_record().try_cnt_ = try_cnt;
} else {
@ -3773,6 +3777,8 @@ int ObSPIService::dbms_cursor_open(ObPLExecCtx *ctx,
exec_timestamp.exec_type_ = cursor.is_ps_cursor() ? sql::PSCursor : sql::DbmsCursor;
ObWaitEventDesc max_wait_desc;
ObWaitEventStat total_wait_desc;
ObArenaAllocator exec_param_alloc;
ObString exec_param_str;
const bool enable_perf_event = lib::is_diagnose_info_enabled();
const bool enable_sql_audit = GCONF.enable_sql_audit
&& ctx->exec_ctx_->get_my_session()->get_local_ob_enable_sql_audit();
@ -3804,6 +3810,17 @@ int ObSPIService::dbms_cursor_open(ObPLExecCtx *ctx,
}
}
if (OB_SUCC(ret) && exec_params.count() > 0) {
char *tmp_ptr = NULL;
int64_t tmp_len = 0;
OZ (ObMPStmtExecute::store_params_value_to_str(exec_param_alloc,
*session,
&exec_params,
tmp_ptr,
tmp_len));
OX (exec_param_str.assign(tmp_ptr, tmp_len));
}
if (OB_FAIL(ret)) {
// do nothing
} else if (!for_update && use_stream) {
@ -3916,7 +3933,8 @@ int ObSPIService::dbms_cursor_open(ObPLExecCtx *ctx,
exec_timestamp,
true,
(exec_params.count() > 0 || cursor.is_ps_cursor()) ? ps_sql : sql_str,
true);
true,
&exec_param_str);
session_info->get_raw_audit_record().exec_record_ = record_bk;
session_info->get_raw_audit_record().try_cnt_ = try_cnt;
}
@ -4021,7 +4039,8 @@ int ObSPIService::dbms_cursor_open(ObPLExecCtx *ctx,
exec_timestamp,
true,
(exec_params.count() > 0 || cursor.is_ps_cursor()) ? ps_sql : sql_str,
true);
true,
&exec_param_str);
session_info->get_raw_audit_record().exec_record_ = record_bk;
session_info->get_raw_audit_record().try_cnt_ = retry_cnt;
}
@ -4248,7 +4267,8 @@ int ObSPIService::do_cursor_fetch(ObPLExecCtx *ctx,
exec_timestamp,
true,
ObString(),
true);
true,
spi_result->get_exec_params_str_ptr());
session_info->get_raw_audit_record().exec_record_ = record_bk;
session_info->get_raw_audit_record().try_cnt_ = try_cnt;
}
@ -6323,6 +6343,20 @@ int ObSPIService::inner_open(ObPLExecCtx *ctx,
OZ (construct_exec_params(ctx, param_allocator, param_exprs, param_count,
into_exprs, into_count, exec_params, out_params, is_forall),
K(sql), K(type), K(param_count), K(out_params), K(exec_params));
if (OB_SUCC(ret)
&& OB_NOT_NULL(ctx)
&& OB_NOT_NULL(ctx->exec_ctx_)
&& OB_NOT_NULL(ctx->exec_ctx_->get_my_session())) {
// add exec_param_info for sql_audit
char *tmp_ptr = NULL;
int64_t tmp_len = 0;
OZ (ObMPStmtExecute::store_params_value_to_str(spi_result.get_allocaor(),
*ctx->exec_ctx_->get_my_session(),
&exec_params,
tmp_ptr,
tmp_len));
OX (spi_result.get_exec_params_str_ptr()->assign(tmp_ptr, tmp_len));
}
}
if (OB_SUCC(ret) && is_forall) {

View File

@ -126,7 +126,8 @@ public:
orign_session_value_(NULL),
cursor_session_value_(NULL),
nested_session_value_(NULL),
out_params_() {
out_params_(),
exec_params_str_() {
}
~ObSPIResultSet() { reset(); }
int init(sql::ObSQLSessionInfo &session_info);
@ -157,8 +158,8 @@ public:
cursor_session_value_ = NULL;
nested_session_value_ = NULL;
out_params_.reset();
exec_params_str_.reset();
allocator_.reset();
is_inited_ = false;
}
void reset_member_for_retry(sql::ObSQLSessionInfo &session_info)
@ -167,6 +168,7 @@ public:
result_set_->~ObResultSet();
}
sql_ctx_.reset();
exec_params_str_.reset();
//allocator_.reset();
mem_context_->get_arena_allocator().reset();
result_set_ = new (buf_) ObResultSet(session_info, mem_context_->get_arena_allocator());
@ -212,6 +214,7 @@ public:
void end_cursor_stmt(pl::ObPLExecCtx *pl_ctx, int &result);
int start_nested_stmt_if_need(pl::ObPLExecCtx *pl_ctx, const ObString &sql, stmt::StmtType stmt_type, bool for_update);
void end_nested_stmt_if_need(pl::ObPLExecCtx *pl_ctx, int &result);
ObString *get_exec_params_str_ptr() { return &exec_params_str_; }
private:
bool is_inited_;
EndStmtType need_end_nested_stmt_;
@ -232,6 +235,7 @@ private:
sql::ObSQLSessionInfo::StmtSavedValue *cursor_session_value_;
sql::ObSQLSessionInfo::StmtSavedValue *nested_session_value_;
ObSPIOutParams out_params_; // 用于记录function的返回值
ObString exec_params_str_;
};
class ObSPIService