fix mysqltest for FOR UPDATE rewrite

This commit is contained in:
obdev
2024-02-10 09:07:11 +00:00
committed by ob-robot
parent b528857934
commit 9f7f594b74
3 changed files with 28 additions and 1 deletions

View File

@ -163,6 +163,8 @@ int ObTransformTempTable::generate_with_clause(ObDMLStmt *&stmt, bool &trans_hap
OPT_TRACE("stmt containt oversize set stmt");
} else if (!enable_temp_table_transform || force_temp_table_inline) {
OPT_TRACE("session variable disable temp table transform");
} else if (stmt->has_for_update()) {
OPT_TRACE("stmt has for update, can not extract CTE");
} else if (OB_FAIL(parent_map.create(128, "TempTable"))) {
LOG_WARN("failed to init stmt map", K(ret));
} else if (OB_FAIL(ObTransformUtils::get_all_child_stmts(stmt, child_stmts, &parent_map))) {
@ -208,6 +210,7 @@ int ObTransformTempTable::expand_temp_table(ObIArray<TempTableInfo> &temp_table_
bool force_materia = false;
bool force_inline = false;
bool is_oversize_stmt = false;
bool has_for_update = false;
int64_t stmt_size = 0;
bool need_expand = false;
bool can_expand = true;
@ -219,6 +222,8 @@ int ObTransformTempTable::expand_temp_table(ObIArray<TempTableInfo> &temp_table_
LOG_WARN("check stmt size failed", K(ret));
} else if (OB_FAIL(ObTransformUtils::check_expand_temp_table_valid(helper.temp_table_query_, can_expand))) {
LOG_WARN("failed to check expand temp table valid", K(ret));
} else if (OB_FAIL(check_has_for_update(helper, has_for_update))) {
LOG_WARN("failed to check has for update", K(ret));
} else if (!can_expand) {
// do nothing
OPT_TRACE("CTE can not be expanded");
@ -229,6 +234,9 @@ int ObTransformTempTable::expand_temp_table(ObIArray<TempTableInfo> &temp_table_
} else if (force_inline) {
need_expand = true;
OPT_TRACE("hint force inline CTE");
} else if (lib::is_oracle_mode() && has_for_update) {
need_expand = true;
OPT_TRACE("stmt has FOR UPDATE, force inline CTE");
} else if (force_materia) {
//do nothing
OPT_TRACE("hint force materialize CTE");
@ -410,6 +418,24 @@ int ObTransformTempTable::check_stmt_has_cross_product(ObSelectStmt *stmt, bool
return ret;
}
int ObTransformTempTable::check_has_for_update(const ObDMLStmt::TempTableInfo &helper,
bool &has_for_update)
{
int ret = OB_SUCCESS;
has_for_update = false;
for (int64_t i = 0; OB_SUCC(ret) && i < helper.upper_stmts_.count(); ++i) {
const ObDMLStmt *upper_stmt = helper.upper_stmts_.at(i);
if (OB_ISNULL(upper_stmt)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("upper stmt is NULL", K(ret), K(i));
} else if (upper_stmt->has_for_update()) {
has_for_update = true;
break;
}
}
return ret;
}
/**
* @brief extract_common_subquery_as_cte
* 比较当前stmt的所有child stmt,

View File

@ -133,6 +133,8 @@ public:
const ObStmtMapInfo &map_info,
bool &is_match);
int check_has_for_update(const ObDMLStmt::TempTableInfo &helper, bool &has_for_update);
int remove_simple_stmts(ObIArray<ObSelectStmt*> &stmts);
int get_non_correlated_subquery(ObDMLStmt *stmt,

View File

@ -430,7 +430,6 @@ int ObTransformerImpl::choose_rewrite_rules(ObDMLStmt *stmt, uint64_t &need_type
ObTransformRule::add_trans_type(disable_list, OR_EXPANSION);
ObTransformRule::add_trans_type(disable_list, GROUPBY_PUSHDOWN);
ObTransformRule::add_trans_type(disable_list, GROUPBY_PULLUP);
ObTransformRule::add_trans_type(disable_list, TEMP_TABLE_OPTIMIZATION);
}
if (func.update_global_index_) {
ObTransformRule::add_trans_type(disable_list, OR_EXPANSION);