[CP] fix memory leak in query range with enum set

This commit is contained in:
obdev
2023-02-09 17:08:17 +00:00
committed by ob-robot
parent e2d17e767e
commit 7edc366131
2 changed files with 106 additions and 63 deletions

View File

@ -178,24 +178,30 @@ int ObQueryRange::init_query_range_ctx(ObIAllocator &allocator,
} else { } else {
ObKeyPartId key_part_id(col.table_id_, col.column_id_); ObKeyPartId key_part_id(col.table_id_, col.column_id_);
const ObExprResType *expr_res_type = col.get_column_type(); const ObExprResType *expr_res_type = col.get_column_type();
void *ptr = NULL;
if (OB_ISNULL(expr_res_type)) { if (OB_ISNULL(expr_res_type)) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("expr result type is null", K(ret)); LOG_WARN("expr result type is null", K(ret));
} else if (OB_ISNULL(ptr = allocator.alloc(sizeof(ObKeyPartPos)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to allocate memeory for ObKeyPartPos", K(ret));
} else { } else {
ObExprResType tmp_expr_type = *expr_res_type; ObExprResType tmp_expr_type = *expr_res_type;
if (tmp_expr_type.is_lob_locator()) { if (tmp_expr_type.is_lob_locator()) {
tmp_expr_type.set_type(ObLongTextType); tmp_expr_type.set_type(ObLongTextType);
} }
table_id = (i > 0 ? table_id : col.table_id_); table_id = (i > 0 ? table_id : col.table_id_);
ObKeyPartPos key_part_pos(i, tmp_expr_type); ObKeyPartPos *key_part_pos = new(ptr) ObKeyPartPos(i, tmp_expr_type);
if (OB_UNLIKELY(table_id != col.table_id_)) { // table_id of range columns must be same if (OB_UNLIKELY(table_id != col.table_id_)) { // table_id of range columns must be same
ret = OB_INVALID_ARGUMENT; ret = OB_INVALID_ARGUMENT;
LOG_WARN("range columns must have the same table id", K(table_id), K_(col.table_id)); LOG_WARN("range columns must have the same table id", K(table_id), K_(col.table_id));
} else if (OB_FAIL(key_part_pos.set_enum_set_values(allocator_, col.expr_->get_enum_set_values()))) { } else if (OB_FAIL(key_part_pos->set_enum_set_values(allocator_, col.expr_->get_enum_set_values()))) {
LOG_WARN("fail to set values", K(ret), K(key_part_pos)); LOG_WARN("fail to set values", K(ret), K(key_part_pos));
} else if (OB_FAIL(query_range_ctx_->key_part_map_.set_refactored(key_part_id, key_part_pos))) { } else if (OB_FAIL(query_range_ctx_->key_part_map_.set_refactored(key_part_id, key_part_pos))) {
LOG_WARN("set key part map failed", K(ret), K(key_part_id)); LOG_WARN("set key part map failed", K(ret), K(key_part_id));
} else if (OB_FAIL(query_range_ctx_->key_part_pos_array_.push_back(key_part_pos))) {
LOG_WARN("failed to push back key part pos", K(ret));
} }
} }
} }
@ -228,6 +234,12 @@ int ObQueryRange::init_query_range_ctx(ObIAllocator &allocator,
void ObQueryRange::destroy_query_range_ctx(ObIAllocator &ctx_allocator) void ObQueryRange::destroy_query_range_ctx(ObIAllocator &ctx_allocator)
{ {
if (NULL != query_range_ctx_) { if (NULL != query_range_ctx_) {
for (int64_t i = 0; i < query_range_ctx_->key_part_pos_array_.count(); ++i) {
if (NULL != query_range_ctx_->key_part_pos_array_.at(i)) {
query_range_ctx_->key_part_pos_array_.at(i)->~ObKeyPartPos();
ctx_allocator.free(query_range_ctx_->key_part_pos_array_.at(i));
}
}
query_range_ctx_->~ObQueryRangeCtx(); query_range_ctx_->~ObQueryRangeCtx();
ctx_allocator.free(query_range_ctx_); ctx_allocator.free(query_range_ctx_);
query_range_ctx_ = NULL; query_range_ctx_ = NULL;
@ -426,13 +438,18 @@ int ObQueryRange::check_cur_expr(const ObRawExpr *cur_expr, ObIArray<int64_t> &o
} else if (param->is_column_ref_expr()) { } else if (param->is_column_ref_expr()) {
const ObColumnRefRawExpr *col_expr = static_cast<const ObColumnRefRawExpr *>(param); const ObColumnRefRawExpr *col_expr = static_cast<const ObColumnRefRawExpr *>(param);
ObKeyPartId id(col_expr->get_table_id(), col_expr->get_column_id()); ObKeyPartId id(col_expr->get_table_id(), col_expr->get_column_id());
ObKeyPartPos pos; ObKeyPartPos *pos = nullptr;
bool b_key_part; bool b_key_part;
if (OB_FAIL(is_key_part(id, pos, b_key_part))) { if (OB_FAIL(is_key_part(id, pos, b_key_part))) {
LOG_WARN("failed to get key part", K(ret)); LOG_WARN("failed to get key part", K(ret));
} else if (b_key_part) { } else if (b_key_part) {
is_valid_expr = true; is_valid_expr = true;
ret = add_var_to_array_no_dup(offsets, pos.offset_); if (OB_ISNULL(pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null key pos");
} else if (OB_FAIL(add_var_to_array_no_dup(offsets, pos->offset_))) {
LOG_WARN("failed to add var to array no dup");
}
} }
} }
} }
@ -465,13 +482,16 @@ int ObQueryRange::extract_basic_info(const ObRawExpr *l_expr,
if (l_expr->is_column_ref_expr()) { if (l_expr->is_column_ref_expr()) {
const ObColumnRefRawExpr *col_expr = static_cast<const ObColumnRefRawExpr *>(l_expr); const ObColumnRefRawExpr *col_expr = static_cast<const ObColumnRefRawExpr *>(l_expr);
ObKeyPartId key_part_id(col_expr->get_table_id(), col_expr->get_column_id()); ObKeyPartId key_part_id(col_expr->get_table_id(), col_expr->get_column_id());
ObKeyPartPos key_part_pos; ObKeyPartPos *key_part_pos = nullptr;
bool b_key_part = false; bool b_key_part = false;
if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_key_part))) { if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_key_part))) {
LOG_WARN("failed to get key part", K(ret)); LOG_WARN("failed to get key part", K(ret));
} else if (!b_key_part) { } else if (!b_key_part) {
// do nothing // do nothing
} else if (OB_FAIL(add_var_to_array_no_dup(offsets, key_part_pos.offset_))) { } else if (OB_ISNULL(key_part_pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null key part pos");
} else if (OB_FAIL(add_var_to_array_no_dup(offsets, key_part_pos->offset_))) {
LOG_WARN("failed to add key part offset", K(ret)); LOG_WARN("failed to add key part offset", K(ret));
} else { } else {
is_valid_expr = true; is_valid_expr = true;
@ -509,12 +529,15 @@ int ObQueryRange::extract_basic_info(const ObRawExpr *l_expr,
const_expr = l_expr; const_expr = l_expr;
} }
ObKeyPartId key_part_id(col_expr->get_table_id(), col_expr->get_column_id()); ObKeyPartId key_part_id(col_expr->get_table_id(), col_expr->get_column_id());
ObKeyPartPos key_part_pos; ObKeyPartPos *key_part_pos = nullptr;
if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_is_key_part))) { if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_is_key_part))) {
LOG_WARN("failed to check is key part", K(ret)); LOG_WARN("failed to check is key part", K(ret));
} else if (!b_is_key_part || OB_UNLIKELY(!const_expr->is_const_expr())) { } else if (!b_is_key_part || OB_UNLIKELY(!const_expr->is_const_expr())) {
// always true // always true
} else if (OB_FAIL(add_var_to_array_no_dup(offsets, key_part_pos.offset_))) { } else if (OB_ISNULL(key_part_pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null key part pos");
} else if (OB_FAIL(add_var_to_array_no_dup(offsets, key_part_pos->offset_))) {
LOG_WARN("failed to add key part offset", K(ret)); LOG_WARN("failed to add key part offset", K(ret));
} else { } else {
is_valid_expr = true; is_valid_expr = true;
@ -571,7 +594,7 @@ int ObQueryRange::check_can_extract_rowid(const ObIArray<const ObColumnRefRawExp
LOG_WARN("get unexpected null", K(ret)); LOG_WARN("get unexpected null", K(ret));
} else { } else {
ObKeyPartId key_part_id(col_expr->get_table_id(), col_expr->get_column_id()); ObKeyPartId key_part_id(col_expr->get_table_id(), col_expr->get_column_id());
ObKeyPartPos key_part_pos; ObKeyPartPos *key_part_pos = nullptr;
if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_key_part))) { if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_key_part))) {
LOG_WARN("failed to get key part", K(ret)); LOG_WARN("failed to get key part", K(ret));
} else if (b_key_part) { } else if (b_key_part) {
@ -589,7 +612,12 @@ int ObQueryRange::check_can_extract_rowid(const ObIArray<const ObColumnRefRawExp
} }
if (OB_SUCC(ret) && cur_valid) { if (OB_SUCC(ret) && cur_valid) {
is_valid_expr = true; is_valid_expr = true;
ret = add_var_to_array_no_dup(offsets, key_part_pos.offset_); if (OB_ISNULL(key_part_pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null key part pos");
} else if (OB_FAIL(add_var_to_array_no_dup(offsets, key_part_pos->offset_))) {
LOG_WARN("failed to add var to array no dup", K(ret));
}
} }
} }
} }
@ -1527,7 +1555,7 @@ int ObQueryRange::get_rowid_key_part(const ObRawExpr *l_expr,
for (int64_t i = 0; OB_SUCC(ret) && i < pk_column_items.count(); ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < pk_column_items.count(); ++i) {
const ObColumnRefRawExpr *column_item = pk_column_items.at(i); const ObColumnRefRawExpr *column_item = pk_column_items.at(i);
ObKeyPartId key_part_id(column_item->get_table_id(), column_item->get_column_id()); ObKeyPartId key_part_id(column_item->get_table_id(), column_item->get_column_id());
ObKeyPartPos key_part_pos; ObKeyPartPos *key_part_pos = nullptr;
bool b_is_key_part = false; bool b_is_key_part = false;
tmp_key_part = NULL; tmp_key_part = NULL;
if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_is_key_part))) { if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_is_key_part))) {
@ -1546,6 +1574,9 @@ int ObQueryRange::get_rowid_key_part(const ObRawExpr *l_expr,
} }
if (OB_FAIL(ret) || !b_is_key_part) { if (OB_FAIL(ret) || !b_is_key_part) {
GET_ALWAYS_TRUE_OR_FALSE(true, tmp_key_part); GET_ALWAYS_TRUE_OR_FALSE(true, tmp_key_part);
} else if (OB_ISNULL(key_part_pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null key part pos");
} else if (OB_ISNULL((tmp_key_part = create_new_key_part()))) { } else if (OB_ISNULL((tmp_key_part = create_new_key_part()))) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("alloc memory failed", K(ret)); LOG_ERROR("alloc memory failed", K(ret));
@ -1554,7 +1585,7 @@ int ObQueryRange::get_rowid_key_part(const ObRawExpr *l_expr,
tmp_key_part->rowid_column_idx_ = i; tmp_key_part->rowid_column_idx_ = i;
tmp_key_part->is_phy_rowid_key_part_ = is_physical_rowid; tmp_key_part->is_phy_rowid_key_part_ = is_physical_rowid;
tmp_key_part->id_ = key_part_id; tmp_key_part->id_ = key_part_id;
tmp_key_part->pos_ = key_part_pos; tmp_key_part->pos_ = *key_part_pos;
tmp_key_part->null_safe_ = false; tmp_key_part->null_safe_ = false;
//if current expr can be extracted to range, just store the expr //if current expr can be extracted to range, just store the expr
if (c_type != T_OP_LIKE) { if (c_type != T_OP_LIKE) {
@ -1629,7 +1660,7 @@ int ObQueryRange::get_extract_rowid_range_infos(const ObRawExpr *calc_urowid_exp
LOG_WARN("get unexpected null", K(ret), K(col_expr)); LOG_WARN("get unexpected null", K(ret), K(col_expr));
} else { } else {
ObKeyPartId id(col_expr->get_table_id(), col_expr->get_column_id()); ObKeyPartId id(col_expr->get_table_id(), col_expr->get_column_id());
ObKeyPartPos pos; ObKeyPartPos *pos = nullptr;
bool b_key_part = false; bool b_key_part = false;
if (OB_FAIL(is_key_part(id, pos, b_key_part))) { if (OB_FAIL(is_key_part(id, pos, b_key_part))) {
LOG_WARN("failed to check is key part", K(ret)); LOG_WARN("failed to check is key part", K(ret));
@ -1682,14 +1713,17 @@ int ObQueryRange::get_column_key_part(const ObRawExpr *l_expr,
query_range_ctx_->need_final_extract_ = true; query_range_ctx_->need_final_extract_ = true;
} }
ObKeyPartId id(column_item->get_table_id(), column_item->get_column_id()); ObKeyPartId id(column_item->get_table_id(), column_item->get_column_id());
ObKeyPartPos pos; ObKeyPartPos *pos = nullptr;
bool b_is_key_part = false; bool b_is_key_part = false;
bool always_true = true; bool always_true = true;
if (OB_FAIL(is_key_part(id, pos, b_is_key_part))) { if (OB_FAIL(is_key_part(id, pos, b_is_key_part))) {
LOG_WARN("is_key_part failed", K(ret)); LOG_WARN("is_key_part failed", K(ret));
} else if (!b_is_key_part || OB_UNLIKELY(!const_expr->is_const_expr())) { } else if (!b_is_key_part || OB_UNLIKELY(!const_expr->is_const_expr())) {
GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part); GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part);
} else if (!can_be_extract_range(cmp_type, pos.column_type_, calc_type, } else if (OB_ISNULL(pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null key part pos");
} else if (!can_be_extract_range(cmp_type, pos->column_type_, calc_type,
const_expr->get_result_type().get_type(), always_true)) { const_expr->get_result_type().get_type(), always_true)) {
GET_ALWAYS_TRUE_OR_FALSE(always_true, out_key_part); GET_ALWAYS_TRUE_OR_FALSE(always_true, out_key_part);
} else if (OB_FAIL(get_calculable_expr_val(const_expr, const_val, is_valid))) { } else if (OB_FAIL(get_calculable_expr_val(const_expr, const_val, is_valid))) {
@ -1702,7 +1736,7 @@ int ObQueryRange::get_column_key_part(const ObRawExpr *l_expr,
} else { } else {
ObObj val; ObObj val;
out_key_part->id_ = id; out_key_part->id_ = id;
out_key_part->pos_ = pos; out_key_part->pos_ = *pos;
out_key_part->null_safe_ = (T_OP_NSEQ == c_type); out_key_part->null_safe_ = (T_OP_NSEQ == c_type);
if (!const_expr->cnt_param_expr() if (!const_expr->cnt_param_expr()
|| (!const_expr->has_flag(CNT_DYNAMIC_PARAM) || (!const_expr->has_flag(CNT_DYNAMIC_PARAM)
@ -1770,7 +1804,7 @@ int ObQueryRange::get_column_key_part(const ObRawExpr *l_expr,
} }
if (OB_SUCC(ret) && is_oracle_mode()) { if (OB_SUCC(ret) && is_oracle_mode()) {
// NChar like Nchar, Char like Char is not precise due to padding blank characters // NChar like Nchar, Char like Char is not precise due to padding blank characters
ObObjType column_type = pos.column_type_.get_type(); ObObjType column_type = pos->column_type_.get_type();
ObObjType const_type = const_expr->get_result_type().get_type(); ObObjType const_type = const_expr->get_result_type().get_type();
if ((ObCharType == column_type && ObCharType == const_type) || if ((ObCharType == column_type && ObCharType == const_type) ||
(ObNCharType == column_type && ObNCharType == const_type)) { (ObNCharType == column_type && ObNCharType == const_type)) {
@ -1785,7 +1819,7 @@ int ObQueryRange::get_column_key_part(const ObRawExpr *l_expr,
// do nothing // do nothing
} }
} }
if (OB_SUCC(ret) && OB_FAIL(check_expr_precise(out_key_part, const_expr, calc_type, pos))) { if (OB_SUCC(ret) && OB_FAIL(check_expr_precise(out_key_part, const_expr, calc_type, *pos))) {
LOG_WARN("failed to check expr precise", K(ret)); LOG_WARN("failed to check expr precise", K(ret));
} }
} }
@ -2705,7 +2739,7 @@ int ObQueryRange::get_multi_in_key_part(const ObOpRawExpr *l_expr,
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
ObKeyPart *tmp_key_part = NULL; ObKeyPart *tmp_key_part = NULL;
bool has_rowid = false; bool has_rowid = false;
common::hash::ObHashMap<int64_t, ObKeyPartPos> idx_pos_map; common::hash::ObHashMap<int64_t, ObKeyPartPos*> idx_pos_map;
common::hash::ObHashMap<int64_t, InParamMeta *> idx_param_map; common::hash::ObHashMap<int64_t, InParamMeta *> idx_param_map;
common::hash::ObHashMap<int64_t, int64_t> expr_idx_param_idx_map; common::hash::ObHashMap<int64_t, int64_t> expr_idx_param_idx_map;
if (OB_ISNULL(l_expr) || OB_ISNULL(r_expr)) { if (OB_ISNULL(l_expr) || OB_ISNULL(r_expr)) {
@ -2748,7 +2782,7 @@ int ObQueryRange::get_multi_in_key_part(const ObOpRawExpr *l_expr,
param_res_type.set_calc_meta(res_type.get_row_calc_cmp_types().at(j)); param_res_type.set_calc_meta(res_type.get_row_calc_cmp_types().at(j));
const ObRawExpr *const_expr = r_param->get_param_expr(j); const ObRawExpr *const_expr = r_param->get_param_expr(j);
InParamMeta *param_meta = NULL; InParamMeta *param_meta = NULL;
ObKeyPartPos cur_key_pos; ObKeyPartPos *cur_key_pos = nullptr;
bool can_be_extract = true; bool can_be_extract = true;
bool always_true = true; bool always_true = true;
bool is_val_valid = true; bool is_val_valid = true;
@ -2773,20 +2807,23 @@ int ObQueryRange::get_multi_in_key_part(const ObOpRawExpr *l_expr,
LOG_WARN("failed to check const value valid", K(ret)); LOG_WARN("failed to check const value valid", K(ret));
} }
} }
} else if (OB_ISNULL(cur_key_pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(j));
} else if (OB_UNLIKELY(!const_expr->is_const_expr())) { } else if (OB_UNLIKELY(!const_expr->is_const_expr())) {
can_be_extract = false; can_be_extract = false;
always_true = true; always_true = true;
} else if (OB_FAIL(idx_param_map.get_refactored(j, param_meta))) { } else if (OB_FAIL(idx_param_map.get_refactored(j, param_meta))) {
LOG_WARN("failed to get param meta", K(ret)); LOG_WARN("failed to get param meta", K(ret));
} else if (!can_be_extract_range(T_OP_EQ, } else if (!can_be_extract_range(T_OP_EQ,
cur_key_pos.column_type_, cur_key_pos->column_type_,
param_res_type.get_calc_meta(), param_res_type.get_calc_meta(),
const_expr->get_result_type().get_type(), const_expr->get_result_type().get_type(),
always_true)) { always_true)) {
can_be_extract = false; can_be_extract = false;
} else if (OB_FAIL(get_param_value(tmp_key_part->in_keypart_, } else if (OB_FAIL(get_param_value(tmp_key_part->in_keypart_,
param_meta, param_meta,
cur_key_pos, *cur_key_pos,
const_expr, const_expr,
dtc_params, dtc_params,
is_val_valid))) { is_val_valid))) {
@ -2796,7 +2833,7 @@ int ObQueryRange::get_multi_in_key_part(const ObOpRawExpr *l_expr,
} else if (OB_FAIL(check_expr_precise(tmp_key_part, } else if (OB_FAIL(check_expr_precise(tmp_key_part,
const_expr, const_expr,
param_res_type.get_calc_meta(), param_res_type.get_calc_meta(),
cur_key_pos))) { *cur_key_pos))) {
LOG_WARN("failed to check expr precise", K(ret)); LOG_WARN("failed to check expr precise", K(ret));
} }
if (OB_SUCC(ret) && !can_be_extract) { if (OB_SUCC(ret) && !can_be_extract) {
@ -2842,7 +2879,7 @@ int ObQueryRange::prepare_multi_in_info(const ObOpRawExpr *l_expr,
const ObOpRawExpr *r_expr, const ObOpRawExpr *r_expr,
ObKeyPart *&tmp_key_part, ObKeyPart *&tmp_key_part,
bool &has_rowid, bool &has_rowid,
common::hash::ObHashMap<int64_t, ObKeyPartPos> &idx_pos_map, common::hash::ObHashMap<int64_t, ObKeyPartPos*> &idx_pos_map,
common::hash::ObHashMap<int64_t, InParamMeta *> &idx_param_map, common::hash::ObHashMap<int64_t, InParamMeta *> &idx_param_map,
common::hash::ObHashMap<int64_t, int64_t> &expr_idx_param_idx_map, common::hash::ObHashMap<int64_t, int64_t> &expr_idx_param_idx_map,
const ObDataTypeCastParams &dtc_params) const ObDataTypeCastParams &dtc_params)
@ -2852,17 +2889,11 @@ int ObQueryRange::prepare_multi_in_info(const ObOpRawExpr *l_expr,
if (OB_ISNULL(l_expr) || OB_ISNULL(r_expr)) { if (OB_ISNULL(l_expr) || OB_ISNULL(r_expr)) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(l_expr), K(r_expr)); LOG_WARN("get unexpected null", K(ret), K(l_expr), K(r_expr));
} else if (OB_FAIL(idx_pos_map.create( } else if (OB_FAIL(idx_pos_map.create(l_expr->get_param_count(), "IdxKeyMap", "IdxKeyMap"))) {
hash::cal_next_prime(l_expr->get_param_count()),
"IdxKeyMap", "IdxKeyMap"))) {
LOG_WARN("fail to init hashmap", K(ret)); LOG_WARN("fail to init hashmap", K(ret));
} else if (OB_FAIL(idx_param_map.create( } else if (OB_FAIL(idx_param_map.create(l_expr->get_param_count(), "IdxParamMap", "IdxParamMap"))) {
hash::cal_next_prime(l_expr->get_param_count()),
"IdxParamMap", "IdxParamMap"))) {
LOG_WARN("fail to init hashmap", K(ret)); LOG_WARN("fail to init hashmap", K(ret));
} else if (OB_FAIL(expr_idx_param_idx_map.create( } else if (OB_FAIL(expr_idx_param_idx_map.create(l_expr->get_param_count(), "IdxMap", "IdxMap"))) {
hash::cal_next_prime(l_expr->get_param_count()),
"IdxMap", "IdxMap"))) {
LOG_WARN("fail to init hashmap", K(ret)); LOG_WARN("fail to init hashmap", K(ret));
} else { } else {
int64_t param_cnt = 0; int64_t param_cnt = 0;
@ -2886,12 +2917,15 @@ int ObQueryRange::prepare_multi_in_info(const ObOpRawExpr *l_expr,
} else { } else {
const ObColumnRefRawExpr *col_expr = static_cast<const ObColumnRefRawExpr *>(expr); const ObColumnRefRawExpr *col_expr = static_cast<const ObColumnRefRawExpr *>(expr);
ObKeyPartId key_id(col_expr->get_table_id(), col_expr->get_column_id()); ObKeyPartId key_id(col_expr->get_table_id(), col_expr->get_column_id());
ObKeyPartPos key_pos; ObKeyPartPos *key_pos = nullptr;
bool b_key_part = false; bool b_key_part = false;
if (OB_FAIL(is_key_part(key_id, key_pos, b_key_part))) { if (OB_FAIL(is_key_part(key_id, key_pos, b_key_part))) {
LOG_WARN("failed to check key part", K(ret)); LOG_WARN("failed to check key part", K(ret));
} else if (!b_key_part) { } else if (!b_key_part) {
query_range_ctx_->cur_expr_is_precise_ = false; query_range_ctx_->cur_expr_is_precise_ = false;
} else if (OB_ISNULL(key_pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null key part pos");
} else { } else {
if (tmp_key_part == NULL) { if (tmp_key_part == NULL) {
if (OB_ISNULL(tmp_key_part = create_new_key_part())) { if (OB_ISNULL(tmp_key_part = create_new_key_part())) {
@ -2915,12 +2949,12 @@ int ObQueryRange::prepare_multi_in_info(const ObOpRawExpr *l_expr,
LOG_WARN("failed to set idx to key meta map", K(ret)); LOG_WARN("failed to set idx to key meta map", K(ret));
} else if (OB_FAIL(expr_idx_param_idx_map.set_refactored(i, param_cnt++))) { } else if (OB_FAIL(expr_idx_param_idx_map.set_refactored(i, param_cnt++))) {
LOG_WARN("failed to set expr idx to key idx map", K(ret)); LOG_WARN("failed to set expr idx to key idx map", K(ret));
} else if (OB_FAIL(tmp_key_part->in_keypart_->offsets_.push_back(key_pos.offset_))) { } else if (OB_FAIL(tmp_key_part->in_keypart_->offsets_.push_back(key_pos->offset_))) {
LOG_WARN("failed to push back key offset", K(ret)); LOG_WARN("failed to push back key offset", K(ret));
} else if (OB_FAIL(tmp_key_part->in_keypart_->in_params_.push_back(new_param_meta))) { } else if (OB_FAIL(tmp_key_part->in_keypart_->in_params_.push_back(new_param_meta))) {
LOG_WARN("failed to push back param", K(ret)); LOG_WARN("failed to push back param", K(ret));
} else { } else {
new_param_meta->pos_ = key_pos; new_param_meta->pos_ = *key_pos;
new_param_meta->vals_.set_block_allocator(ModulePageAllocator(allocator_)); new_param_meta->vals_.set_block_allocator(ModulePageAllocator(allocator_));
} }
} }
@ -3041,13 +3075,16 @@ int ObQueryRange::get_single_in_key_part(const ObColumnRefRawExpr *col_expr,
LOG_WARN("get invalid argument", K(ret), K(col_expr), K(r_expr)); LOG_WARN("get invalid argument", K(ret), K(col_expr), K(r_expr));
} else { } else {
ObKeyPartId key_id(col_expr->get_table_id(), col_expr->get_column_id()); ObKeyPartId key_id(col_expr->get_table_id(), col_expr->get_column_id());
ObKeyPartPos key_pos; ObKeyPartPos *key_pos = nullptr;
bool b_key_part = false; bool b_key_part = false;
InParamMeta *new_param_meta = NULL; InParamMeta *new_param_meta = NULL;
if (OB_FAIL(is_key_part(key_id, key_pos, b_key_part))) { if (OB_FAIL(is_key_part(key_id, key_pos, b_key_part))) {
LOG_WARN("failed to check key part", K(ret)); LOG_WARN("failed to check key part", K(ret));
} else if (!b_key_part) { } else if (!b_key_part) {
GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part); GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part);
} else if (OB_ISNULL(key_pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null key part pos");
} else if (OB_ISNULL(tmp_key_part = create_new_key_part())) { } else if (OB_ISNULL(tmp_key_part = create_new_key_part())) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to create new key part", K(ret)); LOG_WARN("failed to create new key part", K(ret));
@ -3056,7 +3093,7 @@ int ObQueryRange::get_single_in_key_part(const ObColumnRefRawExpr *col_expr,
} else if (OB_ISNULL(tmp_key_part->in_keypart_)) { } else if (OB_ISNULL(tmp_key_part->in_keypart_)) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret)); LOG_WARN("get unexpected null", K(ret));
} else if (OB_FAIL(tmp_key_part->in_keypart_->offsets_.push_back(key_pos.offset_))) { } else if (OB_FAIL(tmp_key_part->in_keypart_->offsets_.push_back(key_pos->offset_))) {
LOG_WARN("failed to push back key offset", K(ret)); LOG_WARN("failed to push back key offset", K(ret));
} else if (OB_ISNULL(new_param_meta = tmp_key_part->in_keypart_->create_param_meta(allocator_))) { } else if (OB_ISNULL(new_param_meta = tmp_key_part->in_keypart_->create_param_meta(allocator_))) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
@ -3064,7 +3101,7 @@ int ObQueryRange::get_single_in_key_part(const ObColumnRefRawExpr *col_expr,
} else { } else {
tmp_key_part->in_keypart_->table_id_ = col_expr->get_table_id(); tmp_key_part->in_keypart_->table_id_ = col_expr->get_table_id();
tmp_key_part->in_keypart_->is_strict_in_ = true; tmp_key_part->in_keypart_->is_strict_in_ = true;
new_param_meta->pos_ = key_pos; new_param_meta->pos_ = *key_pos;
new_param_meta->vals_.set_block_allocator(ModulePageAllocator(allocator_)); new_param_meta->vals_.set_block_allocator(ModulePageAllocator(allocator_));
ObSEArray<int64_t, 4> invalid_val_idx; ObSEArray<int64_t, 4> invalid_val_idx;
bool always_true = false; bool always_true = false;
@ -3080,14 +3117,14 @@ int ObQueryRange::get_single_in_key_part(const ObColumnRefRawExpr *col_expr,
cur_can_be_extract = false; cur_can_be_extract = false;
cur_always_true = true; cur_always_true = true;
} else if (!can_be_extract_range(T_OP_EQ, } else if (!can_be_extract_range(T_OP_EQ,
key_pos.column_type_, key_pos->column_type_,
res_type.get_calc_meta(), res_type.get_calc_meta(),
const_expr->get_result_type().get_type(), const_expr->get_result_type().get_type(),
cur_always_true)) { cur_always_true)) {
cur_can_be_extract = false; cur_can_be_extract = false;
} else if (OB_FAIL(get_param_value(tmp_key_part->in_keypart_, } else if (OB_FAIL(get_param_value(tmp_key_part->in_keypart_,
new_param_meta, new_param_meta,
key_pos, *key_pos,
const_expr, const_expr,
dtc_params, dtc_params,
is_val_valid))) { is_val_valid))) {
@ -3097,7 +3134,7 @@ int ObQueryRange::get_single_in_key_part(const ObColumnRefRawExpr *col_expr,
} else if (OB_FAIL(check_expr_precise(tmp_key_part, } else if (OB_FAIL(check_expr_precise(tmp_key_part,
const_expr, const_expr,
res_type.get_calc_meta(), res_type.get_calc_meta(),
key_pos))) { *key_pos))) {
LOG_WARN("failed to check expr precise", K(ret)); LOG_WARN("failed to check expr precise", K(ret));
} }
if (OB_SUCC(ret) && !cur_can_be_extract && cur_always_true) { if (OB_SUCC(ret) && !cur_can_be_extract && cur_always_true) {
@ -3512,19 +3549,22 @@ int ObQueryRange::pre_extract_geo_op(const ObOpRawExpr *geo_expr,
} }
ObKeyPartId key_part_id(column_item->get_table_id(), ObKeyPartId key_part_id(column_item->get_table_id(),
is_cellid_col ? column_info.cellid_columnId_ : column_id); is_cellid_col ? column_info.cellid_columnId_ : column_id);
ObKeyPartPos key_part_pos; ObKeyPartPos *key_part_pos = nullptr;
bool b_is_key_part = false; bool b_is_key_part = false;
if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_is_key_part))) { if (OB_FAIL(is_key_part(key_part_id, key_part_pos, b_is_key_part))) {
LOG_WARN("is_key_part failed", K(ret)); LOG_WARN("is_key_part failed", K(ret));
} else if (!b_is_key_part) { } else if (!b_is_key_part) {
GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part); GET_ALWAYS_TRUE_OR_FALSE(true, out_key_part);
} else if (OB_ISNULL(key_part_pos)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null key part pos");
} else if (OB_ISNULL((out_key_part = create_new_key_part()))) { } else if (OB_ISNULL((out_key_part = create_new_key_part()))) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_ERROR("alloc memory failed", K(ret)); LOG_ERROR("alloc memory failed", K(ret));
} else { } else {
contain_geo_filters_ = true; contain_geo_filters_ = true;
out_key_part->id_ = key_part_id; out_key_part->id_ = key_part_id;
out_key_part->pos_ = key_part_pos; out_key_part->pos_ = *key_part_pos;
if (op_type == ObGeoRelationType::T_DWITHIN) { if (op_type == ObGeoRelationType::T_DWITHIN) {
if (OB_FAIL(get_dwithin_item(expr, extra_item))) { if (OB_FAIL(get_dwithin_item(expr, extra_item))) {
LOG_WARN("failed to get dwithin item", K(ret)); LOG_WARN("failed to get dwithin item", K(ret));
@ -3728,7 +3768,7 @@ int ObQueryRange::get_in_expr_res_type(const ObRawExpr *in_expr, int64_t val_idx
return ret; return ret;
} }
int ObQueryRange::is_key_part(const ObKeyPartId &id, ObKeyPartPos &pos, bool &is_key_part) int ObQueryRange::is_key_part(const ObKeyPartId &id, ObKeyPartPos *&pos, bool &is_key_part)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
is_key_part = false; is_key_part = false;
@ -3738,7 +3778,8 @@ int ObQueryRange::is_key_part(const ObKeyPartId &id, ObKeyPartPos &pos, bool &is
} else { } else {
int64_t max_off = query_range_ctx_->max_valid_offset_; int64_t max_off = query_range_ctx_->max_valid_offset_;
int map_ret = query_range_ctx_->key_part_map_.get_refactored(id, pos); int map_ret = query_range_ctx_->key_part_map_.get_refactored(id, pos);
if (OB_SUCCESS == map_ret && (max_off == -1 || (max_off != - 1 && pos.offset_ <= max_off))) { if (OB_SUCCESS == map_ret && OB_NOT_NULL(pos) &&
(max_off == -1 || (max_off != - 1 && pos->offset_ <= max_off))) {
is_key_part = true; is_key_part = true;
SQL_REWRITE_LOG(DEBUG, "id pair is key part", K_(id.table_id), K_(id.column_id)); SQL_REWRITE_LOG(DEBUG, "id pair is key part", K_(id.table_id), K_(id.column_id));
} else if (OB_HASH_NOT_EXIST != map_ret) { } else if (OB_HASH_NOT_EXIST != map_ret) {

View File

@ -102,22 +102,23 @@ private:
~ObQueryRangeCtx() ~ObQueryRangeCtx()
{ {
} }
void clear() // void clear()
{ // {
key_part_map_.reset(); // key_part_map_.reset();
need_final_extract_ = false; // key_part_pos_array_.reset();
} // need_final_extract_ = false;
void reset() // }
{ // void reset()
clear(); // {
precise_range_exprs_.reset(); // clear();
final_exprs_.reset(); // precise_range_exprs_.reset();
expr_constraints_ = NULL; // final_exprs_.reset();
params_ = NULL; // expr_constraints_ = NULL;
cur_expr_is_precise_ = false; // params_ = NULL;
} // cur_expr_is_precise_ = false;
// }
//131的原因是最大的rowkey个数是128,距离128最近的素数是131 //131的原因是最大的rowkey个数是128,距离128最近的素数是131
common::hash::ObPlacementHashMap<ObKeyPartId, ObKeyPartPos, 131> key_part_map_; common::hash::ObPlacementHashMap<ObKeyPartId, ObKeyPartPos*, 131> key_part_map_;
bool need_final_extract_; bool need_final_extract_;
int64_t max_valid_offset_; int64_t max_valid_offset_;
bool cur_expr_is_precise_; //当前正在被抽取的表达式是精确的范围,没有被放大 bool cur_expr_is_precise_; //当前正在被抽取的表达式是精确的范围,没有被放大
@ -128,6 +129,7 @@ private:
ExprConstrantArray *expr_constraints_; ExprConstrantArray *expr_constraints_;
const ParamsIArray *params_; const ParamsIArray *params_;
common::ObSEArray<const ObRawExpr *, 16> final_exprs_; common::ObSEArray<const ObRawExpr *, 16> final_exprs_;
ObSEArray<ObKeyPartPos*, 8> key_part_pos_array_;
}; };
public: public:
enum ObQueryRangeState enum ObQueryRangeState
@ -644,7 +646,7 @@ private:
const ObOpRawExpr *r_expr, const ObOpRawExpr *r_expr,
ObKeyPart *&tmp_key_part, ObKeyPart *&tmp_key_part,
bool &has_rowid, bool &has_rowid,
common::hash::ObHashMap<int64_t, ObKeyPartPos> &idx_pos_map, common::hash::ObHashMap<int64_t, ObKeyPartPos*> &idx_pos_map,
common::hash::ObHashMap<int64_t, InParamMeta *> &idx_param_map, common::hash::ObHashMap<int64_t, InParamMeta *> &idx_param_map,
common::hash::ObHashMap<int64_t, int64_t> &expr_idx_param_idx_map, common::hash::ObHashMap<int64_t, int64_t> &expr_idx_param_idx_map,
const ObDataTypeCastParams &dtc_params); const ObDataTypeCastParams &dtc_params);
@ -681,7 +683,7 @@ private:
const ObRawExpr *const_expr, const ObRawExpr *const_expr,
const ObExprCalcType &calc_type, const ObExprCalcType &calc_type,
const ObKeyPartPos &key_pos); const ObKeyPartPos &key_pos);
int is_key_part(const ObKeyPartId &id, ObKeyPartPos &pos, bool &is_key_part); int is_key_part(const ObKeyPartId &id, ObKeyPartPos *&pos, bool &is_key_part);
int split_general_or(ObKeyPart *graph, ObKeyPartList &or_storage); int split_general_or(ObKeyPart *graph, ObKeyPartList &or_storage);
int split_or(ObKeyPart *graph, ObKeyPartList &or_list); int split_or(ObKeyPart *graph, ObKeyPartList &or_list);
int split_and(ObKeyPart *and_graph, ObKeyPartList &and_list); int split_and(ObKeyPart *and_graph, ObKeyPartList &and_list);