Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Metz
oceanbase
提交
ae9ef477
O
oceanbase
项目概览
Metz
/
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看板
提交
ae9ef477
编写于
7月 14, 2021
作者:
O
obdev
提交者:
wangzelin.wzl
7月 14, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Patch bugfix from 3.1.x.
上级
86a8d6f4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
55 addition
and
74 deletion
+55
-74
src/sql/rewrite/ob_transform_outerjoin_limit_pushdown.cpp
src/sql/rewrite/ob_transform_outerjoin_limit_pushdown.cpp
+55
-71
src/sql/rewrite/ob_transform_outerjoin_limit_pushdown.h
src/sql/rewrite/ob_transform_outerjoin_limit_pushdown.h
+0
-3
未找到文件。
src/sql/rewrite/ob_transform_outerjoin_limit_pushdown.cpp
浏览文件 @
ae9ef477
...
...
@@ -102,9 +102,7 @@ int ObTransformOuterJoinLimitPushDown::check_basic(ObDMLStmt* stmt, OjLimitPushD
select_stmt
->
has_group_by
()
||
select_stmt
->
has_having
()
||
select_stmt
->
has_rollup
()
||
select_stmt
->
has_window_function
()
||
select_stmt
->
has_sequence
()
||
select_stmt
->
get_semi_infos
().
count
()
>
0
||
// disable meaningless distinct co-exists with orderby cases.
// distinct with limit only is allowed and no need special handling.
(
select_stmt
->
has_distinct
()
&&
select_stmt
->
has_order_by
()))
{
select_stmt
->
has_distinct
())
{
is_valid
=
false
;
}
else
if
(
OB_FAIL
(
check_limit
(
select_stmt
,
is_valid_limit
)))
{
LOG_WARN
(
"failed to check the validity of limit expr"
,
K
(
ret
));
...
...
@@ -421,22 +419,31 @@ int ObTransformOuterJoinLimitPushDown::check_validity_for_target_table(OjLimitPu
int
ObTransformOuterJoinLimitPushDown
::
do_transform
(
OjLimitPushDownHelper
&
helper
)
{
int
ret
=
OB_SUCCESS
;
TableItem
*
target_view_table
=
NULL
;
ObSelectStmt
*
ref_query
=
NULL
;
if
(
OB_ISNULL
(
helper
.
select_stmt_
)
||
OB_ISNULL
(
helper
.
target_table_
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid parameter in helper"
,
K
(
ret
));
}
else
if
(
helper
.
need_create_view_
&&
OB_FAIL
(
prepare_view_table
(
helper
.
select_stmt_
,
helper
.
target_table_
,
helper
.
extracted_conditions_
,
helper
.
saved_order_items_
,
helper
.
view_table_
)))
{
}
else
if
(
OB_FAIL
(
remove_and_copy_condition_orderby
(
helper
.
select_stmt_
,
helper
.
extracted_conditions_
,
helper
.
saved_order_items_
)))
{
LOG_WARN
(
"failed to do remove and copy for condition and orderby"
,
K
(
ret
));
}
else
if
(
helper
.
need_create_view_
&&
OB_FAIL
(
ObTransformUtils
::
create_view_with_table
(
helper
.
select_stmt_
,
ctx_
,
helper
.
target_table_
,
helper
.
view_table_
)))
{
LOG_WARN
(
"failed to prepare new view for pushing down"
,
K
(
ret
));
}
else
if
(
OB_ISNULL
(
helper
.
view_table_
)
||
!
helper
.
view_table_
->
is_generated_table
()
||
OB_ISNULL
(
ref_query
=
helper
.
view_table_
->
ref_query_
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid view table"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
pushdown_view_table
(
helper
.
select_stmt_
,
helper
.
view_table_
,
helper
.
extracted_conditions_
,
helper
.
saved_order_items_
,
!
helper
.
need_create_view_
,
helper
.
is_limit_only_
)))
{
helper
.
view_table_
,
helper
.
extracted_conditions_
,
helper
.
saved_order_items_
,
!
helper
.
need_create_view_
,
helper
.
is_limit_only_
)))
{
LOG_WARN
(
"failed to push down view table"
,
K
(
ret
));
}
else
{
/* do nothing */
}
...
...
@@ -449,32 +456,6 @@ int ObTransformOuterJoinLimitPushDown::do_transform(OjLimitPushDownHelper& helpe
return
ret
;
}
int
ObTransformOuterJoinLimitPushDown
::
prepare_view_table
(
ObSelectStmt
*
stmt
,
TableItem
*
target_table
,
ObIArray
<
ObRawExpr
*>&
extracted_conditions
,
ObIArray
<
OrderItem
>&
saved_order_items
,
TableItem
*&
view_table
)
{
int
ret
=
OB_SUCCESS
;
ObSelectStmt
*
ref_query
=
NULL
;
// before warpping with view, remove extracted condition exprs in upper stmt,
// and do condition exprs copy avoid being modified by create_view_with_table,
// which will be added back to the created view later.
// order by exprs have been copied at former collection stage.
if
(
OB_ISNULL
(
stmt
)
||
OB_ISNULL
(
target_table
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid stmt"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
remove_and_copy_condition_orderby
(
stmt
,
extracted_conditions
,
saved_order_items
)))
{
LOG_WARN
(
"failed to do remove and copy for condition and orderby"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObTransformUtils
::
create_view_with_table
(
stmt
,
ctx_
,
target_table
,
view_table
)))
{
LOG_WARN
(
"failed to create view with table"
,
K
(
ret
));
}
else
if
(
OB_ISNULL
(
view_table
)
||
!
view_table
->
is_generated_table
()
||
OB_ISNULL
(
ref_query
=
view_table
->
ref_query_
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"get unexpected view table"
,
K
(
ret
),
K
(
*
view_table
));
}
else
{
// do nothing
}
return
ret
;
}
int
ObTransformOuterJoinLimitPushDown
::
remove_and_copy_condition_orderby
(
ObSelectStmt
*
stmt
,
ObIArray
<
ObRawExpr
*>&
extracted_conditions
,
ObIArray
<
OrderItem
>&
saved_order_items
)
{
...
...
@@ -532,8 +513,6 @@ int ObTransformOuterJoinLimitPushDown::add_condition_expr_for_viewtable(
if
(
OB_ISNULL
(
generated_view
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid generated_view"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
append
(
generated_view
->
get_condition_exprs
(),
extracted_conditions
)))
{
LOG_WARN
(
"failed to append condition exprs back"
,
K
(
ret
));
}
else
if
(
need_rename
)
{
// renaming for saved condition expr from upper level
// after pushdown into generated_view condition exprs.
...
...
@@ -541,7 +520,10 @@ int ObTransformOuterJoinLimitPushDown::add_condition_expr_for_viewtable(
ObSEArray
<
ObRawExpr
*
,
16
>
new_column_exprs
;
for
(
int64_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
extracted_conditions
.
count
();
++
i
)
{
ObRawExpr
*
expr
=
extracted_conditions
.
at
(
i
);
if
(
OB_FAIL
(
ObRawExprUtils
::
extract_column_exprs
(
expr
,
old_column_exprs
)))
{
if
(
OB_ISNULL
(
expr
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid condition"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObRawExprUtils
::
extract_column_exprs
(
expr
,
old_column_exprs
)))
{
LOG_WARN
(
"failed to extract column expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObTransformUtils
::
convert_column_expr_to_select_expr
(
old_column_exprs
,
*
generated_view
,
new_column_exprs
)))
{
...
...
@@ -552,6 +534,11 @@ int ObTransformOuterJoinLimitPushDown::add_condition_expr_for_viewtable(
}
}
}
if
(
OB_SUCC
(
ret
))
{
if
(
OB_FAIL
(
append
(
generated_view
->
get_condition_exprs
(),
extracted_conditions
)))
{
LOG_WARN
(
"failed to append condition exprs back"
,
K
(
ret
));
}
else
{
/* do nothing */
}
}
return
ret
;
}
...
...
@@ -562,39 +549,36 @@ int ObTransformOuterJoinLimitPushDown::add_orderby_for_viewtable(
if
(
OB_ISNULL
(
generated_view
)
||
OB_ISNULL
(
upper_stmt
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid parameter"
,
K
(
ret
));
}
else
if
(
!
need_rename
)
{
// directly assign saved order items to generated_view
generated_view
->
get_order_items
().
reset
();
if
(
OB_FAIL
(
generated_view
->
get_order_items
().
assign
(
saved_order_items
)))
{
LOG_WARN
(
"assign new order items failed"
,
K
(
ret
));
}
else
{
/* do nothing */
}
}
else
{
// single table item generated_table into here.
}
else
if
(
need_rename
)
{
// order by column needs to be renamed before moving
// from upper_stmt to inner generated_view.
ObSEArray
<
ObRawExpr
*
,
16
>
old_order_exprs
;
ObSEArray
<
ObRawExpr
*
,
16
>
new_order_exprs
;
if
(
OB_FAIL
(
append
(
generated_view
->
get_order_items
(),
upper_stmt
->
get_order_items
())))
{
LOG_WARN
(
"failed to append order item"
,
K
(
ret
));
}
else
{
for
(
int64_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
upper_stmt
->
get_order_item_size
();
++
i
)
{
if
(
OB_FAIL
(
old_order_exprs
.
push_back
(
upper_stmt
->
get_order_items
().
at
(
i
).
expr_
)))
{
LOG_WARN
(
"failed to append order item"
,
K
(
ret
));
}
}
if
(
OB_SUCC
(
ret
))
{
if
(
OB_FAIL
(
ObTransformUtils
::
convert_column_expr_to_select_expr
(
old_order_exprs
,
*
generated_view
,
new_order_exprs
)))
{
LOG_WARN
(
"failed to convert columnexpr to select expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObTransformUtils
::
replace_expr_for_order_item
(
old_order_exprs
,
new_order_exprs
,
generated_view
->
get_order_items
())))
{
LOG_WARN
(
"failed to replace expr for order item"
,
K
(
ret
));
}
else
{
/* do nothing */
}
for
(
int64_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
saved_order_items
.
count
();
i
++
)
{
ObSEArray
<
ObRawExpr
*
,
16
>
old_order_exprs
;
ObSEArray
<
ObRawExpr
*
,
16
>
new_order_exprs
;
if
(
OB_ISNULL
(
saved_order_items
.
at
(
i
).
expr_
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObRawExprUtils
::
extract_column_exprs
(
saved_order_items
.
at
(
i
).
expr_
,
old_order_exprs
)))
{
LOG_WARN
(
"failed to extract column expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObTransformUtils
::
convert_column_expr_to_select_expr
(
old_order_exprs
,
*
generated_view
,
new_order_exprs
)))
{
LOG_WARN
(
"failed to convert columnexpr to select expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObTransformUtils
::
replace_expr
(
old_order_exprs
,
new_order_exprs
,
saved_order_items
.
at
(
i
).
expr_
)))
{
LOG_WARN
(
"failed to replace expr for order item"
,
K
(
ret
));
}
else
{
/* do nothing */
}
}
}
if
(
OB_SUCC
(
ret
))
{
if
(
OB_FAIL
(
append
(
generated_view
->
get_order_items
(),
saved_order_items
)))
{
LOG_WARN
(
"failed to append order item"
,
K
(
ret
));
}
else
{
/* do nothing */
}
}
return
ret
;
}
...
...
src/sql/rewrite/ob_transform_outerjoin_limit_pushdown.h
浏览文件 @
ae9ef477
...
...
@@ -88,9 +88,6 @@ private:
int
check_validity_for_target_table
(
OjLimitPushDownHelper
&
helper
,
bool
&
is_valid
);
int
prepare_view_table
(
ObSelectStmt
*
stmt
,
TableItem
*
target_table
,
ObIArray
<
ObRawExpr
*>&
extracted_conditions
,
ObIArray
<
OrderItem
>&
saved_order_items
,
TableItem
*&
view_table
);
int
pushdown_view_table
(
ObSelectStmt
*
stmt
,
TableItem
*
target_table
,
ObIArray
<
ObRawExpr
*>&
extracted_conditions
,
ObIArray
<
OrderItem
>&
saved_order_items
,
bool
need_rename
,
bool
is_limit_only
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录