[bugfix]: fix bug in online_ddl.(fail to replace sort key in inner_sql);

This commit is contained in:
Monk-Liu
2023-02-07 16:11:14 +08:00
committed by ob-robot
parent 2a1917b23b
commit de66a8b416
2 changed files with 33 additions and 19 deletions

View File

@ -536,7 +536,7 @@ int ObDelUpdLogPlan::compute_exchange_info_for_pdml_insert(const ObShardingInfo
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected error", K(get_stmt()), K(ret));
} else if (OB_FAIL(static_cast<const ObInsertStmt*>(get_stmt())->get_ddl_sort_keys(exch_info.sort_keys_))) {
LOG_WARN("failed to get sort ddl sort keys", K(ret));
LOG_WARN("fail to get ddl sort key", K(ret));
} else if (exch_info.dist_method_ == ObPQDistributeMethod::PARTITION_RANGE &&
OB_FAIL(exch_info.repart_all_tablet_ids_.assign(target_sharding.get_all_tablet_ids()))) {
LOG_WARN("failed to get all partition ids", K(ret));
@ -1121,10 +1121,11 @@ int ObDelUpdLogPlan::get_ddl_sort_keys_with_part_expr(ObExchangeInfo &exch_info,
int ret = OB_SUCCESS;
sort_keys.reset();
ObArray<OrderItem> tmp_sort_keys;
if (2 != get_stmt()->get_table_size()) {
const ObInsertStmt *ins_stmt = static_cast<const ObInsertStmt *>(get_stmt());
if (2 != ins_stmt->get_table_size()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("error unexpected, table item size is not as expected", K(ret), "table_item_size", get_stmt()->get_table_size());
} else if (OB_FAIL(static_cast<const ObInsertStmt *>(get_stmt())->get_ddl_sort_keys(tmp_sort_keys))) {
LOG_WARN("error unexpected, table item size is not as expected", K(ret), "table_item_size", ins_stmt->get_table_size());
} else if (OB_FAIL(ins_stmt->get_ddl_sort_keys(tmp_sort_keys))) {
LOG_WARN("get ddl sort keys failed", K(ret));
} else if (OB_NOT_NULL(exch_info.calc_part_id_expr_)) {
OrderItem item;

View File

@ -344,6 +344,7 @@ int ObInsertStmt::get_ddl_sort_keys(common::ObIArray<OrderItem> &sort_keys) cons
LOG_WARN("get select exprs failed", K(ret));
} else {
LOG_INFO("get ddl sort keys", K(sort_keys), K(column_list), K(view_column_list));
ObSEArray<uint64_t, 4> column_ids; // the offset in select_items of sortkey
for (int64_t i = 0; OB_SUCC(ret) && i < sort_keys.count(); ++i) {
int64_t j = 0;
for (int64_t j = 0; OB_SUCC(ret) && j < column_list.count(); ++j) {
@ -351,6 +352,8 @@ int ObInsertStmt::get_ddl_sort_keys(common::ObIArray<OrderItem> &sort_keys) cons
if (j >= view_column_list.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("error unexpected, view column list is not as expected", K(ret), K(j), K(view_column_list));
} else if (OB_FAIL(column_ids.push_back(j))) {
LOG_WARN("fail to push back column ids");
} else {
sort_keys.at(i).expr_ = view_column_list.at(j);
}
@ -362,22 +365,32 @@ int ObInsertStmt::get_ddl_sort_keys(common::ObIArray<OrderItem> &sort_keys) cons
LOG_WARN("sort key must be prefix of select list", K(ret), K(sort_keys), K(column_list), K(view_column_list));
}
}
if (OB_SUCC(ret)) {
const common::ObIArray<ObRawExpr*> &column_conv_exprs = get_column_conv_exprs();
const common::ObIArray<ObColumnRefRawExpr*> &value_desc = get_values_desc();
const common::ObIArray<ObColumnRefRawExpr*> &column_exprs = table_info_.column_exprs_;
for (int64_t i = 0; OB_SUCC(ret) && i < sort_keys.count(); ++i) {
ObRawExpr *expr = sort_keys.at(i).expr_;
int64_t j = 0;
for ( ; OB_SUCC(ret) && j < get_column_conv_exprs().count(); ++j) {
ObSysFunRawExpr *sys_func_expr = static_cast<ObSysFunRawExpr *>(get_column_conv_exprs().at(j));
if (OB_ISNULL(sys_func_expr)) {
if (column_ids.at(i) >= value_desc.count()) {
// ignore, since for geometry, column_list.count() could be bigger than value_desc.count();
} else {
// the n-th values desc's column id
uint64_t column_id = value_desc.at(column_ids.at(i))->get_column_id();
// get column_exprs'offset by column_id;
bool found = false;
for (int64_t j = 0; OB_SUCC(ret) && !found && j < column_exprs.count(); j++) {
if (OB_ISNULL(column_exprs.at(j))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("error unexpected, sys func expr is null", K(ret));
} else if (ObOptimizerUtil::is_sub_expr(expr, sys_func_expr)) {
sort_keys.at(i).expr_ = sys_func_expr;
break;
LOG_WARN("column exprs is null", K(ret));
} else if (column_exprs.at(j)->get_column_id() == column_id) {
sort_keys.at(i).expr_ = column_conv_exprs.at(j);
found = true;
}
}
if (OB_SUCC(ret) && j == get_column_conv_exprs().count()) {
if (OB_SUCC(ret) && !found) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("error unexpected, sys func expr must not be nullptr", K(ret), K(get_column_conv_exprs()));
LOG_WARN("can't found column conv expr", K(ret));
}
}
}
}
}