Fix shared exprs bugs when create inline view

This commit is contained in:
xianyu-w
2023-02-14 12:12:15 +00:00
committed by ob-robot
parent 50a6b3cda3
commit 0664c26d30
24 changed files with 911 additions and 1452 deletions

View File

@ -787,21 +787,6 @@ int ObDMLStmt::replace_relation_exprs(const common::ObIArray<ObRawExpr *> &other
return ret;
}
int ObDMLStmt::replace_inner_stmt_expr(const common::ObIArray<ObRawExpr *> &other_exprs,
const common::ObIArray<ObRawExpr *> &new_exprs)
{
int ret = OB_SUCCESS;
ObStmtExprReplacer visitor;
visitor.remove_scope(SCOPE_BASIC_TABLE);
visitor.set_recursive(true);
if (OB_FAIL(visitor.add_replace_exprs(other_exprs, new_exprs))) {
LOG_WARN("failed to add replace exprs", K(ret));
} else if (OB_FAIL(iterate_stmt_expr(visitor))) {
LOG_WARN("failed to iterate stmt expr", K(ret));
}
return ret;
}
int ObDMLStmt::copy_and_replace_stmt_expr(ObRawExprCopier &copier)
{
int ret = OB_SUCCESS;
@ -3045,6 +3030,27 @@ int ObDMLStmt::get_from_tables(ObSqlBitSet<> &table_set) const
return ret;
}
int ObDMLStmt::get_from_tables(common::ObIArray<TableItem *>& from_tables) const
{
int ret = OB_SUCCESS;
for (int64_t i = 0; OB_SUCC(ret) && i < from_items_.count(); ++i) {
TableItem *table_item = NULL;
const FromItem &from_item = from_items_.at(i);
if (from_item.is_joined_ &&
OB_ISNULL(table_item = get_joined_table(from_item.table_id_))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null", K(ret));
} else if (!from_item.is_joined_ &&
OB_ISNULL(table_item = get_table_item_by_id(from_item.table_id_))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null", K(ret));
} else if (OB_FAIL(from_tables.push_back(table_item))) {
LOG_WARN("failed to push back", K(ret));
}
}
return ret;
}
ColumnItem *ObDMLStmt::get_column_item(uint64_t table_id, const ObString &col_name)
{
ColumnItem *item = NULL;

View File

@ -667,24 +667,6 @@ public:
int replace_relation_exprs(const common::ObIArray<ObRawExpr *> &other_exprs,
const common::ObIArray<ObRawExpr *> &new_exprs);
/**
* @brief replace_inner_stmt_expr
* 对本层出现的 expr 进行替换。
* stmt 中有一些 expr 可能出现在多处。对 stmt 进行深拷贝后,要调整新stmt中对应expr的指向。
* other_exprs 与 new_exprs 一一映射。函数会将 a \in other_exprs 替换为对应的 b \in new_exprs
* 构造 other_exprs 与 new_exprs 构成的映射关系需要包含以下几类表达式
* 1. ObColumnRefRawExpr: 列表达式
* 2. ObAggFunRawExpr: 聚合函数表达式
* 3. ObQueryRefRawExpr: 子查询引用表达式
* 4. ObWinFunRawExpr: 窗口函数表达式
* 其中 2-4 仅出现在 ObSelectStmt 中。
* @param other_exprs
* @param new_exprs
* @return
*/
int replace_inner_stmt_expr(const common::ObIArray<ObRawExpr*> &other_exprs,
const common::ObIArray<ObRawExpr*> &new_exprs);
int copy_and_replace_stmt_expr(ObRawExprCopier &copier);
virtual int iterate_stmt_expr(ObStmtExprVisitor &vistor);
@ -899,6 +881,7 @@ public:
int get_table_rel_ids(const ObIArray<TableItem*> &tables, ObSqlBitSet<> &table_set) const;
int get_from_tables(ObRelIds &table_set) const;
int get_from_tables(ObSqlBitSet<> &table_set) const;
int get_from_tables(common::ObIArray<TableItem*>& from_tables) const;
int add_table_item(const ObSQLSessionInfo *session_info, TableItem *table_item);
int add_table_item(const ObSQLSessionInfo *session_info, TableItem *table_item, bool &have_same_table_name);