patch 4.0
This commit is contained in:
@ -18,47 +18,24 @@
|
||||
#include "sql/engine/expr/ob_expr_cmp_func.h"
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
|
||||
namespace oceanbase {
|
||||
using namespace common;
|
||||
namespace sql {
|
||||
|
||||
ObExprBetween::ObExprBetween(ObIAllocator& alloc) : ObRelationalExprOperator(alloc, T_OP_BTW, N_BTW, 3)
|
||||
{}
|
||||
|
||||
int ObExprBetween::calc_result3(
|
||||
ObObj& result, const ObObj& obj1, const ObObj& obj2, const ObObj& obj3, ObExprCtx& expr_ctx) const
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
namespace sql
|
||||
{
|
||||
|
||||
ObExprBetween::ObExprBetween(ObIAllocator &alloc)
|
||||
: ObRelationalExprOperator(alloc, T_OP_BTW, N_BTW, 3)
|
||||
{
|
||||
// 1 between null and 2 => NULL
|
||||
// 1 between null and 0 => 0
|
||||
// 1 between 2 and null => 0
|
||||
// 1 between 0 and null => NULL
|
||||
int ret = OB_SUCCESS;
|
||||
ObObj tmp_res;
|
||||
EXPR_DEFINE_CMP_CTX(result_type_.get_calc_meta(), false, expr_ctx);
|
||||
/*
|
||||
* no matter what the types of objs are,
|
||||
*
|
||||
* obj2 and obj1, obj1 and obj3 can be compared directly without any casts here.
|
||||
*/
|
||||
if (OB_FAIL(ObExprLessEqual::calc_nocast(tmp_res, obj2, obj1, cmp_ctx))) {
|
||||
LOG_WARN("failed to compare objects", K(ret), K(obj2), K(obj1));
|
||||
} else if (tmp_res.is_false()) {
|
||||
result.set_int32(static_cast<int32_t>(false));
|
||||
} else if (OB_FAIL(ObExprLessEqual::calc_nocast(result, obj1, obj3, cmp_ctx))) {
|
||||
LOG_WARN("failed to compare objects", K(ret), K(obj1), K(obj3));
|
||||
} else if (tmp_res.is_null() && result.is_true()) {
|
||||
result.set_null();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int calc_between_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
|
||||
int calc_between_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum)
|
||||
{
|
||||
// left <= val <= right
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum* val = NULL;
|
||||
ObDatum* left = NULL;
|
||||
ObDatum* right = NULL;
|
||||
ObDatum *val = NULL;
|
||||
ObDatum *left = NULL;
|
||||
ObDatum *right = NULL;
|
||||
if (OB_FAIL(expr.args_[0]->eval(ctx, val))) {
|
||||
LOG_WARN("eval arg 0 failed", K(ret));
|
||||
} else if (val->is_null()) {
|
||||
@ -70,13 +47,17 @@ int calc_between_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
|
||||
} else if (left->is_null() && right->is_null()) {
|
||||
res_datum.set_null();
|
||||
} else {
|
||||
bool left_cmp_succ = true; // is left <= val true or not
|
||||
bool right_cmp_succ = true; // is val <= right true or not
|
||||
bool left_cmp_succ = true; // is left <= val true or not
|
||||
bool right_cmp_succ = true; // is val <= right true or not
|
||||
if (!left->is_null()) {
|
||||
left_cmp_succ = (reinterpret_cast<DatumCmpFunc>(expr.inner_functions_[0]))(*left, *val) <= 0 ? true : false;
|
||||
left_cmp_succ =
|
||||
(reinterpret_cast<DatumCmpFunc>(expr.inner_functions_[0]))(*left, *val) <= 0 ?
|
||||
true : false;
|
||||
}
|
||||
if (left->is_null() || (left_cmp_succ && !right->is_null())) {
|
||||
right_cmp_succ = (reinterpret_cast<DatumCmpFunc>(expr.inner_functions_[1]))(*val, *right) <= 0 ? true : false;
|
||||
right_cmp_succ =
|
||||
(reinterpret_cast<DatumCmpFunc>(expr.inner_functions_[1]))(*val, *right) <= 0 ?
|
||||
true : false;
|
||||
}
|
||||
if ((left->is_null() && right_cmp_succ) || (right->is_null() && left_cmp_succ)) {
|
||||
res_datum.set_null();
|
||||
@ -89,37 +70,42 @@ int calc_between_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprBetween::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprBetween::cg_expr(ObExprCGCtx &expr_cg_ctx,
|
||||
const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
// left <= val <= right
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(3 != rt_expr.arg_cnt_) || OB_ISNULL(rt_expr.args_) || OB_ISNULL(rt_expr.args_[0]) ||
|
||||
OB_ISNULL(rt_expr.args_[1]) || OB_ISNULL(rt_expr.args_[2]) || OB_ISNULL(expr_cg_ctx.allocator_)) {
|
||||
if (OB_UNLIKELY(3 != rt_expr.arg_cnt_) || OB_ISNULL(rt_expr.args_) ||
|
||||
OB_ISNULL(rt_expr.args_[0]) || OB_ISNULL(rt_expr.args_[1]) ||
|
||||
OB_ISNULL(rt_expr.args_[2]) || OB_ISNULL(expr_cg_ctx.allocator_)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("rt_expr is invalid",
|
||||
K(ret),
|
||||
K(rt_expr.arg_cnt_),
|
||||
KP(rt_expr.args_),
|
||||
KP(rt_expr.args_[0]),
|
||||
KP(rt_expr.args_[1]),
|
||||
KP(rt_expr.args_[2]));
|
||||
LOG_WARN("rt_expr is invalid", K(ret), K(rt_expr.arg_cnt_), KP(rt_expr.args_),
|
||||
KP(rt_expr.args_[0]), KP(rt_expr.args_[1]), KP(rt_expr.args_[2]));
|
||||
} else {
|
||||
DatumCmpFunc cmp_func_1 = NULL; // left <= val
|
||||
DatumCmpFunc cmp_func_2 = NULL; // val <= right
|
||||
const ObDatumMeta& val_meta = rt_expr.args_[0]->datum_meta_;
|
||||
const ObDatumMeta& left_meta = rt_expr.args_[1]->datum_meta_;
|
||||
const ObDatumMeta& right_meta = rt_expr.args_[2]->datum_meta_;
|
||||
const ObCollationType cmp_cs_type = raw_expr.get_result_type().get_calc_collation_type();
|
||||
const ObDatumMeta &val_meta = rt_expr.args_[0]->datum_meta_;
|
||||
const ObDatumMeta &left_meta = rt_expr.args_[1]->datum_meta_;
|
||||
const ObDatumMeta &right_meta = rt_expr.args_[2]->datum_meta_;
|
||||
const ObCollationType cmp_cs_type =
|
||||
raw_expr.get_result_type().get_calc_collation_type();
|
||||
if (OB_ISNULL(cmp_func_1 = ObExprCmpFuncsHelper::get_datum_expr_cmp_func(
|
||||
left_meta.type_, val_meta.type_, is_oracle_mode(), cmp_cs_type))) {
|
||||
left_meta.type_, val_meta.type_,
|
||||
is_oracle_mode(),
|
||||
cmp_cs_type))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get_datum_expr_cmp_func failed", K(ret), K(left_meta), K(val_meta), K(is_oracle_mode()), K(rt_expr));
|
||||
LOG_WARN("get_datum_expr_cmp_func failed", K(ret), K(left_meta), K(val_meta),
|
||||
K(is_oracle_mode()), K(rt_expr));
|
||||
} else if (OB_ISNULL(cmp_func_2 = ObExprCmpFuncsHelper::get_datum_expr_cmp_func(
|
||||
val_meta.type_, right_meta.type_, is_oracle_mode(), cmp_cs_type))) {
|
||||
val_meta.type_, right_meta.type_,
|
||||
is_oracle_mode(),
|
||||
cmp_cs_type))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get_datum_expr_cmp_func failed", K(ret), K(val_meta), K(right_meta), K(is_oracle_mode()), K(rt_expr));
|
||||
} else if (OB_ISNULL(rt_expr.inner_functions_ =
|
||||
reinterpret_cast<void**>(expr_cg_ctx.allocator_->alloc(sizeof(DatumCmpFunc) * 2)))) {
|
||||
LOG_WARN("get_datum_expr_cmp_func failed", K(ret), K(val_meta), K(right_meta),
|
||||
K(is_oracle_mode()), K(rt_expr));
|
||||
} else if (OB_ISNULL(rt_expr.inner_functions_ = reinterpret_cast<void**>(
|
||||
expr_cg_ctx.allocator_->alloc(sizeof(DatumCmpFunc) * 2)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("alloc memory for inner_functions_ failed", K(ret));
|
||||
} else {
|
||||
@ -132,5 +118,5 @@ int ObExprBetween::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr,
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user