Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Metz
oceanbase
提交
a0ff8aaa
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a0ff8aaa
编写于
8月 19, 2021
作者:
J
jz0
提交者:
wangzelin.wzl
8月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Patch bug fixes to opensource branch.
上级
10799a59
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
523 addition
and
764 deletion
+523
-764
src/sql/optimizer/ob_log_table_scan.cpp
src/sql/optimizer/ob_log_table_scan.cpp
+6
-3
src/sql/optimizer/ob_log_temp_table_insert.cpp
src/sql/optimizer/ob_log_temp_table_insert.cpp
+4
-2
src/sql/optimizer/ob_optimizer_util.cpp
src/sql/optimizer/ob_optimizer_util.cpp
+2
-0
src/sql/rewrite/ob_transform_or_expansion.cpp
src/sql/rewrite/ob_transform_or_expansion.cpp
+23
-21
src/sql/rewrite/ob_transform_or_expansion.h
src/sql/rewrite/ob_transform_or_expansion.h
+2
-2
src/sql/rewrite/ob_transform_query_push_down.cpp
src/sql/rewrite/ob_transform_query_push_down.cpp
+0
-2
src/sql/rewrite/ob_transform_simplify.cpp
src/sql/rewrite/ob_transform_simplify.cpp
+24
-17
src/sql/rewrite/ob_transform_simplify.h
src/sql/rewrite/ob_transform_simplify.h
+2
-2
src/sql/rewrite/ob_transform_utils.cpp
src/sql/rewrite/ob_transform_utils.cpp
+74
-18
src/sql/rewrite/ob_transform_utils.h
src/sql/rewrite/ob_transform_utils.h
+14
-0
unittest/sql/rewrite/result/test_transformer_plan_after_el.result
.../sql/rewrite/result/test_transformer_plan_after_el.result
+5
-5
unittest/sql/rewrite/result/test_transformer_plan_after_trans_aggr.result
...rite/result/test_transformer_plan_after_trans_aggr.result
+10
-14
unittest/sql/rewrite/result/test_transformer_stmt_after_el.result
.../sql/rewrite/result/test_transformer_stmt_after_el.result
+138
-0
unittest/sql/rewrite/result/test_transformer_stmt_after_trans_aggr.result
...rite/result/test_transformer_stmt_after_trans_aggr.result
+219
-678
未找到文件。
src/sql/optimizer/ob_log_table_scan.cpp
浏览文件 @
a0ff8aaa
...
...
@@ -685,9 +685,12 @@ int ObLogTableScan::extract_access_exprs(
}
else
if
(
OB_ISNULL
(
expr
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"expr is null"
,
K
(
col_idx
),
K
(
ret
));
}
else
if
(
OB_FAIL
(
expr
->
formalize
(
opt_ctx
->
get_session_info
())))
{
LOG_WARN
(
"failed to formalize the new expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
else
{
expr
->
set_ref_id
(
get_table_id
(),
column_schema
->
get_column_id
());
if
(
OB_FAIL
(
expr
->
formalize
(
opt_ctx
->
get_session_info
())))
{
LOG_WARN
(
"failed to formalize the new expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
}
if
(
OB_SUCC
(
ret
))
{
if
(
OB_FAIL
(
rowkey_exprs
.
push_back
(
expr
)))
{
...
...
src/sql/optimizer/ob_log_temp_table_insert.cpp
浏览文件 @
a0ff8aaa
...
...
@@ -43,8 +43,10 @@ int ObLogTempTableInsert::allocate_exchange_post(AllocExchContext* ctx)
LOG_WARN
(
"get unexpected null"
,
K
(
child
),
K
(
ret
));
}
else
if
(
child
->
get_sharding_info
().
is_distributed
())
{
sharding_info_
.
set_location_type
(
child
->
get_sharding_info
().
get_location_type
());
}
else
{
ret
=
sharding_info_
.
copy_with_part_keys
(
child
->
get_sharding_info
());
}
else
if
(
OB_FAIL
(
sharding_info_
.
copy_with_part_keys
(
child
->
get_sharding_info
())))
{
LOG_WARN
(
"failed to copy sharding info"
,
K
(
ret
));
}
else
if
(
sharding_info_
.
is_match_all
())
{
sharding_info_
.
set_location_type
(
OB_TBL_LOCATION_LOCAL
);
}
return
ret
;
}
...
...
src/sql/optimizer/ob_optimizer_util.cpp
浏览文件 @
a0ff8aaa
...
...
@@ -666,6 +666,8 @@ int ObOptimizerUtil::compute_const_exprs(
LOG_WARN
(
"failed to push back expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
}
else
if
(
T_BOOL
==
const_expr
->
get_expr_type
())
{
// is true/false will not be regarded as const
}
else
if
(
OB_FAIL
(
add_var_to_array_no_dup
(
const_exprs
,
common_expr
)))
{
LOG_WARN
(
"failed to push back expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
...
...
src/sql/rewrite/ob_transform_or_expansion.cpp
浏览文件 @
a0ff8aaa
...
...
@@ -647,7 +647,6 @@ int ObTransformOrExpansion::adjust_or_expansion_stmt(const int64_t transformed_e
ObRawExprFactory
*
expr_factory
=
NULL
;
ObRawExpr
*
transformed_expr
=
NULL
;
ObSEArray
<
ObQueryRefRawExpr
*
,
4
>
removed_subqueries
;
ObSEArray
<
ObQueryRefRawExpr
*
,
4
>
need_add_subqueries
;
if
(
OB_ISNULL
(
ctx_
)
||
OB_ISNULL
(
session_info
=
ctx_
->
session_info_
)
||
OB_ISNULL
(
expr_factory
=
ctx_
->
expr_factory_
))
{
ret
=
OB_INVALID_ARGUMENT
;
...
...
@@ -667,31 +666,22 @@ int ObTransformOrExpansion::adjust_or_expansion_stmt(const int64_t transformed_e
LOG_WARN
(
"null transformed expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
or_expansion_stmt
->
get_condition_exprs
().
remove
(
transformed_expr_pos
)))
{
LOG_WARN
(
"failed to remove condition expr"
,
K
(
ret
));
}
else
if
(
transformed_expr
->
has_flag
(
CNT_SUB_QUERY
)
&&
OB_FAIL
(
ObTransformUtils
::
extract_query_ref_expr
(
transformed_expr
,
removed_subqueries
)))
{
LOG_WARN
(
"failed to extract query ref expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObOptimizerUtil
::
remove_item
(
or_expansion_stmt
->
get_subquery_exprs
(),
removed_subqueries
)))
{
LOG_WARN
(
"failed to remove subquery exprs"
,
K
(
ret
));
}
else
if
(
T_OP_OR
==
transformed_expr
->
get_expr_type
())
{
ObSEArray
<
ObRawExpr
*
,
4
>
generated_exprs
;
if
(
OB_FAIL
(
create_expr_for_or_expr
(
*
transformed_expr
,
param_pos
,
can_union_distinct
,
generated_exprs
,
need_add_subqueries
)))
{
*
transformed_expr
,
param_pos
,
can_union_distinct
,
generated_exprs
)))
{
LOG_WARN
(
"failed to create expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
append
(
or_expansion_stmt
->
get_condition_exprs
(),
generated_exprs
)))
{
LOG_WARN
(
"failed to append expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
append
(
or_expansion_stmt
->
get_subquery_exprs
(),
need_add_subqueries
)))
{
LOG_WARN
(
"failed to append expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
}
else
if
(
T_OP_IN
==
transformed_expr
->
get_expr_type
())
{
ObSEArray
<
ObRawExpr
*
,
4
>
generated_exprs
;
if
(
OB_FAIL
(
create_expr_for_in_expr
(
*
transformed_expr
,
param_pos
,
can_union_distinct
,
generated_exprs
,
need_add_subqueries
)))
{
*
transformed_expr
,
param_pos
,
can_union_distinct
,
generated_exprs
)))
{
LOG_WARN
(
"failed to create expr"
,
K
(
ret
),
K
(
generated_exprs
));
}
else
if
(
OB_FAIL
(
append
(
or_expansion_stmt
->
get_condition_exprs
(),
generated_exprs
)))
{
LOG_WARN
(
"failed to append exprs"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
append
(
or_expansion_stmt
->
get_subquery_exprs
(),
need_add_subqueries
)))
{
LOG_WARN
(
"failed to append expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
}
else
{
...
...
@@ -701,13 +691,31 @@ int ObTransformOrExpansion::adjust_or_expansion_stmt(const int64_t transformed_e
if
(
OB_SUCC
(
ret
))
{
if
(
OB_FAIL
(
or_expansion_stmt
->
formalize_stmt
(
session_info
)))
{
LOG_WARN
(
"failed to formalize stmt"
,
K
(
ret
));
}
else
{
// clean unused subqueries
ObSEArray
<
ObRawExpr
*
,
4
>
relation_exprs
;
ObSEArray
<
ObQueryRefRawExpr
*
,
8
>
used_subquery_exprs
;
if
(
OB_FAIL
(
or_expansion_stmt
->
get_relation_exprs
(
relation_exprs
)))
{
LOG_WARN
(
"failed to get relation exprs"
);
}
else
if
(
OB_FAIL
(
ObTransformUtils
::
extract_query_ref_expr
(
relation_exprs
,
used_subquery_exprs
)))
{
LOG_WARN
(
"failed to get query exprs"
);
}
else
{
for
(
int64_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
or_expansion_stmt
->
get_subquery_exprs
().
count
();
++
i
)
{
ObQueryRefRawExpr
*
expr
=
or_expansion_stmt
->
get_subquery_exprs
().
at
(
i
);
if
(
ObOptimizerUtil
::
find_item
(
used_subquery_exprs
,
expr
))
{
// do nothing
}
else
if
(
OB_FAIL
(
ObOptimizerUtil
::
remove_item
(
or_expansion_stmt
->
get_subquery_exprs
(),
expr
)))
{
LOG_WARN
(
"failed to remove item from subquery exprs"
,
K
(
ret
));
}
}
}
}
}
return
ret
;
}
int
ObTransformOrExpansion
::
create_expr_for_in_expr
(
const
ObRawExpr
&
transformed_expr
,
const
int64_t
param_pos
,
bool
can_union_distinct
,
ObIArray
<
ObRawExpr
*>&
generated_exprs
,
ObIArray
<
ObQueryRefRawExpr
*>&
subqueries
)
bool
can_union_distinct
,
ObIArray
<
ObRawExpr
*>&
generated_exprs
)
{
int
ret
=
OB_SUCCESS
;
const
ObRawExpr
*
left_expr
=
NULL
;
...
...
@@ -735,8 +743,6 @@ int ObTransformOrExpansion::create_expr_for_in_expr(const ObRawExpr& transformed
}
else
if
(
OB_UNLIKELY
(
param_pos
<
0
)
||
OB_UNLIKELY
(
param_pos
>=
right_expr
->
get_param_count
()))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"unexpected expr pos"
,
K
(
param_pos
),
K
(
right_expr
->
get_param_count
()),
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObTransformUtils
::
extract_query_ref_expr
(
const_cast
<
ObRawExpr
*>
(
left_expr
),
subqueries
)))
{
LOG_WARN
(
"failed to extract query ref expr"
,
K
(
ret
));
}
for
(
int64_t
i
=
can_union_distinct
?
param_pos
:
0
;
OB_SUCC
(
ret
)
&&
i
<=
param_pos
;
++
i
)
{
if
(
OB_FAIL
(
ObRawExprUtils
::
create_equal_expr
(
...
...
@@ -758,7 +764,7 @@ int ObTransformOrExpansion::create_expr_for_in_expr(const ObRawExpr& transformed
}
int
ObTransformOrExpansion
::
create_expr_for_or_expr
(
ObRawExpr
&
transformed_expr
,
const
int64_t
param_pos
,
bool
can_union_distinct
,
common
::
ObIArray
<
ObRawExpr
*>&
generated_exprs
,
ObIArray
<
ObQueryRefRawExpr
*>&
subqueries
)
bool
can_union_distinct
,
common
::
ObIArray
<
ObRawExpr
*>&
generated_exprs
)
{
int
ret
=
OB_SUCCESS
;
ObRawExprFactory
*
expr_factory
=
NULL
;
...
...
@@ -780,16 +786,12 @@ int ObTransformOrExpansion::create_expr_for_or_expr(ObRawExpr& transformed_expr,
LOG_WARN
(
"null expr"
,
K
(
ret
));
}
else
if
(
i
==
param_pos
)
{
temp_expr
=
expr
;
if
(
OB_FAIL
(
ObTransformUtils
::
extract_query_ref_expr
(
expr
,
subqueries
)))
{
LOG_WARN
(
"failed to extract query ref expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObTransformUtils
::
flatten_expr
(
temp_expr
,
generated_exprs
)))
{
if
(
OB_FAIL
(
ObTransformUtils
::
flatten_expr
(
temp_expr
,
generated_exprs
)))
{
LOG_WARN
(
"failed to flatten expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
}
else
if
(
can_union_distinct
)
{
/*do nothing */
}
else
if
(
OB_FAIL
(
ObTransformUtils
::
extract_query_ref_expr
(
expr
,
subqueries
)))
{
LOG_WARN
(
"failed to extract query ref expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
ObRawExprUtils
::
build_lnnvl_expr
(
*
expr_factory
,
expr
,
temp_expr
)))
{
LOG_WARN
(
"failed to create lnnvl expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
generated_exprs
.
push_back
(
temp_expr
)))
{
...
...
src/sql/rewrite/ob_transform_or_expansion.h
浏览文件 @
a0ff8aaa
...
...
@@ -70,9 +70,9 @@ private:
int
adjust_or_expansion_stmt
(
const
int64_t
transformed_expr_pos
,
const
int64_t
param_pos
,
bool
can_union_distinct
,
ObSelectStmt
*&
or_expansion_stmt
);
int
create_expr_for_in_expr
(
const
ObRawExpr
&
transformed_expr
,
const
int64_t
param_pos
,
bool
can_union_distinct
,
common
::
ObIArray
<
ObRawExpr
*>&
generated_exprs
,
common
::
ObIArray
<
ObQueryRefRawExpr
*>&
subqueries
);
common
::
ObIArray
<
ObRawExpr
*>&
generated_exprs
);
int
create_expr_for_or_expr
(
ObRawExpr
&
transformed_expr
,
const
int64_t
param_pos
,
bool
can_union_distinct
,
common
::
ObIArray
<
ObRawExpr
*>&
generated_exprs
,
common
::
ObIArray
<
ObQueryRefRawExpr
*>&
subqueries
);
common
::
ObIArray
<
ObRawExpr
*>&
generated_exprs
);
int
preprocess_or_condition
(
ObSelectStmt
*
select_stmt
,
ObRawExpr
*
expr
,
bool
&
can_union_distinct
,
bool
&
spj_is_unique
,
bool
&
skip_this_cond
,
const
bool
is_topk
);
...
...
src/sql/rewrite/ob_transform_query_push_down.cpp
浏览文件 @
a0ff8aaa
...
...
@@ -577,8 +577,6 @@ int ObTransformQueryPushDown::push_down_stmt_exprs(ObSelectStmt* select_stmt, Ob
LOG_WARN
(
"view stmt append subquery failed"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
adjust_stmt_hints
(
select_stmt
,
view_stmt
)))
{
LOG_WARN
(
"failed to adjust hints"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
view_stmt
->
adjust_subquery_list
()))
{
LOG_WARN
(
"failed to adjust subquery list"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
view_stmt
->
adjust_subquery_stmt_parent
(
select_stmt
,
view_stmt
)))
{
LOG_WARN
(
"failed to adjust subquery stmt parent"
,
K
(
ret
));
}
else
{
...
...
src/sql/rewrite/ob_transform_simplify.cpp
浏览文件 @
a0ff8aaa
...
...
@@ -722,7 +722,8 @@ int ObTransformSimplify::replace_is_null_condition(ObDMLStmt* stmt, bool& trans_
if
(
OB_ISNULL
(
cond
=
stmt
->
get_condition_expr
(
i
)))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"condition expr is null"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
inner_replace_is_null_condition
(
stmt
,
stmt
->
get_condition_exprs
().
at
(
i
),
is_happened
)))
{
}
else
if
(
OB_FAIL
(
inner_replace_is_null_condition
(
stmt
,
stmt
->
get_condition_exprs
().
at
(
i
),
ObTransformUtils
::
NULLABLE_SCOPE
::
NS_WHERE
,
is_happened
)))
{
LOG_WARN
(
"failed to replace is null expr"
,
K
(
ret
));
}
else
{
trans_happened
|=
is_happened
;
...
...
@@ -731,7 +732,8 @@ int ObTransformSimplify::replace_is_null_condition(ObDMLStmt* stmt, bool& trans_
if
(
OB_SUCC
(
ret
)
&&
stmt
->
is_select_stmt
())
{
ObSelectStmt
*
sel_stmt
=
static_cast
<
ObSelectStmt
*>
(
stmt
);
for
(
int64_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
sel_stmt
->
get_having_expr_size
();
++
i
)
{
if
(
OB_FAIL
(
inner_replace_is_null_condition
(
sel_stmt
,
sel_stmt
->
get_having_exprs
().
at
(
i
),
is_happened
)))
{
if
(
OB_FAIL
(
inner_replace_is_null_condition
(
sel_stmt
,
sel_stmt
->
get_having_exprs
().
at
(
i
),
ObTransformUtils
::
NULLABLE_SCOPE
::
NS_TOP
,
is_happened
)))
{
LOG_WARN
(
"failed to replace is null expr"
,
K
(
ret
));
}
else
{
trans_happened
|=
is_happened
;
...
...
@@ -742,7 +744,7 @@ int ObTransformSimplify::replace_is_null_condition(ObDMLStmt* stmt, bool& trans_
return
ret
;
}
int
ObTransformSimplify
::
inner_replace_is_null_condition
(
ObDMLStmt
*
stmt
,
ObRawExpr
*&
expr
,
bool
&
trans_happened
)
int
ObTransformSimplify
::
inner_replace_is_null_condition
(
ObDMLStmt
*
stmt
,
ObRawExpr
*&
expr
,
int
nullable_scope
,
bool
&
trans_happened
)
{
int
ret
=
OB_SUCCESS
;
bool
is_happened
=
false
;
...
...
@@ -764,7 +766,7 @@ int ObTransformSimplify::inner_replace_is_null_condition(ObDMLStmt* stmt, ObRawE
if
(
OB_ISNULL
(
temp
=
op_expr
->
get_param_expr
(
i
)))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"null expr"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
SMART_CALL
(
inner_replace_is_null_condition
(
stmt
,
temp
,
is_happened
))))
{
}
else
if
(
OB_FAIL
(
SMART_CALL
(
inner_replace_is_null_condition
(
stmt
,
temp
,
nullable_scope
,
is_happened
))))
{
LOG_WARN
(
"failed to replace is null expr"
,
K
(
ret
));
}
else
{
trans_happened
|=
is_happened
;
...
...
@@ -775,7 +777,7 @@ int ObTransformSimplify::inner_replace_is_null_condition(ObDMLStmt* stmt, ObRawE
if
(
OB_SUCC
(
ret
)
&&
(
T_OP_IS
==
expr
->
get_expr_type
()
||
T_OP_IS_NOT
==
expr
->
get_expr_type
()))
{
// do transforamtion for its own exprs
if
(
OB_FAIL
(
do_replace_is_null_condition
(
stmt
,
expr
,
is_happened
)))
{
if
(
OB_FAIL
(
do_replace_is_null_condition
(
stmt
,
expr
,
nullable_scope
,
is_happened
)))
{
LOG_WARN
(
"failed to replace is null condition"
,
K
(
ret
));
}
else
{
trans_happened
|=
is_happened
;
...
...
@@ -794,7 +796,7 @@ int ObTransformSimplify::inner_replace_is_null_condition(ObDMLStmt* stmt, ObRawE
return
ret
;
}
int
ObTransformSimplify
::
do_replace_is_null_condition
(
ObDMLStmt
*
stmt
,
ObRawExpr
*&
expr
,
bool
&
trans_happened
)
int
ObTransformSimplify
::
do_replace_is_null_condition
(
ObDMLStmt
*
stmt
,
ObRawExpr
*&
expr
,
int
nullable_scope
,
bool
&
trans_happened
)
{
int
ret
=
OB_SUCCESS
;
trans_happened
=
false
;
...
...
@@ -820,6 +822,7 @@ int ObTransformSimplify::do_replace_is_null_condition(ObDMLStmt* stmt, ObRawExpr
is_expected
=
true
;
}
else
if
(
child_0
->
is_column_ref_expr
())
{
bool
sql_auto_is_null
=
false
;
bool
found
=
false
;
const
ObColumnRefRawExpr
*
col_expr
=
static_cast
<
const
ObColumnRefRawExpr
*>
(
child_0
);
uint64_t
table_id
=
col_expr
->
get_table_id
();
if
(
OB_FAIL
(
ctx_
->
session_info_
->
get_sql_auto_is_null
(
sql_auto_is_null
)))
{
...
...
@@ -830,6 +833,11 @@ int ObTransformSimplify::do_replace_is_null_condition(ObDMLStmt* stmt, ObRawExpr
!
col_expr
->
get_result_type
().
is_date
()
&&
!
(
sql_auto_is_null
&&
col_expr
->
is_auto_increment
())))
{
if
(
OB_FAIL
(
is_expected_table_for_replace
(
stmt
,
table_id
,
is_expected
)))
{
LOG_WARN
(
"fail to judge expected table"
,
K
(
ret
),
K
(
table_id
),
K
(
is_expected
));
}
else
if
(
is_expected
&&
OB_FAIL
(
ObTransformUtils
::
check_nullable_exprs_in_groupby
(
stmt
,
const_cast
<
ObColumnRefRawExpr
*>
(
col_expr
),
nullable_scope
,
found
)))
{
LOG_WARN
(
"fail to checkin nullable in groupby"
,
K
(
ret
),
K
(
table_id
),
K
(
is_expected
));
}
else
if
(
found
)
{
is_expected
=
false
;
}
}
}
...
...
@@ -1008,19 +1016,18 @@ int ObTransformSimplify::is_expected_table_for_replace(ObDMLStmt* stmt, uint64_t
LOG_WARN
(
"fail to judge expected table"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
}
else
{
// table from current stmt
if
(
table_item
->
is_basic_table
()
||
table_item
->
is_generated_table
())
{
bool
is_on_null_side
=
false
;
if
(
OB_FAIL
(
ObOptimizerUtil
::
is_table_on_null_side
(
stmt
,
table_item
->
table_id_
,
is_on_null_side
)))
{
LOG_WARN
(
"check is table on null side failed"
,
K
(
ret
),
K
(
*
table_item
));
}
else
{
is_expected
=
!
is_on_null_side
;
}
}
else
if
(
table_item
->
is_basic_table
())
{
bool
is_on_null_side
=
false
;
if
(
OB_FAIL
(
ObOptimizerUtil
::
is_table_on_null_side
(
stmt
,
table_item
->
table_id_
,
is_on_null_side
)))
{
LOG_WARN
(
"check is table on null side failed"
,
K
(
ret
),
K
(
*
table_item
));
}
else
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"unexpected table item type"
,
K_
(
table_item
->
type
));
is_expected
=
!
is_on_null_side
;
}
}
else
if
(
table_item
->
is_generated_table
())
{
is_expected
=
false
;
}
else
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"unexpected table item type"
,
K_
(
table_item
->
type
));
}
return
ret
;
}
...
...
src/sql/rewrite/ob_transform_simplify.h
浏览文件 @
a0ff8aaa
...
...
@@ -38,8 +38,8 @@ private:
int
having_filter_can_be_pushed_down
(
const
ObRawExpr
*
having_filter
,
const
ObSelectStmt
&
select_stmt
,
const
bool
has_rownum
,
bool
&
can_be
);
int
replace_is_null_condition
(
ObDMLStmt
*
stmt
,
bool
&
trans_happened
);
int
inner_replace_is_null_condition
(
ObDMLStmt
*
stmt
,
ObRawExpr
*&
expr
,
bool
&
trans_happened
);
int
do_replace_is_null_condition
(
ObDMLStmt
*
stmt
,
ObRawExpr
*&
expr
,
bool
&
trans_happened
);
int
inner_replace_is_null_condition
(
ObDMLStmt
*
stmt
,
ObRawExpr
*&
expr
,
int
nullalbe_scope
,
bool
&
trans_happened
);
int
do_replace_is_null_condition
(
ObDMLStmt
*
stmt
,
ObRawExpr
*&
expr
,
int
nullalbe_scope
,
bool
&
trans_happened
);
int
replace_op_null_condition
(
ObDMLStmt
*
stmt
,
bool
&
trans_happened
);
int
replace_cmp_null_condition
(
ObRawExpr
*&
expr
,
const
ObDMLStmt
&
stmt
,
const
ParamStore
&
param_store
,
bool
&
trans_happened
);
...
...
src/sql/rewrite/ob_transform_utils.cpp
浏览文件 @
a0ff8aaa
...
...
@@ -2091,6 +2091,63 @@ int ObTransformUtils::find_expr(const ObIArray<const ObRawExpr*>& source, const
return
ret
;
}
int
ObTransformUtils
::
check_nullable_exprs_in_groupby
(
ObDMLStmt
*
stmt
,
ObRawExpr
*
expr
,
int
nullable_scope
,
bool
&
found
)
{
int
ret
=
OB_SUCCESS
;
found
=
false
;
ObSelectStmt
*
select_stmt
=
NULL
;
if
(
OB_ISNULL
(
stmt
)
||
OB_ISNULL
(
expr
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid input"
,
K
(
stmt
),
K
(
expr
));
}
else
if
(
!
stmt
->
is_select_stmt
())
{
// do nothing
}
else
if
(
FALSE_IT
(
select_stmt
=
static_cast
<
ObSelectStmt
*>
(
stmt
)))
{
// do nothing
}
else
if
(
NULLABLE_SCOPE
::
NS_TOP
==
nullable_scope
&&
OB_FAIL
(
find_expr_in_groupby_clause
(
select_stmt
,
expr
,
found
)))
{
LOG_WARN
(
"failed to find expr in group by clause"
,
K
(
ret
));
}
else
if
(
!
found
&&
NULLABLE_SCOPE
::
NS_TOP
==
nullable_scope
&&
OB_FAIL
(
find_expr_in_scala_groupby
(
select_stmt
,
expr
,
found
)))
{
LOG_WARN
(
"failed to find expr in scala group by"
,
K
(
ret
));
}
else
{
// todo: other nullable scenarios
}
return
ret
;
}
int
ObTransformUtils
::
find_expr_in_groupby_clause
(
ObSelectStmt
*
select_stmt
,
ObRawExpr
*
column_expr
,
bool
&
found
)
{
int
ret
=
OB_SUCCESS
;
found
=
false
;
if
(
OB_ISNULL
(
select_stmt
)
||
OB_ISNULL
(
column_expr
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid input"
,
K
(
select_stmt
),
K
(
column_expr
));
// case: select c1 + c2 from t group by rollup (c1+c2);
// can't deduce c1 + c2 as not null even if c1 and c2 are not null
//const ObIArray<ObRawExpr*> &rollup_exprs = select_stmt->get_rollup_exprs();
}
else
if
(
ObOptimizerUtil
::
find_item
(
select_stmt
->
get_rollup_exprs
(),
column_expr
))
{
found
=
true
;
}
return
ret
;
}
int
ObTransformUtils
::
find_expr_in_scala_groupby
(
ObSelectStmt
*
select_stmt
,
ObRawExpr
*
expr
,
bool
&
found
)
{
int
ret
=
OB_SUCCESS
;
found
=
false
;
if
(
OB_ISNULL
(
select_stmt
)
||
OB_ISNULL
(
expr
))
{
ret
=
OB_ERR_UNEXPECTED
;
LOG_WARN
(
"invalid input"
,
K
(
select_stmt
),
K
(
expr
));
}
else
if
(
select_stmt
->
is_scala_group_by
()
&&
(
expr
->
is_column_ref_expr
()
||
(
expr
->
is_aggr_expr
()
&&
T_FUN_COUNT
!=
expr
->
get_expr_type
())))
{
// case: select * from t1 where (c1, c2) not in (select pk, max(pk) from t2);
// can't deduce pk and max(pk) as not null when t2 is empty
found
=
true
;
}
return
ret
;
}
/**
* column <=> ? or ? <=> column
* column is ? or column != ?
...
...
@@ -7045,29 +7102,28 @@ int ObTransformUtils::extract_column_contained_expr(
}
else
if
(
is_stack_overflow
)
{
ret
=
OB_SIZE_OVERFLOW
;
LOG_WARN
(
"too deep recursive"
,
K
(
ret
));
}
else
if
(
!
expr
->
get_expr_levels
().
has_member
(
stmt_level
))
{
}
else
if
(
!
(
expr
->
get_expr_levels
().
has_member
(
stmt_level
)
||
expr
->
has_flag
(
CNT_SUB_QUERY
)
))
{
/*do nothing */
}
else
if
(
!
expr
->
is_query_ref_expr
()
&&
!
expr
->
get_relation_ids
().
is_empty
())
{
if
(
!
expr
->
is_column_ref_expr
()
&&
!
expr
->
is_aggr_expr
()
&&
!
expr
->
is_win_func_expr
()
&&
expr
->
get_expr_levels
().
num_members
()
==
1
&&
!
ObRawExprUtils
::
find_expr
(
contain_column_exprs
,
expr
)
&&
OB_FAIL
(
contain_column_exprs
.
push_back
(
expr
)))
{
LOG_WARN
(
"failed to push back expr"
,
K
(
ret
));
}
else
{
for
(
int64_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
expr
->
get_param_count
();
++
i
)
{
if
(
OB_FAIL
(
SMART_CALL
(
extract_column_contained_expr
(
expr
->
get_param_expr
(
i
),
stmt_level
,
contain_column_exprs
))))
{
LOG_WARN
(
"failed to extract column contained expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
}
}
}
else
if
(
expr
->
is_query_ref_expr
())
{
if
(
OB_FAIL
(
extract_stmt_column_contained_expr
(
}
else
if
(
expr
->
is_query_ref_expr
()
&&
expr
->
get_expr_level
()
==
stmt_level
)
{
if
(
OB_FAIL
(
contain_column_exprs
.
push_back
(
expr
)))
{
LOG_WARN
(
"failed to push back expr into column array"
,
K
(
ret
));
}
else
if
(
OB_FAIL
(
extract_stmt_column_contained_expr
(
static_cast
<
ObQueryRefRawExpr
*>
(
expr
)
->
get_ref_stmt
(),
stmt_level
,
contain_column_exprs
)))
{
LOG_WARN
(
"failed to extract stmt column contained expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
}
else
{
/*do nothing*/
}
else
if
(
!
expr
->
get_relation_ids
().
is_empty
()
&&
!
expr
->
is_column_ref_expr
()
&&
!
expr
->
is_aggr_expr
()
&&
!
expr
->
is_win_func_expr
()
&&
expr
->
get_expr_levels
().
num_members
()
==
1
&&
!
ObRawExprUtils
::
find_expr
(
contain_column_exprs
,
expr
)
&&
OB_FAIL
(
contain_column_exprs
.
push_back
(
expr
)))
{
LOG_WARN
(
"failed to push back expr"
,
K
(
ret
));
}
else
{
for
(
int64_t
i
=
0
;
OB_SUCC
(
ret
)
&&
i
<
expr
->
get_param_count
();
++
i
)
{
if
(
OB_FAIL
(
SMART_CALL
(
extract_column_contained_expr
(
expr
->
get_param_expr
(
i
),
stmt_level
,
contain_column_exprs
))))
{
LOG_WARN
(
"failed to extract column contained expr"
,
K
(
ret
));
}
else
{
/*do nothing*/
}
}
}
return
ret
;
}
...
...
src/sql/rewrite/ob_transform_utils.h
浏览文件 @
a0ff8aaa
...
...
@@ -81,6 +81,14 @@ private:
};
public:
enum
NULLABLE_SCOPE
{
NS_FROM
=
1
<<
0
,
NS_WHERE
=
1
<<
1
,
NS_GROUPBY
=
1
<<
2
,
NS_HAVING
=
1
<<
3
,
NS_TOP
=
1
<<
4
};
static
int
is_correlated_expr
(
const
ObRawExpr
*
expr
,
int32_t
correlated_level
,
bool
&
is_correlated
);
static
int
is_correlated_subquery
(
ObSelectStmt
*
subquery
,
...
...
@@ -268,6 +276,12 @@ public:
static
int
find_expr
(
const
ObIArray
<
OrderItem
>&
source
,
const
ObRawExpr
*
target
,
bool
&
bret
);
static
int
check_nullable_exprs_in_groupby
(
ObDMLStmt
*
stmt
,
ObRawExpr
*
expr
,
int
nullable_scope
,
bool
&
found
);
static
int
find_expr_in_groupby_clause
(
ObSelectStmt
*
select_stmt
,
ObRawExpr
*
column_expr
,
bool
&
found
);
static
int
find_expr_in_scala_groupby
(
ObSelectStmt
*
select_stmt
,
ObRawExpr
*
expr
,
bool
&
found
);
/**
* @brief is_null_propagate_type
* white list for null propagate expr
...
...
unittest/sql/rewrite/result/test_transformer_plan_after_el.result
浏览文件 @
a0ff8aaa
...
...
@@ -165,9 +165,9 @@ SQL: select * from t2 left join (select * from t1) as v on t2.c1 = v.c2 where (
=========================================
|ID|OPERATOR |NAME|EST. ROWS|COST|
-----------------------------------------
|0 |NESTED-LOOP JOIN| |0 |1
21
|
|1 | SUBPLAN SCAN |v |0 |1
21
|
|2 | TABLE SCAN |t1 |
100 |90
|
|0 |NESTED-LOOP JOIN| |0 |1
40
|
|1 | SUBPLAN SCAN |v |0 |1
40
|
|2 | TABLE SCAN |t1 |
0 |140
|
|3 | TABLE GET |t2 |1 |36 |
=========================================
...
...
@@ -175,9 +175,9 @@ Outputs & filters:
-------------------------------------
0 - output([t2.c1], [t2.c2], [t2.c3], [v.c1], [v.c2]), filter(nil),
conds(nil), nl_params_([v.c2])
1 - output([v.c2], [v.c1]), filter(
[(T_OP_IS, v.c2, NULL, 0)], [? > (T_OP_IS_NOT, v.c2, NULL, 0)]
),
1 - output([v.c2], [v.c1]), filter(
nil
),
access([v.c2], [v.c1])
2 - output([t1.c1], [t1.c2]), filter(
nil
),
2 - output([t1.c1], [t1.c2]), filter(
[(T_OP_IS, t1.c2, NULL, 0)], [? > (T_OP_IS_NOT, t1.c2, NULL, 0)], [(T_OP_IS_NOT, t1.c1, NULL, 0)]
),
access([t1.c1], [t1.c2]), partitions(p0)
3 - output([t2.c1], [t2.c2], [t2.c3]), filter(nil),
access([t2.c1], [t2.c2], [t2.c3]), partitions(p0)
...
...
unittest/sql/rewrite/result/test_transformer_plan_after_trans_aggr.result
浏览文件 @
a0ff8aaa
...
...
@@ -2025,23 +2025,19 @@ Outputs & filters:
*************** Case 84 ***************
SQL: select max(c3) from t9 where c2 is TRUE;
======================================================
|ID|OPERATOR |NAME |EST. ROWS|COST|
------------------------------------------------------
|0 |SCALAR GROUP BY| |1 |37 |
|1 | SUBPLAN SCAN |VIEW1 |1 |37 |
|2 | TABLE SCAN |t9(idx_t9,Reverse)|1 |37 |
======================================================
==============================================
|ID|OPERATOR |NAME |EST. ROWS|COST|
----------------------------------------------
|0 |SCALAR GROUP BY| |1 |97 |
|1 | TABLE SCAN |t9(idx_t9)|99 |78 |
==============================================
Outputs & filters:
-------------------------------------
0 - output([T_FUN_MAX(VIEW1.c3)]), filter(nil),
group(nil), agg_func([T_FUN_MAX(VIEW1.c3)])
1 - output([VIEW1.c3]), filter(nil),
access([VIEW1.c3])
2 - output([t9.c3]), filter([(T_OP_IS, t9.c2, 1, 0)], [(T_OP_IS_NOT, t9.c3, NULL, 0)]),
access([t9.c2], [t9.c3]), partitions(p0),
limit(1), offset(nil)
0 - output([T_FUN_MAX(t9.c3)]), filter(nil),
group(nil), agg_func([T_FUN_MAX(t9.c3)])
1 - output([t9.c3]), filter([(T_OP_IS, t9.c2, 1, 0)]),
access([t9.c2], [t9.c3]), partitions(p0)
*************** Case 85 ***************
SQL: select max(c3) from t9 where c2 = 1 and c1 = 1;
...
...
unittest/sql/rewrite/result/test_transformer_stmt_after_el.result
浏览文件 @
a0ff8aaa
...
...
@@ -12095,6 +12095,144 @@ SQL: select * from t2 left join (select * from t1) as v on t2.c1 = v.c2 where (
]
}
]
},
{
"item_type":"T_OP_IS_NOT",
"result_type": {
"meta": {
"type":"INT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":1,
"scale":0
},
"flag":1,
"calc_type": {
"type":"DECIMAL",
"collation":"binary",
"coercibility":"NUMERIC"
}
},
"expr_info": [
"CNT_CONST",
"CNT_COLUMN"
],
"rel_id": [
2
],
"expr_levels": [
0
],
"children": [
{
"item_type":"T_REF_COLUMN",
"result_type": {
"meta": {
"type":"INT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":11,
"scale":0
},
"flag":16387,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_COLUMN",
"CNT_COLUMN"
],
"rel_id": [
2
],
"table_id":-3,
"column_id":16,
"database_name":"",
"table_name":"v",
"synonym_name":"",
"synonym_db_name":"",
"column_name":"c1",
"expr_level":0,
"expr_levels": [
0
],
"column_flags":0,
"enum_set_values": [
],
"is_lob_column":false,
"is_unpivot_mocked_column":false,
"is_hidden":false
},
{
"item_type":"T_NULL",
"result_type": {
"meta": {
"type":"NULL",
"collation":"binary",
"coercibility":"IGNORABLE"
},
"accuracy": {
"length":0,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"NULL":"NULL"
}
},
{
"item_type":"T_BOOL",
"result_type": {
"meta": {
"type":"TINYINT",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":1,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"expr_info": [
"IS_CONST",
"CNT_CONST"
],
"rel_id": [
],
"value": {
"TINYINT":0
}
}
]
},
{
"item_type":"T_OP_EQ",
unittest/sql/rewrite/result/test_transformer_stmt_after_trans_aggr.result
浏览文件 @
a0ff8aaa
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录