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,18 +17,19 @@
#include "sql/engine/expr/ob_expr_equal.h"
#include "sql/session/ob_sql_session_info.h"
namespace oceanbase {
namespace oceanbase
{
using namespace oceanbase::common;
namespace sql {
namespace sql
{
ObExprField::ObExprField(ObIAllocator& alloc)
: ObVectorExprOperator(alloc, T_FUN_SYS_FIELD, N_FIELD, MORE_THAN_ONE, NOT_ROW_DIMENSION), need_cast_(true)
{}
ObExprField::ObExprField(ObIAllocator &alloc) : ObVectorExprOperator(alloc, T_FUN_SYS_FIELD, N_FIELD, MORE_THAN_ONE,
NOT_ROW_DIMENSION), need_cast_(true) {}
int ObExprField::assign(const ObExprOperator& other)
int ObExprField::assign(const ObExprOperator &other)
{
int ret = OB_SUCCESS;
const ObExprField* tmp_other = dynamic_cast<const ObExprField*>(&other);
const ObExprField *tmp_other = dynamic_cast<const ObExprField *>(&other);
if (OB_UNLIKELY(NULL == tmp_other)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument. wrong type for other", K(ret), K(other));
@ -42,8 +43,10 @@ int ObExprField::assign(const ObExprOperator& other)
return ret;
}
int ObExprField::calc_result_typeN(
ObExprResType& type, ObExprResType* types_stack, int64_t param_num, ObExprTypeCtx& type_ctx) const
int ObExprField::calc_result_typeN(ObExprResType &type,
ObExprResType *types_stack,
int64_t param_num,
ObExprTypeCtx &type_ctx) const
{
int ret = OB_SUCCESS;
bool has_num = false;
@ -62,8 +65,8 @@ int ObExprField::calc_result_typeN(
// nothing to do
} else if (ObFloatTC == type_class || ObDoubleTC == type_class) {
has_real = true;
} else if (type_class >= ObDateTimeTC && type_class < ObMaxTC && type_class != ObYearTC &&
ObEnumSetInnerTC != type_class) {
} else if (type_class >= ObDateTimeTC && type_class < ObMaxTC && type_class != ObYearTC
&& ObEnumSetInnerTC != type_class) {
has_string = true;
} else if ((type_class < ObDateTimeTC && type_class > ObNullTC) || type_class == ObYearTC) {
has_num = true;
@ -92,14 +95,14 @@ int ObExprField::calc_result_typeN(
}
type.set_int();
// mysql precision is also 3
//调研mysql precision3
type.set_precision(3);
// calc comparison collation,etc
//calc comparison collation,etc
type.set_scale(DEFAULT_SCALE_FOR_INTEGER);
if (ob_is_string_type(type.get_calc_type())) {
ret = aggregate_charsets_for_comparison(type, types_stack, param_num, type_ctx.get_coll_type());
}
if (OB_SUCC(ret) && type_ctx.get_session()->use_static_typing_engine()) {
if (OB_SUCC(ret)) {
for (int64_t i = 0; OB_SUCC(ret) && i < param_num; ++i) {
types_stack[i].set_calc_meta(type.get_calc_meta());
}
@ -109,84 +112,10 @@ int ObExprField::calc_result_typeN(
return ret;
}
int ObExprField::calc_without_cast(ObObj& result, const ObObj* obj_stack, int64_t param_num, ObExprCtx& expr_ctx) const
int ObExprField::deserialize(const char *buf, const int64_t data_len, int64_t &pos)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(obj_stack) || OB_UNLIKELY(param_num <= 1)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(ret), K(obj_stack), K(param_num));
} else if (!obj_stack[0].is_null()) {
EXPR_DEFINE_CMP_CTX(result_type_.get_calc_meta(), true, expr_ctx);
ObObj cmp;
bool need_cast = false;
for (int64_t i = 1; OB_SUCC(ret) && i < param_num; ++i) {
if (OB_FAIL(
ObRelationalExprOperator::compare_nocast(cmp, obj_stack[0], obj_stack[i], cmp_ctx, CO_EQ, need_cast))) {
LOG_WARN("failed to compare objects", K(ret), K(obj_stack[0]), K(obj_stack[i]));
} else if (OB_UNLIKELY(need_cast)) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("unexpected error. cast should not be necessary",
K(ret),
K(obj_stack[0]),
K(obj_stack[i]),
K(cmp_ctx.cmp_cs_type_),
K(cmp_ctx.cmp_type_));
} else if (cmp.is_true()) {
result.set_int(i);
break;
}
}
}
return ret;
}
int ObExprField::calc_with_cast(ObObj& result, const ObObj* obj_stack, int64_t param_num, ObExprCtx& expr_ctx) const
{
int ret = OB_SUCCESS;
if (OB_ISNULL(obj_stack) || OB_UNLIKELY(param_num <= 1)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(ret), K(obj_stack), K(param_num));
} else if (!obj_stack[0].is_null()) {
EXPR_DEFINE_CMP_CTX(result_type_.get_calc_meta(), true, expr_ctx);
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_NONE);
ObObj cmp;
ObObj buf_obj0;
const ObObj* res_obj0 = NULL;
if (OB_FAIL(ObObjCaster::to_type(cmp_ctx.cmp_type_, cast_ctx, obj_stack[0], buf_obj0, res_obj0))) {
LOG_WARN("failed to cast obj", K(ret), "obj_type", cmp_ctx.cmp_type_, "obj", obj_stack[0]);
} else if (NULL == res_obj0) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to cast obj", K(ret), K_(cmp_ctx.cmp_type), K(obj_stack[0]));
}
for (int64_t i = 1; OB_SUCC(ret) && i < param_num; ++i) {
if (OB_FAIL(ObExprEqual::calc_cast(cmp, *res_obj0, obj_stack[i], cmp_ctx, cast_ctx))) {
LOG_WARN("failed to compare objects", K(ret), K(*res_obj0), K(obj_stack[i]));
} else if (cmp.is_true()) {
result.set_int(i);
break;
}
}
}
return ret;
}
int ObExprField::calc_resultN(
common::ObObj& result, const common::ObObj* obj_stack, int64_t param_num, ObExprCtx& expr_ctx) const
{
int ret = OB_SUCCESS;
result.set_int(0); // field(null,1,2,3) returns 0 not null
if (OB_UNLIKELY(need_cast_)) {
ret = calc_with_cast(result, obj_stack, param_num, expr_ctx);
} else {
ret = calc_without_cast(result, obj_stack, param_num, expr_ctx);
}
return ret;
}
int ObExprField::deserialize(const char* buf, const int64_t data_len, int64_t& pos)
{
int ret = OB_SUCCESS;
need_cast_ = true; // defensive code
need_cast_ = true;//defensive code
if (OB_FAIL(ObVectorExprOperator::deserialize(buf, data_len, pos))) {
LOG_WARN("deserialize in BASE class failed", K(ret));
} else {
@ -195,7 +124,7 @@ int ObExprField::deserialize(const char* buf, const int64_t data_len, int64_t& p
return ret;
}
int ObExprField::serialize(char* buf, const int64_t buf_len, int64_t& pos) const
int ObExprField::serialize(char *buf, const int64_t buf_len, int64_t &pos) const
{
int ret = OB_SUCCESS;
if (OB_FAIL(ObVectorExprOperator::serialize(buf, buf_len, pos))) {
@ -214,7 +143,7 @@ int64_t ObExprField::get_serialize_size() const
return len;
}
int ObExprField::cg_expr(ObExprCGCtx&, const ObRawExpr&, ObExpr& expr) const
int ObExprField::cg_expr(ObExprCGCtx &, const ObRawExpr &, ObExpr &expr) const
{
int ret = OB_SUCCESS;
CK(expr.arg_cnt_ > 1);
@ -222,10 +151,10 @@ int ObExprField::cg_expr(ObExprCGCtx&, const ObRawExpr&, ObExpr& expr) const
return ret;
}
int ObExprField::eval_field(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
int ObExprField::eval_field(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{
int ret = OB_SUCCESS;
ObDatum* first = NULL;
ObDatum *first = NULL;
if (OB_FAIL(expr.args_[0]->eval(ctx, first))) {
LOG_WARN("evaluate parameter failed", K(ret));
} else {
@ -233,7 +162,7 @@ int ObExprField::eval_field(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_da
// 0 == field(NULL, ...);
if (!first->is_null()) {
for (int64_t pos = 1; OB_SUCC(ret) && pos < expr.arg_cnt_; pos++) {
ObDatum* d = NULL;
ObDatum *d = NULL;
if (OB_FAIL(expr.args_[pos]->eval(ctx, d))) {
LOG_WARN("evaluate parameter failed", K(ret));
} else if (0 == expr.args_[0]->basic_funcs_->null_first_cmp_(*first, *d)) {
@ -246,5 +175,5 @@ int ObExprField::eval_field(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_da
return ret;
}
} // namespace sql
} // namespace oceanbase
} // namespace sql
} // namespace oceanbase