fix eliminate anti join with generated column bug
This commit is contained in:
@ -2037,15 +2037,17 @@ int ObTransformJoinElimination::adjust_source_table(ObDMLStmt *source_stmt,
|
|||||||
} else {
|
} else {
|
||||||
uint64_t source_table_id = source_table->table_id_;
|
uint64_t source_table_id = source_table->table_id_;
|
||||||
uint64_t target_table_id = target_table->table_id_;
|
uint64_t target_table_id = target_table->table_id_;
|
||||||
ColumnItem new_col;
|
|
||||||
ObColumnRefRawExpr *col_expr = NULL;
|
|
||||||
ObRawExprCopier expr_copier(*ctx_->expr_factory_);
|
ObRawExprCopier expr_copier(*ctx_->expr_factory_);
|
||||||
|
ObSEArray<ColumnItem*, 4> columns_need_copy;
|
||||||
|
ObSEArray<uint64_t, 4> column_ids_for_copy;
|
||||||
|
// 1. collect column map already exists
|
||||||
for (int64_t i = 0; OB_SUCC(ret) && i < target_column_items.count(); ++i) {
|
for (int64_t i = 0; OB_SUCC(ret) && i < target_column_items.count(); ++i) {
|
||||||
ColumnItem *target_col = NULL;
|
ColumnItem *target_col = NULL;
|
||||||
ColumnItem *source_col = NULL;
|
ColumnItem *source_col = NULL;
|
||||||
uint64_t column_id = OB_INVALID_ID;
|
uint64_t column_id = OB_INVALID_ID;
|
||||||
if (OB_ISNULL(target_col = target_stmt->get_column_item_by_id(target_table_id,
|
if (OB_ISNULL(target_col = target_stmt->get_column_item_by_id(target_table_id,
|
||||||
target_column_items.at(i).column_id_))) {
|
target_column_items.at(i).column_id_)) ||
|
||||||
|
OB_ISNULL(target_col->get_expr())) {
|
||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_UNEXPECTED;
|
||||||
LOG_WARN("get unexpected null", K(ret));
|
LOG_WARN("get unexpected null", K(ret));
|
||||||
} else if (NULL == output_map) {
|
} else if (NULL == output_map) {
|
||||||
@ -2066,7 +2068,38 @@ int ObTransformJoinElimination::adjust_source_table(ObDMLStmt *source_stmt,
|
|||||||
source_col = source_stmt->get_column_item_by_id(source_table_id, column_id);
|
source_col = source_stmt->get_column_item_by_id(source_table_id, column_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (OB_FAIL(ret) || NULL != source_col) { // add new column to source_stmt
|
if (OB_FAIL(ret)) {
|
||||||
|
} else if (OB_ISNULL(source_col)) { // no map relationship found
|
||||||
|
if (OB_FAIL(columns_need_copy.push_back(target_col))) {
|
||||||
|
LOG_WARN("failed to push back expr", K(ret));
|
||||||
|
} else if (OB_FAIL(column_ids_for_copy.push_back(column_id))) {
|
||||||
|
LOG_WARN("failed to push back uint64_t", K(ret));
|
||||||
|
}
|
||||||
|
} else if (OB_FAIL(expr_copier.add_replaced_expr(target_col->get_expr(),
|
||||||
|
source_col->get_expr()))) {
|
||||||
|
// reuse the existing column mapping for copying the dependant expr of generated column
|
||||||
|
LOG_WARN("failed to add replaced expr", K(ret));
|
||||||
|
} else if (OB_FAIL(source_col_exprs.push_back(source_col->get_expr()))) {
|
||||||
|
LOG_WARN("failed to push back epxr", K(ret));
|
||||||
|
} else if (OB_FAIL(target_col_exprs.push_back(target_col->get_expr()))) {
|
||||||
|
LOG_WARN("failed to push back expr", K(ret));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2. deep copy column item if need
|
||||||
|
if (OB_FAIL(ret)) {
|
||||||
|
} else if (columns_need_copy.count() != column_ids_for_copy.count()) {
|
||||||
|
ret = OB_ERR_UNEXPECTED;
|
||||||
|
LOG_WARN("get unexpected array count", K(columns_need_copy.count()), K(column_ids_for_copy.count()));
|
||||||
|
} else {
|
||||||
|
for (int64_t i = 0; OB_SUCC(ret) && i < columns_need_copy.count(); ++i) {
|
||||||
|
ColumnItem new_col;
|
||||||
|
ObColumnRefRawExpr *col_expr = NULL;
|
||||||
|
ColumnItem *target_col = columns_need_copy.at(i);
|
||||||
|
ColumnItem *source_col = NULL;
|
||||||
|
uint64_t column_id = column_ids_for_copy.at(i);
|
||||||
|
if (OB_ISNULL(target_col)) {
|
||||||
|
ret = OB_ERR_UNEXPECTED;
|
||||||
|
LOG_WARN("get unexpected null", K(ret));
|
||||||
} else if (OB_FAIL(new_col.deep_copy(expr_copier, *target_col))) {
|
} else if (OB_FAIL(new_col.deep_copy(expr_copier, *target_col))) {
|
||||||
LOG_WARN("failed to deep copy column item", K(ret));
|
LOG_WARN("failed to deep copy column item", K(ret));
|
||||||
} else if (OB_ISNULL(col_expr = new_col.get_expr())) {
|
} else if (OB_ISNULL(col_expr = new_col.get_expr())) {
|
||||||
@ -2104,6 +2137,7 @@ int ObTransformJoinElimination::adjust_source_table(ObDMLStmt *source_stmt,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user