patch 4.0
This commit is contained in:
@ -19,76 +19,80 @@
|
||||
using namespace oceanbase::sql;
|
||||
using namespace oceanbase::common;
|
||||
|
||||
namespace oceanbase {
|
||||
namespace sql {
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
|
||||
ObExprNullSafeEqual::ObExprNullSafeEqual(ObIAllocator& alloc)
|
||||
ObExprNullSafeEqual::ObExprNullSafeEqual(ObIAllocator &alloc)
|
||||
: ObRelationalExprOperator(alloc, T_OP_NSEQ, N_NS_EQUAL, 2)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprNullSafeEqual::calc_result_type2(
|
||||
ObExprResType& type, ObExprResType& type1, ObExprResType& type2, ObExprTypeCtx& type_ctx) const
|
||||
int ObExprNullSafeEqual::calc_result_type2(ObExprResType &type,
|
||||
ObExprResType &type1,
|
||||
ObExprResType &type2,
|
||||
ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(ObRelationalExprOperator::calc_result_type2(type, type1, type2, type_ctx))) {
|
||||
LOG_WARN("failed to calc_result_type2", K(ret));
|
||||
}
|
||||
// always allow NULL value
|
||||
type.set_result_flag(OB_MYSQL_NOT_NULL_FLAG);
|
||||
type.set_result_flag(NOT_NULL_FLAG);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNullSafeEqual::calc_result_typeN(
|
||||
ObExprResType& type, ObExprResType* types, int64_t param_num, ObExprTypeCtx& type_ctx) const
|
||||
int ObExprNullSafeEqual::calc_result_typeN(ObExprResType &type,
|
||||
ObExprResType *types,
|
||||
int64_t param_num,
|
||||
ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(ObRelationalExprOperator::calc_result_typeN(type, types, param_num, type_ctx))) {
|
||||
LOG_WARN("failed to calc_result_typeN", K(ret));
|
||||
}
|
||||
// always allow NULL value
|
||||
type.set_result_flag(OB_MYSQL_NOT_NULL_FLAG);
|
||||
type.set_result_flag(NOT_NULL_FLAG);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNullSafeEqual::calc_result2(ObObj& result, const ObObj& obj1, const ObObj& obj2, ObExprCtx& expr_ctx) const
|
||||
{
|
||||
return ObRelationalExprOperator::calc_result2(result, obj1, obj2, expr_ctx, true, CO_EQ);
|
||||
}
|
||||
|
||||
int ObExprNullSafeEqual::calc_resultN(
|
||||
ObObj& result, const ObObj* objs_array, int64_t param_num, ObExprCtx& expr_ctx) const
|
||||
{
|
||||
return ObRelationalExprOperator::calc_resultN(result, objs_array, param_num, expr_ctx, true, CO_EQ);
|
||||
}
|
||||
|
||||
int ObExprNullSafeEqual::compare_row2(common::ObObj& result, const common::ObNewRow* left_row,
|
||||
const common::ObNewRow* right_row, common::ObExprCtx& expr_ctx)
|
||||
int ObExprNullSafeEqual::compare_row2(common::ObObj &result, const common::ObNewRow *left_row,
|
||||
const common::ObNewRow *right_row, common::ObExprCtx &expr_ctx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(left_row) || OB_ISNULL(right_row) || OB_UNLIKELY(left_row->is_invalid()) ||
|
||||
OB_UNLIKELY(right_row->is_invalid()) || OB_UNLIKELY(left_row->count_ != right_row->count_)) {
|
||||
if (OB_ISNULL(left_row)
|
||||
|| OB_ISNULL(right_row)
|
||||
|| OB_UNLIKELY(left_row->is_invalid())
|
||||
|| OB_UNLIKELY(right_row->is_invalid())
|
||||
|| OB_UNLIKELY(left_row->count_ != right_row->count_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid parameter", KPC(left_row), KPC(right_row), K(ret));
|
||||
} else {
|
||||
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_NONE);
|
||||
ObObj cmp_result;
|
||||
bool is_null_safe = true;
|
||||
ObCompareCtx cmp_ctx(ObMaxType, CS_TYPE_INVALID, is_null_safe, expr_ctx.tz_offset_, default_null_pos());
|
||||
ObCompareCtx cmp_ctx(ObMaxType,
|
||||
CS_TYPE_INVALID,
|
||||
is_null_safe,
|
||||
expr_ctx.tz_offset_,
|
||||
default_null_pos());
|
||||
result.set_int32(static_cast<int32_t>(true));
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < left_row->count_; ++i) {
|
||||
cmp_ctx.cmp_type_ = left_row->cells_[i].get_type();
|
||||
cmp_ctx.cmp_cs_type_ = left_row->cells_[i].get_collation_type();
|
||||
if (OB_FAIL(compare(cmp_result, left_row->cells_[i], right_row->cells_[i], cmp_ctx, cast_ctx, CO_EQ))) {
|
||||
LOG_WARN("fail to compare", KPC(left_row), KPC(right_row), K(ret));
|
||||
} else if (cmp_result.is_false() || cmp_result.is_null()) {
|
||||
} else if (cmp_result.is_false()
|
||||
|| cmp_result.is_null()) {
|
||||
result.set_int32(static_cast<int32_t>(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNullSafeEqual::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprNullSafeEqual::cg_expr(
|
||||
ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr, ObExpr &rt_expr) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int row_dim = 0;
|
||||
@ -96,21 +100,21 @@ int ObExprNullSafeEqual::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_
|
||||
CK(2 == rt_expr.arg_cnt_);
|
||||
OZ(is_row_cmp(raw_expr, row_dim));
|
||||
if (OB_SUCC(ret)) {
|
||||
if (row_dim <= 0) { // non row comparison
|
||||
void** funcs = static_cast<void**>(expr_cg_ctx.allocator_->alloc(sizeof(void*)));
|
||||
if (row_dim <= 0) { // non row comparison
|
||||
void **funcs = static_cast<void **>(expr_cg_ctx.allocator_->alloc(sizeof(void *)));
|
||||
if (OB_ISNULL(funcs)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("allocate memory failed", K(ret));
|
||||
} else {
|
||||
auto& l = rt_expr.args_[0]->datum_meta_;
|
||||
auto& r = rt_expr.args_[1]->datum_meta_;
|
||||
auto &l = rt_expr.args_[0]->datum_meta_;
|
||||
auto &r = rt_expr.args_[1]->datum_meta_;
|
||||
if (ObDatumFuncs::is_string_type(l.type_) && ObDatumFuncs::is_string_type(r.type_)) {
|
||||
CK(l.cs_type_ == r.cs_type_);
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
funcs[0] =
|
||||
(void*)ObExprCmpFuncsHelper::get_datum_expr_cmp_func(l.type_, r.type_, lib::is_oracle_mode(), l.cs_type_);
|
||||
funcs[0] = (void *)ObExprCmpFuncsHelper::get_datum_expr_cmp_func(
|
||||
l.type_, r.type_, lib::is_oracle_mode(), l.cs_type_);
|
||||
CK(NULL != funcs[0]);
|
||||
rt_expr.inner_functions_ = funcs;
|
||||
rt_expr.inner_func_cnt_ = 1;
|
||||
@ -128,18 +132,19 @@ int ObExprNullSafeEqual::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNullSafeEqual::ns_equal(
|
||||
const ObExpr& expr, ObDatum& res, ObExpr** left, ObEvalCtx& lctx, ObExpr** right, ObEvalCtx& rctx)
|
||||
int ObExprNullSafeEqual::ns_equal(const ObExpr &expr, ObDatum &res,
|
||||
ObExpr **left, ObEvalCtx &lctx, ObExpr **right, ObEvalCtx &rctx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum* l = NULL;
|
||||
ObDatum* r = NULL;
|
||||
ObDatum *l = NULL;
|
||||
ObDatum *r = NULL;
|
||||
bool equal = true;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && equal && i < expr.inner_func_cnt_; i++) {
|
||||
if (NULL == expr.inner_functions_[i]) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("NULL inner function", K(ret), K(i), K(expr));
|
||||
} else if (OB_FAIL(left[i]->eval(lctx, l)) || OB_FAIL(right[i]->eval(rctx, r))) {
|
||||
} else if (OB_FAIL(left[i]->eval(lctx, l))
|
||||
|| OB_FAIL(right[i]->eval(rctx, r))) {
|
||||
LOG_WARN("expr evaluate failed", K(ret));
|
||||
} else {
|
||||
if (l->is_null() && r->is_null()) {
|
||||
@ -157,7 +162,8 @@ int ObExprNullSafeEqual::ns_equal(
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNullSafeEqual::ns_equal_eval(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
|
||||
int ObExprNullSafeEqual::ns_equal_eval(
|
||||
const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
CK(NULL != expr.inner_functions_ && 1 == expr.inner_func_cnt_);
|
||||
@ -167,16 +173,19 @@ int ObExprNullSafeEqual::ns_equal_eval(const ObExpr& expr, ObEvalCtx& ctx, ObDat
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprNullSafeEqual::row_ns_equal_eval(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
|
||||
int ObExprNullSafeEqual::row_ns_equal_eval(
|
||||
const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
CK(NULL != expr.inner_functions_ && 2 == expr.arg_cnt_ && expr.args_[0]->arg_cnt_ == expr.inner_func_cnt_ &&
|
||||
expr.args_[1]->arg_cnt_ == expr.inner_func_cnt_);
|
||||
CK(NULL != expr.inner_functions_
|
||||
&& 2 == expr.arg_cnt_
|
||||
&& expr.args_[0]->arg_cnt_ == expr.inner_func_cnt_
|
||||
&& expr.args_[1]->arg_cnt_ == expr.inner_func_cnt_);
|
||||
if (OB_SUCC(ret)) {
|
||||
ret = ns_equal(expr, expr_datum, expr.args_[0]->args_, ctx, expr.args_[1]->args_, ctx);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
}//end of ns sql
|
||||
}//end of ns oceanbase
|
||||
|
||||
Reference in New Issue
Block a user