fix const propagate bug for calculating the partition
This commit is contained in:
@ -728,6 +728,7 @@ int ObTransformConstPropagate::collect_equal_pair_from_pullup(ObDMLStmt *stmt,
|
||||
ObRawExpr *select_expr = child_stmt->get_select_items().at(j).expr_;
|
||||
ExprConstInfo equal_info;
|
||||
equal_info.can_pullup_ = !is_null_side;
|
||||
equal_info.mem_equal_ = true;
|
||||
const uint64_t column_id = j + OB_APP_MIN_COLUMN_ID;
|
||||
if (OB_ISNULL(select_expr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
@ -754,8 +755,9 @@ int ObTransformConstPropagate::collect_equal_pair_from_pullup(ObDMLStmt *stmt,
|
||||
}
|
||||
} else if (NULL == equal_info.const_expr_) {
|
||||
// handle const info pull up
|
||||
// case3: select * from (select c1 as a from t1 where c1 = 1) v, t2 where v.a = t2.c1; =>
|
||||
// select * from (select c1 as a from t1 where c1 = 1) v, t2 where 1 = t2.c1;
|
||||
// case3: select * from (select c1 as a from t1 where c1 = '1') v, t2 where v.a = t2.c1; =>
|
||||
// select * from (select c1 as a from t1 where c1 = '1') v, t2 where '1' = t2.c1;
|
||||
equal_info.mem_equal_ = false;
|
||||
if (OB_FAIL(collect_from_pullup_const_infos(child_stmt, select_expr, equal_info))) {
|
||||
LOG_WARN("failed to get expr from pullup const info", K(ret));
|
||||
}
|
||||
@ -1143,8 +1145,13 @@ int ObTransformConstPropagate::replace_internal(ObRawExpr *&cur_expr,
|
||||
LOG_WARN("invalid expr", K(ret));
|
||||
} else if (cur_expr != column_expr) {
|
||||
// do nothing
|
||||
} else if (expr_const_infos.at(i).mem_equal_) {
|
||||
can_replace = true;
|
||||
} else if (OB_FAIL(check_can_replace(cur_expr, parent_exprs, used_in_compare, can_replace))) {
|
||||
LOG_WARN("failed to check can replace", K(ret));
|
||||
}
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (!can_replace) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(check_need_cast_when_replace(cur_expr, parent_exprs, need_cast))) {
|
||||
|
@ -50,6 +50,7 @@ private:
|
||||
equal_infos_(),
|
||||
need_add_constraint_(PRE_CALC_RESULT_NONE),
|
||||
can_pullup_(false),
|
||||
mem_equal_(false),
|
||||
is_used_(false),
|
||||
is_complex_const_info_(false),
|
||||
multi_const_exprs_(),
|
||||
@ -67,6 +68,7 @@ private:
|
||||
common::ObSEArray<ObPCParamEqualInfo, 2> equal_infos_;
|
||||
PreCalcExprExpectResult need_add_constraint_;
|
||||
bool can_pullup_;
|
||||
bool mem_equal_; //param expr mem is const expr.
|
||||
bool is_used_;
|
||||
//record or/in predicate const exprs
|
||||
bool is_complex_const_info_;
|
||||
@ -80,6 +82,7 @@ private:
|
||||
K_(equal_infos),
|
||||
K_(need_add_constraint),
|
||||
K_(can_pullup),
|
||||
K_(mem_equal),
|
||||
K_(is_used),
|
||||
K_(is_complex_const_info),
|
||||
K_(multi_const_exprs),
|
||||
|
@ -3215,12 +3215,20 @@ int ObTransformPredicateMoveAround::create_equal_exprs_for_insert(ObDelUpdStmt *
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("equal expr is null", K(ret));
|
||||
}
|
||||
|
||||
ObRawExpr *sharding_expr = NULL;
|
||||
ObRawExprCopier copier(*ctx_->expr_factory_);
|
||||
ObArray<ObRawExpr *> column_exprs;
|
||||
if (OB_FAIL(ret) || NULL == ret_expr) {
|
||||
//do nothing
|
||||
} else if (OB_FAIL(ret_expr->pull_relation_id())) {
|
||||
LOG_WARN("failed to pull relation id and levels", K(ret));
|
||||
} else if (OB_FAIL(del_upd_stmt->get_sharding_conditions().push_back(ret_expr))) {
|
||||
} else if (OB_FAIL(ObRawExprUtils::extract_column_exprs(ret_expr, column_exprs))) {
|
||||
LOG_WARN("extract column exprs failed", K(ret));
|
||||
} else if (OB_FAIL(copier.add_skipped_expr(column_exprs))) {
|
||||
LOG_WARN("add skipped expr failed", K(ret));
|
||||
} else if (OB_FAIL(copier.copy(ret_expr, sharding_expr))) {
|
||||
LOG_WARN("failed to copy expr", K(ret));
|
||||
} else if (OB_FAIL(del_upd_stmt->get_sharding_conditions().push_back(sharding_expr))) {
|
||||
LOG_WARN("failed to add condition expr", K(ret));
|
||||
} else if (is_not_null && OB_FAIL(ObTransformUtils::add_param_not_null_constraint(*ctx_, constraints))) {
|
||||
LOG_WARN("failed to add param not null constraint", K(ret));
|
||||
|
Reference in New Issue
Block a user