提交 d6394bff 编写于 作者: Y yinyj17 提交者: wangzelin.wzl

fix left to anti bug

上级 8e600315
......@@ -696,24 +696,28 @@ int ObTransformJoinElimination::check_transform_validity_outer_join(
} else {
need_check_relation_exprs = true;
}
if (OB_SUCC(ret) && need_check_relation_exprs) {
bool contained = false;
if (OB_FAIL(ObTransformUtils::check_table_contain_in_semi(stmt,
joined_table->right_table_,
contained))) {
LOG_WARN("failed to check table contained in semi", K(ret));
} else if (contained) {
need_check_relation_exprs = false;
}
}
if (OB_SUCC(ret) && need_check_relation_exprs) {
ObSqlBitSet<> semi_left_rel_ids;
ObSqlBitSet<8, int64_t> right_rel_ids;
ObSEArray<ObRawExpr *, 8> join_conditions;
if (OB_FAIL(join_conditions.assign(joined_table->join_conditions_))) {
LOG_WARN("failed to push back to join conditions.", K(ret));
} else if (OB_FAIL(extract_semi_left_rel_ids(stmt,
joined_table->right_table_,
semi_left_rel_ids))) {
LOG_WARN("failed to extract semi info left table rel ids", K(ret));
} else if (OB_FAIL(extract_child_conditions(stmt,
joined_table->right_table_,
join_conditions,
right_rel_ids))) {
LOG_WARN("failed to extract right child exprs.", K(ret));
} else if (OB_FAIL(adjust_relation_exprs(semi_left_rel_ids,
right_rel_ids,// right table not use by any other expr
} else if (OB_FAIL(adjust_relation_exprs(right_rel_ids,// right table not use by any other expr
join_conditions,
relation_exprs,
is_valid))) {
......@@ -723,41 +727,6 @@ int ObTransformJoinElimination::check_transform_validity_outer_join(
return ret;
}
int ObTransformJoinElimination::extract_semi_left_rel_ids(ObDMLStmt *stmt,
TableItem *table_item,
ObSqlBitSet<> &semi_left_rel_ids)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(stmt) || OB_ISNULL(table_item)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < stmt->get_semi_infos().count(); ++i) {
SemiInfo *semi = stmt->get_semi_infos().at(i);
ObSEArray<uint64_t, 4> r_table_ids;
ObSEArray<uint64_t, 4> common_table_ids;
if (OB_ISNULL(semi)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("semi info is null", K(ret));
} else if (table_item->is_joined_table() &&
OB_FAIL(r_table_ids.assign(static_cast<JoinedTable *>(table_item)->single_table_ids_))) {
} else if (!table_item->is_joined_table() &&
OB_FAIL(r_table_ids.push_back(table_item->table_id_))) {
LOG_WARN("failed to push back joined table", K(ret));
} else if (OB_FAIL(ObOptimizerUtil::intersect(semi->left_table_ids_, r_table_ids, common_table_ids))) {
LOG_WARN("failed to intersect table ids", K(ret));
} else if (!common_table_ids.empty()) {
for (int64_t j = 0; OB_SUCC(ret) && j < common_table_ids.count(); ++j) {
if (OB_FAIL(semi_left_rel_ids.add_member(stmt->get_table_bit_index(common_table_ids.at(j))))) {
LOG_WARN("failed to add semi join left table ids", K(ret));
}
}
}
}
}
return ret;
}
int ObTransformJoinElimination::extract_child_conditions(ObDMLStmt *stmt,
TableItem *table_item,
ObIArray<ObRawExpr *> &join_conditions,
......@@ -799,8 +768,7 @@ int ObTransformJoinElimination::extract_child_conditions(ObDMLStmt *stmt,
return ret;
}
int ObTransformJoinElimination::adjust_relation_exprs(const ObSqlBitSet<> &semi_left_rel_ids,
const ObSqlBitSet<8, int64_t> &right_rel_ids,
int ObTransformJoinElimination::adjust_relation_exprs(const ObSqlBitSet<8, int64_t> &right_rel_ids,
const ObIArray<ObRawExpr *> &join_conditions,
ObIArray<ObRawExpr *> &relation_exprs,
bool &is_valid)
......@@ -813,8 +781,6 @@ int ObTransformJoinElimination::adjust_relation_exprs(const ObSqlBitSet<> &semi_
LOG_WARN("failed to assign to all exprs.", K(ret));
} else if (OB_FAIL(ObOptimizerUtil::remove_item(all_exprs, join_conditions))) {
LOG_WARN("faile to remove item from all stmt exprs.", K(ret));
} else if (OB_FAIL(select_rel_ids.add_members2(semi_left_rel_ids))) {
LOG_WARN("failed to add rel ids", K(ret));
}
for (int64_t i = 0; OB_SUCC(ret) && i < all_exprs.count(); i++) {
if (OB_ISNULL(all_exprs.at(i))) {
......
......@@ -196,16 +196,12 @@ private:
const ObIArray<int64_t> &output_map,
ObIArray<ObRawExpr *> &source_exprs,
ObIArray<ObRawExpr *> &target_exprs);
int extract_semi_left_rel_ids(ObDMLStmt *stmt,
TableItem *table_item,
ObSqlBitSet<> &semi_left_rel_ids);
int extract_child_conditions(ObDMLStmt *stmt,
TableItem *source_table,
ObIArray<ObRawExpr *> &join_conditions,
ObSqlBitSet<8, int64_t> &right_rel_ids);
int adjust_relation_exprs(const ObSqlBitSet<> &semi_left_rel_ids,
const ObSqlBitSet<8, int64_t> &right_rel_ids,
int adjust_relation_exprs(const ObSqlBitSet<8, int64_t> &right_rel_ids,
const ObIArray<ObRawExpr *> &join_conditions,
ObIArray<ObRawExpr *> &relation_exprs,
bool &is_valid);
......
......@@ -532,7 +532,7 @@ int ObTransformLeftJoinToAnti::check_can_be_trans(ObDMLStmt *stmt,
int ret = OB_SUCCESS;
is_valid = false;
TableItem *right_table = NULL;
bool is_del_upd_valid = true;
bool is_table_valid = true;
if (OB_ISNULL(stmt) ||
OB_ISNULL(ctx_) || OB_ISNULL(ctx_->schema_checker_)) {
ret = OB_ERR_UNEXPECTED;
......@@ -558,14 +558,22 @@ int ObTransformLeftJoinToAnti::check_can_be_trans(ObDMLStmt *stmt,
} else if (right_table->is_joined_table()) {
JoinedTable *right_joined_table = static_cast<JoinedTable *>(right_table);
if (is_contain(right_joined_table->single_table_ids_, table_info->table_id_)) {
is_del_upd_valid = false;
is_table_valid = false;
}
} else if (table_info->table_id_ == right_table->table_id_) {
is_del_upd_valid = false;
is_table_valid = false;
}
}
}
for (int64_t i = 0; OB_SUCC(ret) && is_del_upd_valid &&
if (OB_SUCC(ret) && is_table_valid) {
bool contained = false;
if (OB_FAIL(ObTransformUtils::check_table_contain_in_semi(stmt, right_table, contained))) {
LOG_WARN("failed to check table contained in semi", K(ret));
} else if (contained) {
is_table_valid = false;
}
}
for (int64_t i = 0; OB_SUCC(ret) && is_table_valid &&
i < cond_exprs.count(); ++i) {
bool tmp_cond_valid = false;
ObArray<ObRawExpr *> tmp_constraints;
......
......@@ -8302,18 +8302,29 @@ int ObTransformUtils::get_rel_ids_from_tables(const ObDMLStmt *stmt,
}
TableItem *table = NULL;
for (int64_t i = 0; OB_SUCC(ret) && i < table_items.count(); ++i) {
if (OB_ISNULL(table = table_items.at(i))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null.", K(ret));
} else if (table->is_joined_table()) {
ret = get_rel_ids_from_join_table(stmt, static_cast<JoinedTable*>(table),rel_ids);
} else if (OB_FAIL(rel_ids.add_member(stmt->get_table_bit_index(table_items.at(i)->table_id_)))) {
LOG_WARN("failed to add member", K(ret), K(table_items.at(i)->table_id_));
if (OB_FAIL(get_rel_ids_from_table(stmt, table_items.at(i), rel_ids))) {
LOG_WARN("failed to get rel ids from table", K(ret));
}
}
return ret;
}
int ObTransformUtils::get_rel_ids_from_table(const ObDMLStmt *stmt,
const TableItem *table_item,
ObRelIds &rel_ids)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(stmt) || OB_ISNULL(table_item)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null", K(ret));
} else if (table_item->is_joined_table()) {
ret = get_rel_ids_from_join_table(stmt, static_cast<const JoinedTable*>(table_item), rel_ids);
} else if (OB_FAIL(rel_ids.add_member(stmt->get_table_bit_index(table_item->table_id_)))) {
LOG_WARN("failed to add member", K(ret), K(table_item->table_id_));
}
return ret;
}
int ObTransformUtils::get_left_rel_ids_from_semi_info(const ObDMLStmt *stmt,
SemiInfo *info,
ObSqlBitSet<> &rel_ids)
......@@ -11674,5 +11685,30 @@ int ObTransformUtils::check_expr_valid_for_stmt_merge(ObIArray<ObRawExpr*> &sele
return ret;
}
int ObTransformUtils::check_table_contain_in_semi(const ObDMLStmt *stmt,
const TableItem *table,
bool &is_contain)
{
int ret = OB_SUCCESS;
ObRelIds table_rel_ids;
ObSqlBitSet<> semi_left_rel_ids;
if (OB_ISNULL(stmt) || OB_ISNULL(table)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null", K(ret));
} else if (OB_FAIL(get_rel_ids_from_table(stmt, table, table_rel_ids))) {
LOG_WARN("failed to get rel ids from table", K(ret));
}
for (int64_t i = 0; OB_SUCC(ret) && i < stmt->get_semi_info_size(); ++i) {
if (OB_FAIL(get_left_rel_ids_from_semi_info(stmt, stmt->get_semi_infos().at(i),
semi_left_rel_ids))) {
LOG_WARN("failed to get left table ids from semi info", K(ret));
}
}
if (OB_SUCC(ret)) {
is_contain = table_rel_ids.overlap2(semi_left_rel_ids);
}
return ret;
}
} // namespace sql
} // namespace oceanbase
......@@ -1227,6 +1227,10 @@ public:
const ObIArray<TableItem*> &table_items,
ObRelIds &rel_ids);
static int get_rel_ids_from_table(const ObDMLStmt *stmt,
const TableItem *table_item,
ObRelIds &rel_ids);
static int get_left_rel_ids_from_semi_info(const ObDMLStmt *stmt,
SemiInfo *info,
ObSqlBitSet<> &rel_ids);
......@@ -1590,6 +1594,9 @@ public:
static int remove_const_exprs(ObIArray<ObRawExpr *> &input_exprs,
ObIArray<ObRawExpr *> &output_exprs);
static int check_table_contain_in_semi(const ObDMLStmt *stmt,
const TableItem *table,
bool &is_contain);
private:
static int inner_get_lazy_left_join(ObDMLStmt *stmt,
TableItem *table,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册