Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
天地威能
oceanbase
提交
d6394bff
O
oceanbase
项目概览
天地威能
/
oceanbase
与 Fork 源项目一致
Fork自
oceanbase / oceanbase
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oceanbase
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d6394bff
编写于
11月 18, 2022
作者:
Y
yinyj17
提交者:
wangzelin.wzl
11月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix left to anti bug
上级
8e600315
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
75 addition
and
62 deletion
+75
-62
src/sql/rewrite/ob_transform_join_elimination.cpp
src/sql/rewrite/ob_transform_join_elimination.cpp
+12
-46
src/sql/rewrite/ob_transform_join_elimination.h
src/sql/rewrite/ob_transform_join_elimination.h
+1
-5
src/sql/rewrite/ob_transform_left_join_to_anti.cpp
src/sql/rewrite/ob_transform_left_join_to_anti.cpp
+12
-4
src/sql/rewrite/ob_transform_utils.cpp
src/sql/rewrite/ob_transform_utils.cpp
+43
-7
src/sql/rewrite/ob_transform_utils.h
src/sql/rewrite/ob_transform_utils.h
+7
-0
未找到文件。
src/sql/rewrite/ob_transform_join_elimination.cpp
浏览文件 @
d6394bff
...
...
@@ -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
)))
{
...
...
src/sql/rewrite/ob_transform_join_elimination.h
浏览文件 @
d6394bff
...
...
@@ -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
);
...
...
src/sql/rewrite/ob_transform_left_join_to_anti.cpp
浏览文件 @
d6394bff
...
...
@@ -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
;
...
...
src/sql/rewrite/ob_transform_utils.cpp
浏览文件 @
d6394bff
...
...
@@ -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
src/sql/rewrite/ob_transform_utils.h
浏览文件 @
d6394bff
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录