From ceb8929d50491eca66de52f15efc37dd5110dd0c Mon Sep 17 00:00:00 2001 From: obdev Date: Fri, 20 Sep 2024 05:44:34 +0000 Subject: [PATCH] Prohibit memory comparison of text type data in the 'in' expression. --- deps/oblib/src/common/object/ob_obj_type.h | 4 ++++ src/sql/engine/expr/ob_expr_in.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/deps/oblib/src/common/object/ob_obj_type.h b/deps/oblib/src/common/object/ob_obj_type.h index ede7a464e..e06433aa0 100644 --- a/deps/oblib/src/common/object/ob_obj_type.h +++ b/deps/oblib/src/common/object/ob_obj_type.h @@ -1543,6 +1543,10 @@ inline bool ob_is_character_type(ObObjType type, ObCollationType cs_type) return ob_is_nstring(type) || ob_is_varchar_or_char(type, cs_type); } inline bool ob_is_string_type(ObObjType type) { return ob_is_string_tc(type) || ob_is_text_tc(type); } +inline bool ob_is_support_cmp_mem_str_type(ObObjType type, ObCollationType cs_type) +{ + return (ob_is_string_tc(type) || type == ObTinyTextType) && cs_type == CS_TYPE_UTF8MB4_BIN; +} inline bool ob_is_json(const ObObjType type) { return ObJsonType == type; } inline bool ob_is_blob_locator(const ObObjType type, const ObCollationType cs_type) { return ObLobType == type && CS_TYPE_BINARY == cs_type; } inline bool ob_is_clob_locator(const ObObjType type, const ObCollationType cs_type) { return ObLobType == type && CS_TYPE_BINARY != cs_type; } diff --git a/src/sql/engine/expr/ob_expr_in.cpp b/src/sql/engine/expr/ob_expr_in.cpp index 9c71c45dc..063ef5b1b 100644 --- a/src/sql/engine/expr/ob_expr_in.cpp +++ b/src/sql/engine/expr/ob_expr_in.cpp @@ -936,8 +936,8 @@ int ObExprInOrNotIn::eval_batch_in_without_row_fallback(const ObExpr &expr, * both dont have tailing space * right params count is 2(> 2 will turn to hash calc) */ - bool can_cmp_mem = expr.args_[0]->obj_meta_.is_string_type() - && CS_TYPE_UTF8MB4_BIN == expr.args_[0]->obj_meta_.get_collation_type(); + bool can_cmp_mem = ob_is_support_cmp_mem_str_type(expr.args_[0]->obj_meta_.get_type(), + expr.args_[0]->obj_meta_.get_collation_type()); //eval all right params for (int64_t j = 0; OB_SUCC(ret) && j < expr.inner_func_cnt_; ++j) { if (OB_FAIL(expr.args_[1]->args_[j]->eval(ctx, right_store[j]))) { @@ -1115,8 +1115,8 @@ int ObExprInOrNotIn::inner_eval_vector_in_without_row_fallback(const ObExpr &exp * both dont have tailing space * right params count is 2(> 2 will turn to hash calc) */ - bool can_cmp_mem = expr.args_[0]->obj_meta_.is_string_type() - && CS_TYPE_UTF8MB4_BIN == expr.args_[0]->obj_meta_.get_collation_type(); + bool can_cmp_mem = ob_is_support_cmp_mem_str_type(expr.args_[0]->obj_meta_.get_type(), + expr.args_[0]->obj_meta_.get_collation_type()); // eval all right params for (int64_t i = 0; OB_SUCC(ret) && i < expr.inner_func_cnt_; ++i) { // Because we know that in this scenario, @@ -2083,7 +2083,7 @@ void ObExprInOrNotIn::check_right_can_cmp_mem(const ObDatum &datum, bool &cnt_null) { static const char SPACE = ' '; - if (!meta.is_string_type() || CS_TYPE_UTF8MB4_BIN != meta.get_collation_type()) { + if (!ob_is_support_cmp_mem_str_type(meta.get_type(), meta.get_collation_type())) { cnt_null = cnt_null || datum.is_null(); can_cmp_mem = false; } else {