diff --git a/src/sql/resolver/dml/ob_dml_stmt.cpp b/src/sql/resolver/dml/ob_dml_stmt.cpp index 6d9d638b9a..74f873f294 100644 --- a/src/sql/resolver/dml/ob_dml_stmt.cpp +++ b/src/sql/resolver/dml/ob_dml_stmt.cpp @@ -2845,13 +2845,23 @@ int ObDMLStmt::get_view_output( LOG_WARN("the table is not a generated table", K(ret)); } else if (OB_FAIL(get_column_exprs(table.table_id_, columns))) { LOG_WARN("failed to get column exprs", K(ret)); - } else if (OB_FAIL(append(column_list, columns))) { - LOG_WARN("failed to append columns", K(ret)); - } else if (OB_FAIL(table.ref_query_->get_select_exprs(select_list))) { - LOG_WARN("failed to get select list", K(ret)); - } else if (OB_UNLIKELY(select_list.count() != column_list.count())) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("the select list does match the column list", K(ret), K(select_list.count()), K(column_list.count())); + } else { + for (int64_t i = 0; OB_SUCC(ret) && i < columns.count(); ++i) { + ObColumnRefRawExpr *col_expr = columns.at(i); + int64_t idx = OB_INVALID_INDEX; + if (OB_ISNULL(col_expr)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected null", K(ret)); + } else if (OB_FALSE_IT(idx = col_expr->get_column_id() - OB_APP_MIN_COLUMN_ID)) { + } else if (idx < 0 || idx >= table.ref_query_->get_select_item_size()) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get invalid idx", K(ret), K(idx)); + } else if (OB_FAIL(select_list.push_back(table.ref_query_->get_select_item(idx).expr_))) { + LOG_WARN("failed to push back select expr", K(ret)); + } else if (OB_FAIL(column_list.push_back(col_expr))) { + LOG_WARN("failed to push back column expr", K(ret)); + } + } } return ret; } diff --git a/src/sql/rewrite/ob_transform_simplify.cpp b/src/sql/rewrite/ob_transform_simplify.cpp index be119adbe2..31ad96f7c8 100644 --- a/src/sql/rewrite/ob_transform_simplify.cpp +++ b/src/sql/rewrite/ob_transform_simplify.cpp @@ -3009,8 +3009,8 @@ int ObTransformSimplify::try_remove_redundent_select(ObSelectStmt& stmt, ObSelec /** * @brief check_subquery_valid * check subquery return equal one row, if empty do nothing - * has limit 可能使结果为空不做改写; - * select ... where rownum >2; rownum不包含1必空,包含判断较难,暂不处理 + * has limit may return empty result, do nothing: + * select ... where rownum >2; * subquery should in format of: * 1. select ... from dual; no where condition * 2. select aggr() ...; <- no group by, no having @@ -3030,7 +3030,8 @@ int ObTransformSimplify::check_subquery_valid(ObSelectStmt& stmt, bool& is_valid // do nothing } else if (0 == stmt.get_from_item_size() && 0 == stmt.get_condition_size()) { is_valid = true; - } else if (0 == stmt.get_group_expr_size() && 0 == stmt.get_having_expr_size() && sel_expr->has_flag(CNT_AGG)) { + } else if (0 == stmt.get_group_expr_size() && 0 == stmt.get_rollup_expr_size() && + 0 == stmt.get_having_expr_size() && sel_expr->has_flag(CNT_AGG)) { is_valid = true; } }