Skip to content

Commit 0036ef5

Browse files
obdevwangzelin19961202
authored andcommitted
[CP] get_stmt_max_table_dop hung
1 parent 6df2e15 commit 0036ef5

10 files changed

+180
-15
lines changed

src/sql/optimizer/ob_optimizer.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,11 @@ int ObOptimizer::get_stmt_max_table_dop(ObDMLStmt &stmt,
293293
table_item->is_link_table() ||
294294
table_item->is_fake_cte_table() ||
295295
table_item->is_joined_table()) {
296-
/*do nothing*/
297-
} else if (table_item->is_temp_table() ||
298-
table_item->is_generated_table()) {
299-
if (OB_ISNULL(table_item->ref_query_)) {
300-
ret = OB_ERR_UNEXPECTED;
301-
LOG_WARN("get unexpected null", K(ret));
302-
} else if (OB_FAIL(SMART_CALL(get_stmt_max_table_dop(*table_item->ref_query_,
303-
max_table_dop)))) {
304-
LOG_WARN("failed to get stmt max table dop", K(ret));
305-
} else { /*do nothing*/ }
296+
} else if (table_item->is_temp_table()) {
297+
if (OB_FAIL(child_stmts.push_back(table_item->ref_query_))) {
298+
LOG_WARN("push back failed", K(ret));
299+
}
300+
} else if (table_item->is_generated_table()) {
306301
} else {
307302
uint64_t tids[OB_MAX_INDEX_PER_TABLE + 1];
308303
int64_t index_count = OB_MAX_INDEX_PER_TABLE + 1;

src/sql/rewrite/ob_transform_groupby_pushdown.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ int ObTransformGroupByPushdown::adjust_transform_types(uint64_t &transform_types
158158
return ret;
159159
}
160160

161+
int ObTransformGroupByPushdown::check_join_condition_contain_lob(ObDMLStmt &stmt, bool &is_valid)
162+
{
163+
int ret = OB_SUCCESS;
164+
bool has_lob = false;;
165+
ObSEArray<ObRawExpr *, 4> conditions;
166+
if (OB_FAIL(append(conditions, stmt.get_condition_exprs()))) {
167+
LOG_WARN("extract colum failed", K(ret));
168+
} else if (OB_FAIL(ObTransformUtils::get_on_conditions(stmt, conditions))) {
169+
LOG_WARN("failed to get all on conditions", K(ret));
170+
} else if (OB_FAIL(ObTransformUtils::check_exprs_contain_lob_type(conditions, has_lob))) {
171+
LOG_WARN("check lob failed", K(ret));
172+
} else {
173+
is_valid = !has_lob;
174+
}
175+
return ret;
176+
}
177+
161178
int ObTransformGroupByPushdown::check_groupby_push_down_validity(ObSelectStmt *stmt,
162179
bool &is_valid)
163180
{
@@ -203,6 +220,10 @@ int ObTransformGroupByPushdown::check_groupby_push_down_validity(ObSelectStmt *s
203220
// do nothing
204221
} else if (OB_FAIL(check_collation_validity(*stmt, is_valid))) {
205222
LOG_WARN("failed to check collation validity", K(ret));
223+
} else if (!is_valid) {
224+
// do nothing
225+
} else if (OB_FAIL(check_join_condition_contain_lob(*stmt, is_valid))) {
226+
LOG_WARN("check join condition contain clob failed", K(ret));
206227
}
207228
for (int64_t i = 0; OB_SUCC(ret) && is_valid && i < stmt->get_aggr_item_size(); ++i) {
208229
ObAggFunRawExpr *aggr_expr = NULL;

src/sql/rewrite/ob_transform_groupby_pushdown.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class ObTransformGroupByPushdown : public ObTransformRule
199199
ObIArray<ObSEArray<TableItem *, 4>> &trans_tables,
200200
bool disassemble_join = true);
201201
int check_hint_valid(ObDMLStmt &stmt, ObIArray<PushDownParam> &params, bool &is_valid);
202+
203+
int check_join_condition_contain_lob(ObDMLStmt &stmt, bool &is_valid);
202204
private:
203205
// help functions
204206
int64_t get_count_sum_num(const ObIArray<ObRawExpr *> &exprs)

src/sql/rewrite/ob_transform_or_expansion.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,8 @@ int ObTransformOrExpansion::check_basic_validity(const ObDMLStmt &stmt, bool &is
10101010
bool has_odd_func = false;
10111011
bool check_status = true;
10121012
is_valid = false;
1013+
ObSEArray<ObRawExpr *, 4> sel_exprs;
1014+
bool has_lob = false;
10131015
if (reached_max_times_for_or_expansion()) {
10141016
is_valid = false;
10151017
LOG_TRACE("reached max times for or expansion.", K(is_valid));
@@ -1025,8 +1027,15 @@ int ObTransformOrExpansion::check_basic_validity(const ObDMLStmt &stmt, bool &is
10251027
/*do nothing */
10261028
} else if (OB_FAIL(has_odd_function(stmt, has_odd_func))) {
10271029
LOG_WARN("failed to check has odd function", K(ret));
1028-
} else if (has_odd_func) {
1030+
} else if (has_odd_func) {
10291031
/*do nothing */
1032+
} else if (stmt.is_select_stmt() && OB_FAIL(static_cast<const ObSelectStmt &>(stmt).get_select_exprs(sel_exprs))) {
1033+
LOG_WARN("get select exprs failed", K(ret));
1034+
} else if (OB_FAIL(ObTransformUtils::check_exprs_contain_lob_type(sel_exprs, has_lob))) {
1035+
LOG_WARN("check exprs contain lob failed", K(ret));
1036+
} else if (has_lob) {
1037+
//do nothing
1038+
// } else {
10301039
} else {
10311040
is_valid = true;
10321041
}

src/sql/rewrite/ob_transform_project_pruning.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,63 @@ int ObTransformProjectPruning::transform_table_items(ObDMLStmt *&stmt,
121121
return ret;
122122
}
123123

124+
int ObTransformProjectPruning::is_const_expr(ObRawExpr* expr, bool &is_const)
125+
{
126+
int ret = OB_SUCCESS;
127+
is_const = false;
128+
if (OB_ISNULL(expr)) {
129+
ret = OB_ERR_UNEXPECTED;
130+
LOG_WARN("unexpect null expr", K(ret));
131+
} else if (expr->is_const_expr()) {
132+
is_const = true;
133+
} else if (expr->is_set_op_expr()) {
134+
is_const = true;
135+
for (int64_t i = 0; OB_SUCC(ret) && is_const && i < expr->get_param_count(); ++i) {
136+
if (OB_FAIL(SMART_CALL(is_const_expr(expr->get_param_expr(i), is_const)))) {
137+
LOG_WARN("failed to check is const expr", K(ret));
138+
}
139+
}
140+
}
141+
return ret;
142+
}
143+
144+
int ObTransformProjectPruning::check_transform_validity(const ObSelectStmt &stmt, bool &is_valid)
145+
{
146+
int ret = OB_SUCCESS;
147+
is_valid = false;
148+
bool is_const = false;
149+
bool has_assign = true;
150+
if (stmt.has_distinct() || stmt.is_scala_group_by() ||
151+
stmt.is_recursive_union() || (stmt.is_set_stmt() && stmt.is_set_distinct()) ||
152+
stmt.is_hierarchical_query()) {
153+
// do nothing
154+
} else if (OB_FAIL(ObTransformUtils::check_has_assignment(stmt, has_assign))) {
155+
LOG_WARN("check has assign failed", K(ret));
156+
} else if (has_assign) {
157+
//do nothing
158+
} else if (stmt.get_select_item_size() == 1
159+
&& OB_FAIL(is_const_expr(stmt.get_select_item(0).expr_, is_const))) {
160+
LOG_WARN("failed to check is const expr", K(ret));
161+
} else if (is_const) {
162+
// do nothing, only with a dummy output
163+
} else if (stmt.is_set_stmt()) {
164+
is_valid = true;
165+
const ObIArray<ObSelectStmt*> &child_stmts = stmt.get_set_query();
166+
ObRawExpr *order_expr = NULL;
167+
for (int64_t i = 0; OB_SUCC(ret) && is_valid && i < child_stmts.count(); ++i) {
168+
if (OB_ISNULL(child_stmts.at(i))) {
169+
ret = OB_ERR_UNEXPECTED;
170+
LOG_WARN("child query is null", K(ret));
171+
} else if (OB_FAIL(SMART_CALL(check_transform_validity(*child_stmts.at(i), is_valid)))) {
172+
LOG_WARN("failed to check transform validity", K(ret));
173+
}
174+
}
175+
} else {
176+
is_valid = true;
177+
}
178+
return ret;
179+
}
180+
124181
int ObTransformProjectPruning::project_pruning(const uint64_t table_id,
125182
ObSelectStmt &child_stmt,
126183
ObDMLStmt &upper_stmt,

src/sql/rewrite/ob_transform_project_pruning.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class ObTransformProjectPruning : public ObTransformRule
4646
virtual int check_hint_status(const ObDMLStmt &stmt, bool &need_trans) override;
4747
virtual int construct_transform_hint(ObDMLStmt &stmt, void *trans_params) override;
4848

49+
int is_const_expr(ObRawExpr* expr, bool &is_const);
50+
51+
int check_transform_validity(const ObSelectStmt &stmt, bool &is_valid);
52+
4953
int check_hint_allowed_prune(ObSelectStmt &ref_query, bool &allowed);
5054
private:
5155
DISALLOW_COPY_AND_ASSIGN(ObTransformProjectPruning);

src/sql/rewrite/ob_transform_query_push_down.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,21 @@ int ObTransformQueryPushDown::check_select_item_push_down(ObSelectStmt *select_s
487487
bool check_status = false;
488488
bool is_select_expr_valid = false;
489489
ObSEArray<ObRawExpr*, 8> select_exprs;
490+
bool has_assign = false;
490491
if (OB_ISNULL(select_stmt) || OB_ISNULL(view_stmt)) {
491492
ret = OB_INVALID_ARGUMENT;
492493
LOG_WARN("stmt is NULL", K(select_stmt), K(view_stmt), K(ret));
493494
} else if (OB_FAIL(check_select_item_subquery(*select_stmt, *view_stmt, check_status))) {
494495
LOG_WARN("failed to check select item has subquery", K(ret));
495496
} else if (!check_status) {
496497
can_be = false;
497-
} else if (view_stmt->is_contains_assignment() || select_stmt->is_contains_assignment()) {
498+
} else if (OB_FAIL(ObTransformUtils::check_has_assignment(*view_stmt, has_assign))) {
499+
LOG_WARN("check has assign failed", K(ret));
500+
} else if (has_assign) {
501+
can_be = false;
502+
} else if (OB_FAIL(ObTransformUtils::check_has_assignment(*select_stmt, has_assign))) {
503+
LOG_WARN("check has assign failed", K(ret));
504+
} else if (has_assign) {
498505
can_be = false;
499506
} else if (OB_FAIL(view_stmt->get_select_exprs(select_exprs))) {
500507
LOG_WARN("failed to get select exprs", K(ret));
@@ -582,15 +589,19 @@ int ObTransformQueryPushDown::check_where_condition_push_down(ObSelectStmt *sele
582589
bool &can_be)
583590
{
584591
int ret = OB_SUCCESS;
592+
bool has_assign = false;
585593
can_be = false;
586594
transform_having = false;
587595
if (OB_ISNULL(select_stmt) || OB_ISNULL(view_stmt)) {
588596
ret = OB_INVALID_ARGUMENT;
589597
LOG_WARN("stmt is NULL", K(view_stmt), K(ret));
590598
} else if (view_stmt->is_set_stmt() ||
591599
view_stmt->has_limit() ||
592-
view_stmt->has_window_function() ||
593-
view_stmt->is_contains_assignment()) {
600+
view_stmt->has_window_function()) {
601+
can_be = false;
602+
} else if (OB_FAIL(ObTransformUtils::check_has_assignment(*view_stmt, has_assign))) {
603+
LOG_WARN("check has assign failed", K(ret));
604+
} else if (has_assign) {
594605
can_be = false;
595606
} else if (view_stmt->has_group_by() || view_stmt->has_rollup()) {
596607
bool is_invalid = false;

src/sql/rewrite/ob_transform_utils.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10601,6 +10601,61 @@ int ObTransformUtils::create_spj_and_pullup_correlated_exprs_for_set(ObSelectStm
1060110601
return ret;
1060210602
}
1060310603

10604+
int ObTransformUtils::check_exprs_contain_lob_type(ObIArray<ObRawExpr *> &exprs, bool &has_lob)
10605+
{
10606+
int ret = OB_SUCCESS;
10607+
ObSEArray<ObRawExpr *, 4> col_exprs;
10608+
has_lob = false;
10609+
if (OB_FAIL(ObRawExprUtils::extract_column_exprs(exprs, col_exprs))) {
10610+
LOG_WARN("extract colum failed", K(ret));
10611+
}
10612+
for (int64_t i = 0; OB_SUCC(ret) && !has_lob && i < col_exprs.count(); i++) {
10613+
ObColumnRefRawExpr *col_expr = static_cast<ObColumnRefRawExpr *>(col_exprs.at(i));
10614+
if (OB_ISNULL(col_expr)) {
10615+
ret = OB_ERR_UNEXPECTED;
10616+
LOG_WARN("epxr is null", K(ret));
10617+
} else {
10618+
has_lob = (ObLobType == col_expr->get_result_type().get_type() ||
10619+
ObLongTextType == col_expr->get_result_type().get_type());
10620+
}
10621+
}
10622+
return ret;
10623+
}
10624+
10625+
int ObTransformUtils::check_expr_contain_lob_type(ObRawExpr *expr, bool &has_lob)
10626+
{
10627+
int ret = OB_SUCCESS;
10628+
ObSEArray<ObRawExpr *, 1> exprs;
10629+
if (OB_FAIL(exprs.push_back(expr))) {
10630+
LOG_WARN("push back failed", K(ret));
10631+
} else if (OB_FAIL(check_exprs_contain_lob_type(exprs, has_lob))) {
10632+
LOG_WARN("expr contains lob failed", K(ret));
10633+
}
10634+
return ret;
10635+
}
10636+
10637+
int ObTransformUtils::check_has_assignment(const ObDMLStmt &stmt, bool &has_assignment)
10638+
{
10639+
int ret = OB_SUCCESS;
10640+
ObSEArray<ObSelectStmt *, 4> childs;
10641+
has_assignment = stmt.is_contains_assignment();
10642+
if (has_assignment) {
10643+
//do nothing
10644+
} else if (OB_FAIL(stmt.get_child_stmts(childs))) {
10645+
LOG_WARN("get sel exprs failed", K(ret));
10646+
} else {
10647+
for (int64_t i=0; OB_SUCC(ret) && !has_assignment && i < childs.count(); i++) {
10648+
if (OB_ISNULL(childs.at(i))) {
10649+
ret = OB_ERR_UNEXPECTED;
10650+
LOG_WARN("stmt is null", K(ret));
10651+
} else if (SMART_CALL(check_has_assignment(*childs.at(i), has_assignment))) {
10652+
LOG_WARN("check_assignment failed", K(ret));
10653+
}
10654+
}
10655+
}
10656+
return ret;
10657+
}
10658+
1060410659
int ObTransformUtils::adjust_select_item_pos(ObIArray<ObRawExpr*> &right_select_exprs,
1060510660
ObSelectStmt *right_query)
1060610661
{

src/sql/rewrite/ob_transform_utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,13 @@ class ObTransformUtils
15971597
static int check_table_contain_in_semi(const ObDMLStmt *stmt,
15981598
const TableItem *table,
15991599
bool &is_contain);
1600+
1601+
static int check_has_assignment(const ObDMLStmt &stmt, bool &has_assignment);
1602+
1603+
static int check_exprs_contain_lob_type(ObIArray<ObRawExpr *> &exprs, bool &has_lob);
1604+
1605+
static int check_expr_contain_lob_type(ObRawExpr *expr, bool &has_lob);
1606+
16001607
private:
16011608
static int inner_get_lazy_left_join(ObDMLStmt *stmt,
16021609
TableItem *table,

src/sql/rewrite/ob_transform_view_merge.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ int ObTransformViewMerge::check_basic_validity(ObDMLStmt *parent_stmt,
482482
bool &can_be) {
483483
int ret = OB_SUCCESS;
484484
can_be = false;
485+
bool has_assignment = false;
485486
bool has_rownum_expr = false;
486487
bool has_ref_assign_user_var = false;
487488
bool force_merge = false;
@@ -508,11 +509,14 @@ int ObTransformViewMerge::check_basic_validity(ObDMLStmt *parent_stmt,
508509
|| !child_stmt->has_order_by())
509510
|| child_stmt->has_limit()
510511
|| child_stmt->get_aggr_item_size() != 0
511-
|| child_stmt->is_contains_assignment()
512512
|| child_stmt->has_window_function()
513513
|| child_stmt->has_sequence()
514514
|| child_stmt->has_ora_rowscn()) {
515515
can_be = false;
516+
} else if (OB_FAIL(ObTransformUtils::check_has_assignment(*child_stmt, has_assignment))) {
517+
LOG_WARN("check has assignment failed", K(ret));
518+
} else if (has_assignment) {
519+
can_be = false;
516520
} else if (OB_FAIL(child_stmt->has_rownum(has_rownum_expr))) {
517521
LOG_WARN("failed to check has rownum expr", K(ret));
518522
} else if (has_rownum_expr) {

0 commit comments

Comments
 (0)