patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -17,16 +17,23 @@
#include "sql/code_generator/ob_expr_generator_impl.h"
#include "sql/engine/ob_physical_plan.h"
namespace oceanbase {
namespace oceanbase
{
using namespace common;
namespace sql {
namespace sql
{
OB_SERIALIZE_MEMBER(ObKillSessionArg, sess_id_, tenant_id_, user_id_, is_query_, has_user_super_privilege_);
OB_SERIALIZE_MEMBER(ObKillSessionArg,
sess_id_,
tenant_id_,
user_id_,
is_query_,
has_user_super_privilege_);
int ObKillSessionArg::init(ObExecContext& ctx, const ObKillStmt& stmt)
int ObKillSessionArg::init(ObExecContext &ctx, const ObKillStmt &stmt)
{
int ret = OB_SUCCESS;
ObSQLSessionInfo* session = NULL;
ObSQLSessionInfo *session = NULL;
if (OB_ISNULL(session = ctx.get_my_session())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("session is NULL", K(ret), K(ctx));
@ -41,67 +48,68 @@ int ObKillSessionArg::init(ObExecContext& ctx, const ObKillStmt& stmt)
return ret;
}
int ObKillSessionArg::calculate_sessid(ObExecContext& ctx, const ObKillStmt& stmt)
int ObKillSessionArg::calculate_sessid(ObExecContext &ctx, const ObKillStmt &stmt)
{
int ret = OB_SUCCESS;
ObSQLSessionInfo* my_session = ctx.get_my_session();
ObPhysicalPlanCtx* plan_ctx = ctx.get_physical_plan_ctx();
ObPhysicalPlan phy_plan;
ObPhysicalPlanCtx phy_plan_ctx(ctx.get_allocator());
ObExecContext* exec_ctx = NULL; // because ObExecContext is bigger than 10K, can't use it as local variable
ObExprCtx expr_ctx;
ObNewRow tmp_row;
RowDesc row_desc;
ObExprGeneratorImpl expr_gen(0, 0, NULL, row_desc);
ObObj value_obj;
ObRawExpr* value_expr = NULL;
void* tmp_ptr = NULL;
if (OB_ISNULL(my_session) || OB_ISNULL(plan_ctx)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("data member from ObExecContext is Null", K(ret), K(my_session), K(plan_ctx));
} else {
ObArenaAllocator allocator(
common::ObModIds::OB_SQL_EXPR_CALC, OB_MALLOC_NORMAL_BLOCK_SIZE, my_session->get_effective_tenant_id());
ObSqlExpression sql_expr(allocator, 0);
const int64_t cur_time =
plan_ctx->has_cur_time() ? plan_ctx->get_cur_time().get_timestamp() : ObTimeUtility::current_time();
phy_plan_ctx.set_cur_time(cur_time, *my_session);
if (OB_UNLIKELY(NULL == (tmp_ptr = allocator.alloc(sizeof(ObExecContext))))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("fail to alloc ObExecContext", K(ret));
ObSQLSessionInfo *my_session = ctx.get_my_session();
ObPhysicalPlanCtx *plan_ctx = ctx.get_physical_plan_ctx();
HEAP_VAR(ObPhysicalPlan, phy_plan) {
ObPhysicalPlanCtx phy_plan_ctx(ctx.get_allocator());
ObExecContext *exec_ctx = NULL;//because ObExecContext is bigger than 10K, can't use it as local variable
ObExprCtx expr_ctx;
ObNewRow tmp_row;
RowDesc row_desc;
ObObj value_obj;
ObRawExpr *value_expr = NULL;
void *tmp_ptr = NULL;
if (OB_FAIL(ret)) {
} else if (OB_ISNULL(my_session) || OB_ISNULL(plan_ctx)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("data member from ObExecContext is Null", K(ret), K(my_session), K(plan_ctx));
} else {
exec_ctx = new (tmp_ptr) ObExecContext;
phy_plan_ctx.set_phy_plan(&phy_plan);
expr_ctx.phy_plan_ctx_ = &phy_plan_ctx;
expr_ctx.my_session_ = my_session;
expr_ctx.exec_ctx_ = exec_ctx;
expr_ctx.calc_buf_ = &allocator;
if (OB_ISNULL(value_expr = stmt.get_value_expr())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to get value expr", K(ret), K(value_expr));
} else if (OB_FAIL(expr_gen.generate(*value_expr, sql_expr))) {
LOG_WARN("fail to fill sql expression", K(ret));
} else if (FALSE_IT(phy_plan.set_regexp_op_count(expr_gen.get_cur_regexp_op_count()))) {
// will not reach here
} else if (FALSE_IT(phy_plan.set_like_op_count(expr_gen.get_cur_like_op_count()))) {
// will not reach here
} else if (OB_FAIL(sql_expr.calc(expr_ctx, tmp_row, value_obj))) {
LOG_WARN("fail to calc value", K(ret), K(stmt.get_value_expr()));
ObArenaAllocator allocator(common::ObModIds::OB_SQL_EXPR_CALC,
OB_MALLOC_NORMAL_BLOCK_SIZE,
my_session->get_effective_tenant_id());
ObSqlExpression sql_expr(allocator, 0);
const int64_t cur_time = plan_ctx->has_cur_time() ?
plan_ctx->get_cur_time().get_timestamp() : ObTimeUtility::current_time();
phy_plan_ctx.set_cur_time(cur_time, *my_session);
if (OB_UNLIKELY(NULL == (tmp_ptr = allocator.alloc(sizeof(ObExecContext))))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("fail to alloc ObExecContext", K(ret));
} else {
const ObObj* res_obj = NULL;
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_WARN_ON_FAIL);
EXPR_CAST_OBJ_V2(ObUInt32Type, value_obj, res_obj);
ret = OB_ERR_TRUNCATED_WRONG_VALUE_FOR_FIELD == ret ? OB_SUCCESS : ret;
if (OB_FAIL(ret)) {
LOG_WARN(
"fail to cast expr", "orig type", value_obj.get_type(), "dest type", "ObUint32type", K(ret), K(res_obj));
} else if (OB_ISNULL(res_obj)) {
exec_ctx = new (tmp_ptr) ObExecContext(allocator);
phy_plan_ctx.set_phy_plan(&phy_plan);
expr_ctx.phy_plan_ctx_ = &phy_plan_ctx;
expr_ctx.my_session_ = my_session;
expr_ctx.exec_ctx_ = exec_ctx;
expr_ctx.calc_buf_ = &allocator;
ObTempExpr *temp_expr = NULL;
if (OB_ISNULL(value_expr = stmt.get_value_expr())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN(
"fail to cast expr", "orig type", value_obj.get_type(), "dest type", "ObUint32type", K(ret), K(res_obj));
LOG_WARN("fail to get value expr", K(ret), K(value_expr));
} else if (OB_FAIL(ObStaticEngineExprCG::gen_expr_with_row_desc(value_expr,
row_desc, ctx.get_allocator(), ctx.get_my_session(), temp_expr))) {
LOG_WARN("fail to fill sql expression", K(ret));
} else if (OB_ISNULL(temp_expr)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("fail to gen temp expr", K(ret));
} else if (OB_FAIL(temp_expr->eval(ctx, tmp_row, value_obj))) {
LOG_WARN("fail to calc value", K(ret), K(stmt.get_value_expr()));
} else {
sess_id_ = res_obj->get_uint32();
const ObObj *res_obj = NULL;
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_WARN_ON_FAIL);
EXPR_CAST_OBJ_V2(ObUInt32Type, value_obj, res_obj);
ret = OB_ERR_TRUNCATED_WRONG_VALUE_FOR_FIELD == ret ? OB_SUCCESS : ret;
if (OB_FAIL(ret)) {
LOG_WARN("fail to cast expr", "orig type", value_obj.get_type(), "dest type", "ObUint32type", K(ret), K(res_obj));
} else if (OB_ISNULL(res_obj)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("fail to cast expr", "orig type", value_obj.get_type(), "dest type", "ObUint32type", K(ret), K(res_obj));
} else {
sess_id_ = res_obj->get_uint32();
}
}
}
}
@ -109,5 +117,5 @@ int ObKillSessionArg::calculate_sessid(ObExecContext& ctx, const ObKillStmt& stm
return ret;
}
} // namespace sql
} // namespace oceanbase
}
}