Optimize compile time

This commit is contained in:
stdliu 2024-10-25 09:51:36 +00:00 committed by ob-robot
parent 7148f27a0e
commit 6731c49670
15 changed files with 674 additions and 179 deletions

View File

@ -242,6 +242,7 @@ ob_set_subtarget(ob_share common_mixed
client_feedback/ob_feedback_int_struct.cpp
client_feedback/ob_feedback_partition_struct.cpp
datum/ob_datum.cpp
datum/ob_datum_cmp_func_def.cpp
diagnosis/ob_sql_monitor_statname.cpp
diagnosis/ob_sql_plan_monitor_node_list.cpp
interrupt/ob_global_interrupt_call.cpp
@ -664,4 +665,4 @@ add_library(ob_share_static
EXCLUDE_FROM_ALL)
target_link_libraries(ob_share_static
PUBLIC ob_share)
PUBLIC ob_share)

View File

@ -0,0 +1,182 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SHARE
#include "ob_datum_cmp_func_def.h"
#include "share/ob_lob_access_utils.h"
#include "share/rc/ob_tenant_base.h"
using namespace oceanbase;
using namespace oceanbase::common;
using namespace oceanbase::common::datum_cmp;
int ObDatumJsonCmpImpl::cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret, const bool is_lob)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
ObString l_data;
ObString r_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObJsonType, CS_TYPE_BINARY, l.get_string(), is_lob);
ObTextStringIter r_instr_iter(ObJsonType, CS_TYPE_BINARY, r.get_string(), is_lob);
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(l_instr_iter));
} else if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(r_instr_iter));
} else {
ObJsonBin j_bin_l(l_data.ptr(), l_data.length(), &allocator);
ObJsonBin j_bin_r(r_data.ptr(), r_data.length(), &allocator);
ObIJsonBase *j_base_l = &j_bin_l;
ObIJsonBase *j_base_r = &j_bin_r;
if (OB_FAIL(j_bin_l.reset_iter())) {
COMMON_LOG(WARN, "fail to reset left json bin iter", K(ret), K(l.len_));
} else if (OB_FAIL(j_bin_r.reset_iter())) {
COMMON_LOG(WARN, "fail to reset right json bin iter", K(ret), K(r.len_));
} else if (OB_FAIL(j_base_l->compare(*j_base_r, cmp_ret))) {
COMMON_LOG(WARN, "fail to compare json", K(ret), K(*j_base_l), K(*j_base_r));
}
}
return ret;
}
int ObDatumGeoCmpImpl::cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret, const bool is_lob)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
ObString l_data;
ObString r_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObGeometryType, CS_TYPE_BINARY, l.get_string(), is_lob);
ObTextStringIter r_instr_iter(ObGeometryType, CS_TYPE_BINARY, r.get_string(), is_lob);
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(l_instr_iter));
} else if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(r_instr_iter));
} else {
cmp_ret = ObCharset::strcmpsp(CS_TYPE_BINARY, l_data.ptr(), l_data.length(), r_data.ptr(), r_data.length(), false);
}
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return ret;
}
int ObDatumCollectionCmpImpl::cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret, const bool is_lob)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
ObString l_data;
ObString r_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObGeometryType, CS_TYPE_BINARY, l.get_string(), is_lob);
ObTextStringIter r_instr_iter(ObGeometryType, CS_TYPE_BINARY, r.get_string(), is_lob);
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(l_instr_iter));
} else if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(r_instr_iter));
} else {
// only memcmp supported now
cmp_ret = MEMCMP(l_data.ptr(), r_data.ptr(), std::min(l_data.length(), r_data.length()));
if (cmp_ret == 0 && l_data.length() != r_data.length()) {
cmp_ret = l_data.length() > r_data.length() ? 1 : -1;
}
}
return ret;
}
int ObDatumTextCmpImpl::cmp_out_row(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
ObString l_data;
ObString r_data;
const ObLobCommon& rlob = r.get_lob_data();
const ObLobCommon& llob = l.get_lob_data();
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObLongTextType, cs, l.get_string(), true); // longtext only indicates its a lob type
ObTextStringIter r_instr_iter(ObLongTextType, cs, r.get_string(), true);
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(cs), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(cs), K(l_instr_iter));
} else if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(cs), K(r_instr_iter));
} else {
cmp_ret = ObCharset::strcmpsp(
cs, l_data.ptr(), l_data.length(), r_data.ptr(), r_data.length(), with_end_space);
}
// if error occur when reading outrow lobs, the compare result is wrong.
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return ret;
}
int ObDatumTextStringCmpImpl::cmp_out_row(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
ObString l_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObLongTextType, cs, l.get_string(), true); // longtext only indicates its a lob type
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(cs), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(cs), K(l_instr_iter));
} else {
cmp_ret = ObCharset::strcmpsp(
cs, l_data.ptr(), l_data.length(), r.ptr_, r.len_, with_end_space);
}
// if error occur when reading outrow lobs, the compare result is wrong.
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return ret;
}
int ObDatumStringTextCmpImpl::cmp_out_row(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
const ObLobCommon& rlob = r.get_lob_data();
ObString r_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter r_instr_iter(ObLongTextType, cs, r.get_string(), true); // longtext only indicates its a lob type
if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(cs), K(r_instr_iter));
} else {
cmp_ret = ObCharset::strcmpsp(
cs, l.ptr_, l.len_, r_data.ptr(), r_data.length(), with_end_space);
}
// if error occur when reading outrow lobs, the compare result is wrong.
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return ret;
}

View File

@ -27,8 +27,7 @@
#include "lib/json_type/ob_json_base.h" // for ObIJsonBase
#include "lib/json_type/ob_json_bin.h" // for ObJsonBin
#include "lib/wide_integer/ob_wide_integer.h"
#include "share/ob_lob_access_utils.h" // for Text types
#include "share/rc/ob_tenant_base.h"
#include "share/ob_errno.h"
namespace oceanbase
{
@ -356,70 +355,31 @@ struct ObDatumTypeCmp<ObURowIDType, ObURowIDType> : public ObDefined<>
}
};
struct ObDatumJsonCmpImpl
{
static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret, const bool is_lob);
};
template <bool HAS_LOB_LOCATOR>
struct ObDatumJsonCmp : public ObDefined<>
{
inline static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
ObString l_data;
ObString r_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObJsonType, CS_TYPE_BINARY, l.get_string(), HAS_LOB_LOCATOR);
ObTextStringIter r_instr_iter(ObJsonType, CS_TYPE_BINARY, r.get_string(), HAS_LOB_LOCATOR);
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(l_instr_iter));
} else if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(r_instr_iter));
} else {
ObJsonBin j_bin_l(l_data.ptr(), l_data.length(), &allocator);
ObJsonBin j_bin_r(r_data.ptr(), r_data.length(), &allocator);
ObIJsonBase *j_base_l = &j_bin_l;
ObIJsonBase *j_base_r = &j_bin_r;
if (OB_FAIL(j_bin_l.reset_iter())) {
COMMON_LOG(WARN, "fail to reset left json bin iter", K(ret), K(l.len_));
} else if (OB_FAIL(j_bin_r.reset_iter())) {
COMMON_LOG(WARN, "fail to reset right json bin iter", K(ret), K(r.len_));
} else if (OB_FAIL(j_base_l->compare(*j_base_r, cmp_ret))) {
COMMON_LOG(WARN, "fail to compare json", K(ret), K(*j_base_l), K(*j_base_r));
}
}
return ret;
return ObDatumJsonCmpImpl::cmp(l, r, cmp_ret, HAS_LOB_LOCATOR);
}
};
struct ObDatumGeoCmpImpl
{
static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret, const bool is_lob);
};
template <bool HAS_LOB_HEADER>
struct ObDatumGeoCmp : public ObDefined<>
{
inline static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
ObString l_data;
ObString r_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObGeometryType, CS_TYPE_BINARY, l.get_string(), HAS_LOB_HEADER);
ObTextStringIter r_instr_iter(ObGeometryType, CS_TYPE_BINARY, r.get_string(), HAS_LOB_HEADER);
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(l_instr_iter));
} else if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(r_instr_iter));
} else {
cmp_ret = ObCharset::strcmpsp(CS_TYPE_BINARY, l_data.ptr(), l_data.length(), r_data.ptr(), r_data.length(), false);
}
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return ret;
return ObDatumGeoCmpImpl::cmp(l, r, cmp_ret, HAS_LOB_HEADER);
}
};
@ -435,34 +395,17 @@ struct ObDatumUDTCmp : public ObDefined<>
}
};
struct ObDatumCollectionCmpImpl
{
static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret, const bool is_lob);
};
template <bool HAS_LOB_HEADER>
struct ObDatumCollectionCmp : public ObDefined<>
{
inline static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
ObString l_data;
ObString r_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObGeometryType, CS_TYPE_BINARY, l.get_string(), HAS_LOB_HEADER);
ObTextStringIter r_instr_iter(ObGeometryType, CS_TYPE_BINARY, r.get_string(), HAS_LOB_HEADER);
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(l_instr_iter));
} else if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(r_instr_iter));
} else {
// only memcmp supported now
cmp_ret = MEMCMP(l_data.ptr(), r_data.ptr(), std::min(l_data.length(), r_data.length()));
if (cmp_ret == 0 && l_data.length() != r_data.length()) {
cmp_ret = l_data.length() > r_data.length() ? 1 : -1;
}
}
return ret;
return ObDatumCollectionCmpImpl::cmp(l, r, cmp_ret, HAS_LOB_HEADER);
}
};
@ -482,86 +425,113 @@ struct ObDatumCollectionCmp : public ObDefined<>
// }
//
struct ObDatumStrCmpImpl
{
static int OB_INLINE cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space)
{
cmp_ret = ObCharset::strcmpsp(cs, l.ptr_, l.len_, r.ptr_, r.len_, with_end_space);
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return OB_SUCCESS;
}
};
template <ObCollationType CS_TYPE, bool WITH_END_SPACE>
struct ObDatumStrCmp : public ObDefined<SupportedCollection<CS_TYPE>::defined_>
{
inline static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret)
{ // ToDo: @gehao need to handle ObDatum has_lob_header flags ?
cmp_ret = ObCharset::strcmpsp(
CS_TYPE, l.ptr_, l.len_, r.ptr_, r.len_, WITH_END_SPACE);
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return OB_SUCCESS;
{
return ObDatumStrCmpImpl::cmp(l, r, cmp_ret, CS_TYPE, WITH_END_SPACE);
}
};
struct ObDatumTextCmpImpl
{
static OB_INLINE int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space)
{
int ret = OB_SUCCESS;
const ObLobCommon& rlob = r.get_lob_data();
const ObLobCommon& llob = l.get_lob_data();
if (r.len_ != 0 && !rlob.is_mem_loc_ && rlob.in_row_ &&
l.len_ != 0 && !llob.is_mem_loc_ && llob.in_row_) {
cmp_ret = ObCharset::strcmpsp(
cs, llob.get_inrow_data_ptr(), static_cast<int32_t>(llob.get_byte_size(l.len_)),
rlob.get_inrow_data_ptr(), static_cast<int32_t>(rlob.get_byte_size(r.len_)), with_end_space);
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
} else {
ret = cmp_out_row(l, r, cmp_ret, cs, with_end_space);
}
return ret;
}
private:
static int cmp_out_row(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space);
};
template <ObCollationType CS_TYPE, bool WITH_END_SPACE>
struct ObDatumTextCmp : public ObDefined<SupportedCollection<CS_TYPE>::defined_>
{
inline static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret)
{
return ObDatumTextCmpImpl::cmp(l, r, cmp_ret, CS_TYPE, WITH_END_SPACE);
}
};
struct ObDatumTextStringCmpImpl
{
static OB_INLINE int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
ObString l_data;
ObString r_data;
const ObLobCommon& rlob = r.get_lob_data();
const ObLobCommon& llob = l.get_lob_data();
if (r.len_ != 0 && !rlob.is_mem_loc_ && rlob.in_row_ &&
l.len_ != 0 && !llob.is_mem_loc_ && llob.in_row_) {
cmp_ret = ObCharset::strcmpsp(CS_TYPE,
llob.get_inrow_data_ptr(), static_cast<int32_t>(llob.get_byte_size(l.len_)),
rlob.get_inrow_data_ptr(), static_cast<int32_t>(rlob.get_byte_size(r.len_)), WITH_END_SPACE);
if (l.len_ != 0 && !llob.is_mem_loc_ && llob.in_row_) {
cmp_ret = ObCharset::strcmpsp(
cs, llob.get_inrow_data_ptr(), static_cast<int32_t>(llob.get_byte_size(l.len_)),
r.ptr_, r.len_, with_end_space);
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
} else {
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObLongTextType, CS_TYPE, l.get_string(), true); // longtext only indicates its a lob type
ObTextStringIter r_instr_iter(ObLongTextType, CS_TYPE, r.get_string(), true);
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(CS_TYPE), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(CS_TYPE), K(l_instr_iter));
} else if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(CS_TYPE), K(r_instr_iter));
} else {
cmp_ret = ObCharset::strcmpsp(
CS_TYPE, l_data.ptr(), l_data.length(), r_data.ptr(), r_data.length(), WITH_END_SPACE);
}
ret = cmp_out_row(l, r, cmp_ret, cs, with_end_space);
}
// if error occur when reading outrow lobs, the compare result is wrong.
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return ret;
}
private:
static int cmp_out_row(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space);
};
template <ObCollationType CS_TYPE, bool WITH_END_SPACE>
struct ObDatumTextStringCmp : public ObDefined<SupportedCollection<CS_TYPE>::defined_>
{
inline static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret)
{
return ObDatumTextStringCmpImpl::cmp(l, r, cmp_ret, CS_TYPE, WITH_END_SPACE);
}
};
struct ObDatumStringTextCmpImpl
{
static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
const ObLobCommon& llob = l.get_lob_data();
if (l.len_ != 0 && !llob.is_mem_loc_ && llob.in_row_) {
cmp_ret = ObCharset::strcmpsp(CS_TYPE,
llob.get_inrow_data_ptr(), static_cast<int32_t>(llob.get_byte_size(l.len_)),
r.ptr_, r.len_, WITH_END_SPACE);
const ObLobCommon& rlob = r.get_lob_data();
if (r.len_ != 0 && !rlob.is_mem_loc_ && rlob.in_row_ && rlob.reserve_ == 0) {
cmp_ret = ObCharset::strcmpsp(
cs, l.ptr_, l.len_,
rlob.get_inrow_data_ptr(), static_cast<int32_t>(rlob.get_byte_size(r.len_)), with_end_space);
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
} else {
ObString l_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter l_instr_iter(ObLongTextType, CS_TYPE, l.get_string(), true); // longtext only indicates its a lob type
if (OB_FAIL(l_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init left lob str iter failed", K(ret), K(CS_TYPE), K(l));
} else if (OB_FAIL(l_instr_iter.get_full_data(l_data))) {
COMMON_LOG(WARN, "Lob: get left lob str iter full data failed ", K(ret), K(CS_TYPE), K(l_instr_iter));
} else {
cmp_ret = ObCharset::strcmpsp(
CS_TYPE, l_data.ptr(), l_data.length(), r.ptr_, r.len_, WITH_END_SPACE);
}
ret = cmp_out_row(l, r, cmp_ret, cs, with_end_space);
}
// if error occur when reading outrow lobs, the compare result is wrong.
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return ret;
}
private:
static int cmp_out_row(const ObDatum &l, const ObDatum &r, int &cmp_ret,
const ObCollationType cs, const bool with_end_space);
};
template <ObCollationType CS_TYPE, bool WITH_END_SPACE>
@ -569,29 +539,7 @@ struct ObDatumStringTextCmp : public ObDefined<SupportedCollection<CS_TYPE>::def
{
inline static int cmp(const ObDatum &l, const ObDatum &r, int &cmp_ret)
{
int ret = OB_SUCCESS;
cmp_ret = 0;
const ObLobCommon& rlob = r.get_lob_data();
if (r.len_ != 0 && !rlob.is_mem_loc_ && rlob.in_row_ && rlob.reserve_ == 0) {
cmp_ret = ObCharset::strcmpsp(CS_TYPE,
l.ptr_, l.len_,
rlob.get_inrow_data_ptr(), static_cast<int32_t>(rlob.get_byte_size(r.len_)), WITH_END_SPACE);
} else {
ObString r_data;
common::ObArenaAllocator allocator(ObModIds::OB_LOB_READER, OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObTextStringIter r_instr_iter(ObLongTextType, CS_TYPE, r.get_string(), true); // longtext only indicates its a lob type
if (OB_FAIL(r_instr_iter.init(0, NULL, &allocator))) {
COMMON_LOG(WARN, "Lob: init right lob str iter failed", K(ret), K(ret), K(r));
} else if (OB_FAIL(r_instr_iter.get_full_data(r_data))) {
COMMON_LOG(WARN, "Lob: get right lob str iter full data failed ", K(ret), K(CS_TYPE), K(r_instr_iter));
} else {
cmp_ret = ObCharset::strcmpsp(
CS_TYPE, l.ptr_, l.len_, r_data.ptr(), r_data.length(), WITH_END_SPACE);
}
}
// if error occur when reading outrow lobs, the compare result is wrong.
cmp_ret = cmp_ret > 0 ? 1 : (cmp_ret < 0 ? -1 : 0);
return ret;
return ObDatumStringTextCmpImpl::cmp(l, r, cmp_ret, CS_TYPE, WITH_END_SPACE);
}
};

View File

@ -13,6 +13,9 @@
#ifndef OCEANBASE_SHARE_DATUM_FUNCS_UTIL_H_
#define OCEANBASE_SHARE_DATUM_FUNCS_UTIL_H_
#include "share/ob_lob_access_utils.h"
#include "share/rc/ob_tenant_base.h"
namespace oceanbase
{
using namespace sql;
@ -438,6 +441,238 @@ struct DatumStrHashCalculator : public DefHashMethod<T>
}
};
template <bool IS_LOB>
struct DefStrHashFunc
{
static int null_hash(const uint64_t seed, uint64_t &res, hash_algo hash_al)
{
const int null_type = ObNullType;
res = hash_al(&null_type, sizeof(null_type), seed);
return OB_SUCCESS;
}
static int hash(const ObDatum &datum, const uint64_t seed, uint64_t &res,
const ObCollationType cs, const bool calc_end_space, const hash_algo hash_al)
{
int ret = OB_SUCCESS;
if (datum.is_null()) {
ret = null_hash(seed, res, hash_al);
} else {
if (IS_LOB) {
ret = datum_lob_locator_hash(datum, cs, seed, hash_al, res);
} else {
res = datum_varchar_hash(datum, cs, calc_end_space, seed, hash_al);
}
}
return ret;
}
static int hash_v2(const ObDatum &datum, const uint64_t seed, uint64_t &res,
const ObCollationType cs, const bool calc_end_space, const hash_algo hash_al)
{
int ret = OB_SUCCESS;
if (IS_LOB) {
ret = datum_lob_locator_hash(datum, cs, seed, hash_al, res);
} else {
if (datum.is_null()) {
res = seed;
} else {
res = datum_varchar_hash(datum, cs, calc_end_space, seed, hash_al);
}
}
return ret;
}
template <typename DATUM_VEC, typename SEED_VEC>
static void do_hash_batch(uint64_t *hash_values,
const DATUM_VEC &datum_vec,
const ObBitVector &skip,
const int64_t size,
const SEED_VEC &seed_vec,
const ObCollationType cs,
const bool calc_end_space,
const hash_algo hash_al)
{
ObBitVector::flip_foreach(skip, size,
[&](int64_t idx) __attribute__((always_inline)) {
int ret = OB_SUCCESS;
ret = hash(datum_vec[idx], seed_vec[idx], hash_values[idx], cs, calc_end_space, hash_al);
return ret;
}
);
}
static void hash_batch(uint64_t *hash_values,
ObDatum *datums,
const bool is_batch_datum,
const ObBitVector &skip,
const int64_t size,
const uint64_t *seeds,
const bool is_batch_seed,
const ObCollationType cs,
const bool calc_end_space,
const hash_algo hash_al)
{
if (is_batch_datum && !is_batch_seed) {
do_hash_batch(hash_values, VectorIter<const ObDatum, true>(datums), skip, size,
VectorIter<const uint64_t, false>(seeds), cs, calc_end_space, hash_al);
} else if (is_batch_datum && is_batch_seed) {
do_hash_batch(hash_values, VectorIter<const ObDatum, true>(datums), skip, size,
VectorIter<const uint64_t, true>(seeds), cs, calc_end_space, hash_al);
} else if (!is_batch_datum && is_batch_seed) {
do_hash_batch(hash_values, VectorIter<const ObDatum, false>(datums), skip, size,
VectorIter<const uint64_t, true>(seeds), cs, calc_end_space, hash_al);
} else {
do_hash_batch(hash_values, VectorIter<const ObDatum, false>(datums), skip, size,
VectorIter<const uint64_t, false>(seeds), cs, calc_end_space, hash_al);
}
}
template <typename DATUM_VEC, typename SEED_VEC>
static void do_hash_v2_batch(uint64_t *hash_values,
const DATUM_VEC &datum_vec,
const ObBitVector &skip,
const int64_t size,
const SEED_VEC &seed_vec,
const ObCollationType cs,
const bool calc_end_space,
const hash_algo hash_al)
{
ObBitVector::flip_foreach(skip, size,
[&](int64_t idx) __attribute__((always_inline)) {
int ret = OB_SUCCESS;
ret = hash_v2(datum_vec[idx], seed_vec[idx], hash_values[idx], cs, calc_end_space, hash_al);
return ret;
}
);
}
static void hash_v2_batch(uint64_t *hash_values,
ObDatum *datums,
const bool is_batch_datum,
const ObBitVector &skip,
const int64_t size,
const uint64_t *seeds,
const bool is_batch_seed,
const ObCollationType cs,
const bool calc_end_space,
const hash_algo hash_al)
{
if (is_batch_datum && !is_batch_seed) {
do_hash_v2_batch(hash_values, VectorIter<const ObDatum, true>(datums), skip, size,
VectorIter<const uint64_t, false>(seeds), cs, calc_end_space, hash_al);
} else if (is_batch_datum && is_batch_seed) {
do_hash_v2_batch(hash_values, VectorIter<const ObDatum, true>(datums), skip, size,
VectorIter<const uint64_t, true>(seeds), cs, calc_end_space, hash_al);
} else if (!is_batch_datum && is_batch_seed) {
do_hash_v2_batch(hash_values, VectorIter<const ObDatum, false>(datums), skip, size,
VectorIter<const uint64_t, true>(seeds), cs, calc_end_space, hash_al);
} else {
do_hash_v2_batch(hash_values, VectorIter<const ObDatum, false>(datums), skip, size,
VectorIter<const uint64_t, false>(seeds), cs, calc_end_space, hash_al);
}
}
};
struct ObStrHashBatchImpl {
static void OB_NOINLINE hash_batch(uint64_t *hash_values,
ObDatum *datums,
const bool is_batch_datum,
const ObBitVector &skip,
const int64_t size,
const uint64_t *seeds,
const bool is_batch_seed,
const ObCollationType cs,
const bool calc_end_space,
const hash_algo hash_al,
const bool is_lob)
{
return is_lob
? DefStrHashFunc<true>::hash_batch(hash_values, datums, is_batch_datum, skip, size, seeds,
is_batch_seed, cs, calc_end_space, hash_al)
: DefStrHashFunc<false>::hash_batch(hash_values, datums, is_batch_datum, skip, size, seeds,
is_batch_seed, cs, calc_end_space, hash_al);
}
static void OB_NOINLINE hash_v2_batch(uint64_t *hash_values,
ObDatum *datums,
const bool is_batch_datum,
const ObBitVector &skip,
const int64_t size,
const uint64_t *seeds,
const bool is_batch_seed,
const ObCollationType cs,
const bool calc_end_space,
const hash_algo hash_al,
const bool is_lob)
{
return is_lob
? DefStrHashFunc<true>::hash_v2_batch(hash_values, datums, is_batch_datum, skip, size,
seeds, is_batch_seed, cs, calc_end_space, hash_al)
: DefStrHashFunc<false>::hash_v2_batch(hash_values, datums, is_batch_datum, skip, size,
seeds, is_batch_seed, cs, calc_end_space, hash_al);
}
};
template <ObCollationType cs, bool calc_end_space, typename T, bool is_lob>
struct StrDatumHashBatchHelper {
static void hash_batch(uint64_t *hash_values,
ObDatum *datums,
const bool is_batch_datum,
const ObBitVector &skip,
const int64_t size,
const uint64_t *seeds,
const bool is_batch_seed)
{
return ObStrHashBatchImpl::hash_batch(hash_values, datums, is_batch_datum, skip, size,
seeds, is_batch_seed, cs, calc_end_space,
T::is_varchar_hash ? T::hash : NULL, is_lob);
}
static void hash_v2_batch(uint64_t *hash_values,
ObDatum *datums,
const bool is_batch_datum,
const ObBitVector &skip,
const int64_t size,
const uint64_t *seeds,
const bool is_batch_seed)
{
return ObStrHashBatchImpl::hash_v2_batch(hash_values, datums, is_batch_datum, skip, size,
seeds, is_batch_seed, cs, calc_end_space,
T::is_varchar_hash ? T::hash : NULL, is_lob);
}
};
//use DatumStrHashCalculator for CS_TYPE_UTF8MB4_BIN, because CS_TYPE_UTF8MB4_BIN is specializated.
template <bool calc_end_space, typename T, bool is_lob>
struct StrDatumHashBatchHelper<CS_TYPE_UTF8MB4_BIN, calc_end_space, T, is_lob> {
using HashBatch = DefHashFunc<
DatumStrHashCalculator<CS_TYPE_UTF8MB4_BIN, calc_end_space, T, is_lob>>;
static void hash_batch(uint64_t *hash_values,
ObDatum *datums,
const bool is_batch_datum,
const ObBitVector &skip,
const int64_t size,
const uint64_t *seeds,
const bool is_batch_seed)
{
return HashBatch::hash_batch(
hash_values, datums, is_batch_datum, skip, size, seeds, is_batch_seed);
}
static void hash_v2_batch(uint64_t *hash_values,
ObDatum *datums,
const bool is_batch_datum,
const ObBitVector &skip,
const int64_t size,
const uint64_t *seeds,
const bool is_batch_seed)
{
return HashBatch::hash_v2_batch(
hash_values, datums, is_batch_datum, skip, size, seeds, is_batch_seed);
}
};
template <ObCollationType cs_type, bool calc_end_space, typename T>
struct DatumStrHashCalculator<cs_type, calc_end_space, T, true /* is_lob_locator */>
: public DefHashMethod<T>
@ -696,6 +931,14 @@ struct InitBasicStrFuncArray<X, Y, true>
template <typename T, bool is_lob_locator>
using Hash = DefHashFunc<DatumStrHashCalculator<static_cast<ObCollationType>(X),
static_cast<bool>(Y), T, is_lob_locator>>;
/*
template <typename T, bool is_lob_locator>
using HashBatch = DefHashFunc<DatumStrHashCalculator<static_cast<ObCollationType>(X),
static_cast<bool>(Y), T, is_lob_locator>>;
*/
template <typename T, bool is_lob>
using HashBatch = StrDatumHashBatchHelper<static_cast<ObCollationType>(X), static_cast<bool>(Y), T, is_lob>;
template <bool null_first>
using StrCmp = ObNullSafeDatumStrCmp<static_cast<ObCollationType>(X),
static_cast<bool>(Y), null_first>;
@ -713,22 +956,22 @@ struct InitBasicStrFuncArray<X, Y, true>
if (datum_cmp::SupportedCollection<static_cast<ObCollationType>(X)>::defined_) {
auto &basic_funcs = EXPR_BASIC_STR_FUNCS;
basic_funcs[X][Y][0].default_hash_ = Hash<ObDefaultHash, false>::hash;
basic_funcs[X][Y][0].default_hash_batch_ = Hash<ObDefaultHash, false>::hash_batch;
basic_funcs[X][Y][0].default_hash_batch_ = HashBatch<ObDefaultHash, false>::hash_batch;
basic_funcs[X][Y][0].murmur_hash_ = Hash<ObMurmurHash, false>::hash;
basic_funcs[X][Y][0].murmur_hash_batch_ = Hash<ObMurmurHash, false>::hash_batch;
basic_funcs[X][Y][0].murmur_hash_batch_ = HashBatch<ObMurmurHash, false>::hash_batch;
basic_funcs[X][Y][0].xx_hash_ = Hash<ObXxHash, false>::hash;
basic_funcs[X][Y][0].xx_hash_batch_ = Hash<ObXxHash, false>::hash_batch;
basic_funcs[X][Y][0].xx_hash_batch_ = HashBatch<ObXxHash, false>::hash_batch;
basic_funcs[X][Y][0].wy_hash_ = Hash<ObWyHash, false>::hash;
basic_funcs[X][Y][0].wy_hash_batch_ = Hash<ObWyHash, false>::hash_batch;
basic_funcs[X][Y][0].wy_hash_batch_ = HashBatch<ObWyHash, false>::hash_batch;
basic_funcs[X][Y][0].null_first_cmp_ = Def::defined_ ? &StrCmp<1>::cmp : NULL;
basic_funcs[X][Y][0].null_last_cmp_ = Def::defined_ ? &StrCmp<0>::cmp : NULL;
basic_funcs[X][Y][0].murmur_hash_v2_ = Hash<ObMurmurHash, false>::hash_v2;
basic_funcs[X][Y][0].murmur_hash_v2_batch_ = Hash<ObMurmurHash, false>::hash_v2_batch;
basic_funcs[X][Y][0].murmur_hash_v2_batch_ = HashBatch<ObMurmurHash, false>::hash_v2_batch;
basic_funcs[X][Y][1].default_hash_ = Hash<ObDefaultHash, true>::hash;
basic_funcs[X][Y][1].default_hash_batch_ = Hash<ObDefaultHash, true>::hash_batch;
basic_funcs[X][Y][1].default_hash_batch_ = HashBatch<ObDefaultHash, true>::hash_batch;
basic_funcs[X][Y][1].murmur_hash_ = Hash<ObMurmurHash, true>::hash;
basic_funcs[X][Y][1].murmur_hash_batch_ = Hash<ObMurmurHash, true>::hash_batch;
basic_funcs[X][Y][1].murmur_hash_batch_ = HashBatch<ObMurmurHash, true>::hash_batch;
// basic_funcs[X][Y][1].xx_hash_ = Hash<ObXxHash, true>::hash;
// basic_funcs[X][Y][1].xx_hash_batch_ = Hash<ObXxHash, true>::hash_batch;
// basic_funcs[X][Y][1].wy_hash_ = Hash<ObWyHash, true>::hash;
@ -738,7 +981,7 @@ struct InitBasicStrFuncArray<X, Y, true>
basic_funcs[X][Y][1].null_first_cmp_ = DefText::defined_ ? &TextCmp<1>::cmp : NULL;
basic_funcs[X][Y][1].null_last_cmp_ = DefText::defined_ ? &TextCmp<0>::cmp : NULL;
basic_funcs[X][Y][1].murmur_hash_v2_ = Hash<ObMurmurHash, true>::hash_v2;
basic_funcs[X][Y][1].murmur_hash_v2_batch_ = Hash<ObMurmurHash, true>::hash_v2_batch;
basic_funcs[X][Y][1].murmur_hash_v2_batch_ = HashBatch<ObMurmurHash, true>::hash_v2_batch;
}
}
};
@ -1232,4 +1475,4 @@ struct InitDecintCmpArray
} // end common
} // end oceanbase
#endif // OCEANBASE_SHARE_DATUM_FUNCS_UTIL_H_
#endif // OCEANBASE_SHARE_DATUM_FUNCS_UTIL_H_

View File

@ -14,6 +14,9 @@
#define USING_LOG_PREFIX SQL_ENG
#include "sql/engine/expr/ob_array_expr_utils.h"
#include "sql/engine/expr/ob_expr_result_type_util.h"
#include "sql/session/ob_sql_session_info.h"
#include "sql/engine/ob_exec_context.h"
using namespace oceanbase::common;
namespace oceanbase

View File

@ -18,14 +18,13 @@
#include "lib/string/ob_string.h"
#include "lib/udt/ob_array_type.h"
#include "sql/engine/expr/ob_expr.h" // for ObExpr
#include "sql/session/ob_sql_session_info.h"
#include "sql/engine/ob_exec_context.h"
#include "sql/engine/expr/ob_expr_lob_utils.h"
namespace oceanbase
{
namespace sql
{
class ObExecContext;
struct ObVectorCastInfo
{
@ -139,4 +138,4 @@ public:
} // sql
} // oceanbase
#endif // OCEANBASE_SQL_OB_ARRAY_EXPR_UTILS_H_
#endif // OCEANBASE_SQL_OB_ARRAY_EXPR_UTILS_H_

View File

@ -18,7 +18,6 @@
#include "sql/engine/expr/ob_expr.h"
#include "share/vector/ob_uniform_base.h"
#include "share/vector/ob_discrete_base.h"
#include "ob_expr_add.h"
#include "sql/engine/expr/ob_array_expr_utils.h"
namespace oceanbase

View File

@ -24,7 +24,6 @@
#include "sql/engine/ob_batch_rows.h"
#include "common/ob_common_utility.h"
#include "sql/ob_eval_bound.h"
#include "share/schema/ob_schema_struct.h"
namespace oceanbase
{

View File

@ -18,9 +18,9 @@
#include "sql/engine/expr/ob_expr_cmp_func.h"
#include "share/datum/ob_datum_cmp_func_def.h"
#include "share/datum/ob_datum_funcs.h"
#include "sql/engine/expr/ob_expr_operator.h"
// #include "sql/engine/expr/ob_expr_operator.h"
#include "sql/engine/expr/ob_batch_eval_util.h"
#include "share/ob_lob_access_utils.h"
// #include "share/ob_lob_access_utils.h"
#include "lib/udt/ob_array_type.h"
#include "sql/engine/ob_subschema_ctx.h"
#include "sql/engine/expr/ob_array_expr_utils.h"
@ -231,6 +231,44 @@ struct ObRelationalStrFunc<true, CS_TYPE, WITH_END_SPACE, CMP_OP>
// }
};
template<typename T, bool WITH_END_SPACE, ObCmpOp CMP_OP>
struct ObNewRelationalStrFunc
{
static OB_NOINLINE int eval(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{
int ret = OB_SUCCESS;
ObDatum *l = NULL;
ObDatum *r = NULL;
bool contain_null = false;
int cmp_ret = 0;
if (OB_FAIL(ObRelationalExprOperator::get_comparator_operands(
expr, ctx, l, r, expr_datum, contain_null))) {
LOG_WARN("failed to eval args", K(ret));
} else if (!contain_null) {
if (OB_ISNULL(l) || OB_ISNULL(r)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid operands", K(ret), K(l), K(r));
} else if (OB_FAIL(T::cmp(*l, *r, cmp_ret,
expr.args_[0]->datum_meta_.cs_type_, WITH_END_SPACE))) {
LOG_WARN("datum compare failed", K(*l), K(*r));
} else {
expr_datum.set_int(get_cmp_ret<CMP_OP>(cmp_ret));
}
}
return ret;
}
};
template <ObCollationType cs, bool WITH_END_SPACE, ObCmpOp CMP_OP>
struct ObStrRelationEvalWrap {
static int eval(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{
return ObNewRelationalStrFunc<datum_cmp::ObDatumStrCmpImpl,
WITH_END_SPACE,
CMP_OP>::eval(expr, ctx, expr_datum);
}
};
template<bool, ObScale SCALE, ObCmpOp CMP_OP>
struct ObRelationFixedDoubleFunc{};
@ -282,6 +320,16 @@ struct ObRelationalTextFunc<true, CS_TYPE, WITH_END_SPACE, CMP_OP>
}
};
template <ObCollationType cs, bool WITH_END_SPACE, ObCmpOp CMP_OP>
struct ObTextRelationEvalWrap {
static int eval(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{
return ObNewRelationalStrFunc<datum_cmp::ObDatumTextCmpImpl,
WITH_END_SPACE,
CMP_OP>::eval(expr, ctx, expr_datum);
}
};
template<bool, ObCollationType CS_TYPE, bool WITH_END_SPACE, ObCmpOp CMP_OP>
struct ObRelationalTextStrFunc{};
@ -305,6 +353,17 @@ struct ObRelationalTextStrFunc<true, CS_TYPE, WITH_END_SPACE, CMP_OP>
}
};
template <ObCollationType cs, bool WITH_END_SPACE, ObCmpOp CMP_OP>
struct ObTextStrRelationEvalWrap {
static int eval(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{
return ObNewRelationalStrFunc<datum_cmp::ObDatumTextStringCmpImpl,
WITH_END_SPACE,
CMP_OP>::eval(expr, ctx, expr_datum);
}
};
template<bool, ObCollationType CS_TYPE, bool WITH_END_SPACE, ObCmpOp CMP_OP>
struct ObRelationalStrTextFunc{};
@ -328,6 +387,17 @@ struct ObRelationalStrTextFunc<true, CS_TYPE, WITH_END_SPACE, CMP_OP>
}
};
template <ObCollationType cs, bool WITH_END_SPACE, ObCmpOp CMP_OP>
struct ObStrTextRelationEvalWrap {
static int eval(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{
return ObNewRelationalStrFunc<datum_cmp::ObDatumStringTextCmpImpl,
WITH_END_SPACE,
CMP_OP>::eval(expr, ctx, expr_datum);
}
};
template<bool, bool HAS_LOB_HEADER, ObCmpOp CMP_OP>
struct ObRelationalJsonFunc{};
@ -753,6 +823,7 @@ struct ObRelationalVecFunc
}
};
extern ObExpr::EvalBatchFunc EVAL_BATCH_NULL_EXTEND_CMP_FUNCS[CO_MAX];
extern ObExpr::EvalBatchFunc EVAL_BATCH_STR_CMP_FUNCS[CO_MAX];
extern ObExpr::EvalBatchFunc EVAL_BATCH_TEXT_CMP_FUNCS[CO_MAX];
@ -906,6 +977,9 @@ struct TCExprCmpFuncIniter
}
};
// macro to help use the old string relation eval functions, which are always inline
// we choose ObNewRelationalStrFunc here to compile faster.
#define USE_OLD_STR_RELATION_EVAL_FUNC 0
template<int X, int Y>
struct TCExprCmpFuncIniter<X, Y, false>: public ExprDummyIniter{};
@ -915,16 +989,23 @@ using TCExprCmpIniter = TCExprCmpFuncIniter<X, Y, datum_cmp::ObDatumTCCmp<static
template<int X, int Y>
struct StrExprFuncIniter
{
#if USE_OLD_STR_RELATION_EVAL_FUNC
using Def = datum_cmp::ObDatumStrCmp<static_cast<ObCollationType>(X), false>;
template<bool WITH_END_SPACE>
using EvalCmp = ObRelationalStrFunc<Def::defined_,
static_cast<ObCollationType>(X),
WITH_END_SPACE,
static_cast<ObCmpOp>(Y)>;
#else
template<bool WITH_END_SPACE>
using EvalCmp = ObStrRelationEvalWrap<static_cast<ObCollationType>(X),
WITH_END_SPACE,
static_cast<ObCmpOp>(Y)>;
#endif
static void init_array()
{
EVAL_STR_CMP_FUNCS[X][Y][0] = Def::defined_ ? EvalCmp<0>::eval : NULL;
EVAL_STR_CMP_FUNCS[X][Y][1] = Def::defined_ ? EvalCmp<1>::eval : NULL;
EVAL_STR_CMP_FUNCS[X][Y][0] = EvalCmp<0>::eval;
EVAL_STR_CMP_FUNCS[X][Y][1] = EvalCmp<1>::eval;
}
};
@ -937,16 +1018,23 @@ struct StrExprFuncIniter<CS_TYPE_MAX, Y>
template<int X, int Y>
struct TextExprFuncIniter
{
#if USE_OLD_STR_RELATION_EVAL_FUNC
using Def = datum_cmp::ObDatumTextCmp<static_cast<ObCollationType>(X), false>;
template<bool WITH_END_SPACE>
using EvalCmp = ObRelationalTextFunc<Def::defined_,
static_cast<ObCollationType>(X),
WITH_END_SPACE,
static_cast<ObCmpOp>(Y)>;
#else
template<bool WITH_END_SPACE>
using EvalCmp = ObTextRelationEvalWrap<static_cast<ObCollationType>(X),
WITH_END_SPACE,
static_cast<ObCmpOp>(Y)>;
#endif
static void init_array()
{
EVAL_TEXT_CMP_FUNCS[X][Y][0] = Def::defined_ ? EvalCmp<0>::eval : NULL;
EVAL_TEXT_CMP_FUNCS[X][Y][1] = Def::defined_ ? EvalCmp<1>::eval : NULL;
EVAL_TEXT_CMP_FUNCS[X][Y][0] = EvalCmp<0>::eval;
EVAL_TEXT_CMP_FUNCS[X][Y][1] = EvalCmp<1>::eval;
}
};
@ -959,19 +1047,28 @@ struct TextExprFuncIniter<CS_TYPE_MAX, Y>
template<int X, int Y>
struct TextStrExprFuncIniter
{
#if USE_OLD_STR_RELATION_EVAL_FUNC
using Def = datum_cmp::ObDatumTextStringCmp<static_cast<ObCollationType>(X), false>;
template<bool WITH_END_SPACE>
using EvalCmp = ObRelationalTextStrFunc<Def::defined_,
static_cast<ObCollationType>(X),
WITH_END_SPACE,
static_cast<ObCmpOp>(Y)>;
#else
template<bool WITH_END_SPACE>
using EvalCmp = ObTextStrRelationEvalWrap<static_cast<ObCollationType>(X),
WITH_END_SPACE,
static_cast<ObCmpOp>(Y)>;
#endif
static void init_array()
{
EVAL_TEXT_STR_CMP_FUNCS[X][Y][0] = Def::defined_ ? EvalCmp<0>::eval : NULL;
EVAL_TEXT_STR_CMP_FUNCS[X][Y][1] = Def::defined_ ? EvalCmp<1>::eval : NULL;
EVAL_TEXT_STR_CMP_FUNCS[X][Y][0] = EvalCmp<0>::eval;
EVAL_TEXT_STR_CMP_FUNCS[X][Y][1] = EvalCmp<1>::eval;
}
};
#undef USE_OLD_STR_RELATION_EVAL_FUNC
template<int Y>
struct TextStrExprFuncIniter<CS_TYPE_MAX, Y>
{
@ -981,16 +1078,23 @@ struct TextStrExprFuncIniter<CS_TYPE_MAX, Y>
template<int X, int Y>
struct StrTextExprFuncIniter
{
#if USE_OLD_STR_RELATION_EVAL_FUNC
using Def = datum_cmp::ObDatumStringTextCmp<static_cast<ObCollationType>(X), false>;
template<bool WITH_END_SPACE>
using EvalCmp = ObRelationalStrTextFunc<Def::defined_,
static_cast<ObCollationType>(X),
WITH_END_SPACE,
static_cast<ObCmpOp>(Y)>;
#else
template<bool WITH_END_SPACE>
using EvalCmp = ObStrTextRelationEvalWrap<static_cast<ObCollationType>(X),
WITH_END_SPACE,
static_cast<ObCmpOp>(Y)>;
#endif
static void init_array()
{
EVAL_STR_TEXT_CMP_FUNCS[X][Y][0] = Def::defined_ ? EvalCmp<0>::eval : NULL;
EVAL_STR_TEXT_CMP_FUNCS[X][Y][1] = Def::defined_ ? EvalCmp<1>::eval : NULL;
EVAL_STR_TEXT_CMP_FUNCS[X][Y][0] = EvalCmp<0>::eval;
EVAL_STR_TEXT_CMP_FUNCS[X][Y][1] = EvalCmp<1>::eval;
}
};
@ -1228,4 +1332,4 @@ struct DecintCmpFuncIniter
} // end namespace sql
} // end namespace oceanbase
#endif // _OCEANBASE_EXPR_CMP_FUNC_IPP_H_
#endif // _OCEANBASE_EXPR_CMP_FUNC_IPP_H_

View File

@ -15,6 +15,7 @@
#include "lib/ob_errno.h"
#include "sql/engine/ob_exec_context.h"
#include "sql/engine/expr/ob_expr_lob_utils.h"
#include "sql/session/ob_sql_session_info.h"
using namespace oceanbase::common;
using namespace oceanbase::sql;

View File

@ -16,13 +16,14 @@
#include "share/ob_lob_access_utils.h"
#include "sql/engine/expr/ob_expr_util.h"
#include "sql/session/ob_sql_session_info.h"
namespace oceanbase
{
namespace sql
{
class ObBasicSessionInfo;
// wrapper class to handle sql expr string/text type result
template <typename VectorType>
class ObTextStringVectorResult : public common::ObTextStringResult

View File

@ -36,6 +36,7 @@
#include "share/vector/expr_cmp_func.h"
#include "sql/engine/expr/ob_expr_func_round.h"
#include "sql/engine/expr/ob_array_expr_utils.h"
#include "share/schema/ob_schema_struct.h"
namespace oceanbase

View File

@ -40,7 +40,6 @@
#include "sql/engine/expr/ob_expr_extra_info_factory.h"
#include "sql/engine/expr/ob_i_expr_extra_info.h"
#include "lib/hash/ob_hashset.h"
#include "share/schema/ob_schema_struct.h"
#include "lib/udt/ob_array_type.h"
#include "sql/session/ob_local_session_var.h"

View File

@ -25,6 +25,9 @@
#include "sql/ob_result_set.h"
#include "sql/ob_spi.h"
#include "lib/xml/ob_binary_aggregate.h"
#include "share/schema/ob_schema_getter_guard.h"
#include "sql/engine/expr/ob_expr.h"
#include "sql/session/ob_sql_session_info.h"
#ifdef OB_BUILD_ORACLE_PL
#include "pl/sys_package/ob_sdo_geometry.h"
#endif
@ -1530,4 +1533,4 @@ void ObXMLExprHelper::get_accuracy_from_expr(const ObExpr &expr, ObAccuracy &acc
}
} // sql
} // oceanbase
} // oceanbase

View File

@ -26,9 +26,21 @@ using namespace oceanbase::common;
namespace oceanbase
{
namespace share
{
namespace schema
{
class ObSchemaGetterGuard;
}
}
namespace sql
{
class ObExpr;
class ObEvalCtx;
class ObSQLSessionInfo;
enum ObGetXmlBaseType {
OB_IS_REPARSE,
OB_SHOULD_CHECK,
@ -112,7 +124,7 @@ public:
sql::ObExecContext *exec_context,
bool is_ps_protocol,
const ColumnsFieldIArray *fields = NULL,
ObSchemaGetterGuard *schema_guard = NULL);
share::schema::ObSchemaGetterGuard *schema_guard = NULL);
static uint64_t get_tenant_id(ObSQLSessionInfo *session);
static int append_header_in_front(ObIAllocator &allocator, ObXmlDocument *&root, ObIMulModeBase *node);
static int cast_to_res(ObIAllocator &allocator, ObString &xml_content, const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res);
@ -133,4 +145,4 @@ private:
} // sql
} // oceanbase
#endif // OCEANBASE_SQL_OB_EXPR_XML_FUNC_HELPER_H_
#endif // OCEANBASE_SQL_OB_EXPR_XML_FUNC_HELPER_H_