patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -15,11 +15,13 @@
#include "sql/ob_sql_context.h"
#include "sql/resolver/expr/ob_raw_expr_util.h"
#include "sql/resolver/dml/ob_select_stmt.h"
namespace oceanbase {
namespace oceanbase
{
using namespace common;
namespace sql {
namespace sql
{
void ObUpdateStmtPrinter::init(char* buf, int64_t buf_len, int64_t* pos, ObUpdateStmt* stmt)
void ObUpdateStmtPrinter::init(char *buf, int64_t buf_len, int64_t *pos, ObUpdateStmt *stmt)
{
ObDMLStmtPrinter::init(buf, buf_len, pos, stmt);
}
@ -44,6 +46,7 @@ int ObUpdateStmtPrinter::do_print()
return ret;
}
int ObUpdateStmtPrinter::print()
{
int ret = OB_SUCCESS;
@ -53,8 +56,7 @@ int ObUpdateStmtPrinter::print()
LOG_WARN("stmt_ should not be NULL", K(ret));
} else if (OB_FAIL(print_basic_stmt())) {
LOG_WARN("fail to print basic stmt", K(ret), K(*stmt_));
} else { /*do nothing*/
}
} else { /*do nothing*/ }
return ret;
}
@ -68,7 +70,7 @@ int ObUpdateStmtPrinter::print_basic_stmt()
LOG_WARN("stmt_ should not be NULL", K(ret));
} else if (OB_FAIL(print_update())) {
LOG_WARN("fail to print select", K(ret), K(*stmt_));
} else if (OB_FAIL(print_from(false /*not need from, only print table name*/))) {
} else if (OB_FAIL(print_from(false/*not need from, only print table name*/))) {
LOG_WARN("fail to print from", K(ret), K(*stmt_));
} else if (OB_FAIL(print_set())) {
LOG_WARN("fail to print from", K(ret), K(*stmt_));
@ -100,7 +102,7 @@ int ObUpdateStmtPrinter::print_update()
} else {
DATA_PRINTF("update ");
if (OB_SUCC(ret)) {
if (OB_FAIL(print_hint())) { // hint
if (OB_FAIL(print_hint())) { // hint
LOG_WARN("fail to print hint", K(ret), K(*stmt_));
}
}
@ -121,14 +123,19 @@ int ObUpdateStmtPrinter::print_set()
} else {
DATA_PRINTF(" set ");
if (OB_SUCC(ret)) {
const ObUpdateStmt* update_stmt = static_cast<const ObUpdateStmt*>(stmt_);
const ObUpdateStmt *update_stmt = static_cast<const ObUpdateStmt*>(stmt_);
for (int64_t i = 0; OB_SUCC(ret) && i < update_stmt->get_tables_assignments().count(); ++i) {
for (int64_t j = 0; OB_SUCC(ret) && j < update_stmt->get_tables_assignments().at(i).assignments_.count(); ++j) {
const ObAssignment& assign = update_stmt->get_tables_assignments().at(i).assignments_.at(j);
for (int64_t i = 0; OB_SUCC(ret) && i < update_stmt->get_update_table_info().count(); ++i) {
ObUpdateTableInfo* table_info = update_stmt->get_update_table_info().at(i);
if (OB_ISNULL(table_info)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get null table info", K(ret));
}
for (int64_t j = 0; OB_SUCC(ret) && j < table_info->assignments_.count(); ++j) {
const ObAssignment &assign = table_info->assignments_.at(j);
// (c1, c2) = select x1, x2 from ... is represented as
// c1 = alias(subquery, 0), c2 = alias(subquery, 1)
ObAliasRefRawExpr* alias = NULL;
ObAliasRefRawExpr *alias = NULL;
if (OB_ISNULL(assign.column_expr_) || OB_ISNULL(assign.expr_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("column expr is null", K(ret), K(assign.column_expr_), K(assign.expr_));
@ -143,7 +150,7 @@ int ObUpdateStmtPrinter::print_set()
DATA_PRINTF(",");
}
} else if (alias->get_project_index() == 0) {
if (OB_FAIL(print_vector_assign(update_stmt->get_tables_assignments().at(i), alias->get_param_expr(0)))) {
if (OB_FAIL(print_vector_assign(table_info->assignments_, alias->get_param_expr(0)))) {
LOG_WARN("failed to print vector assign", K(ret));
} else if (OB_SUCC(ret)) {
DATA_PRINTF(",");
@ -159,7 +166,7 @@ int ObUpdateStmtPrinter::print_set()
return ret;
}
int ObUpdateStmtPrinter::print_simple_assign(const ObAssignment& assign)
int ObUpdateStmtPrinter::print_simple_assign(const ObAssignment &assign)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(assign.expr_) || OB_ISNULL(assign.column_expr_)) {
@ -171,7 +178,7 @@ int ObUpdateStmtPrinter::print_simple_assign(const ObAssignment& assign)
DATA_PRINTF(" = ");
}
if (OB_SUCC(ret)) {
ObRawExpr* tmp_expr = NULL;
ObRawExpr *tmp_expr = NULL;
if (OB_FAIL(ObRawExprUtils::erase_inner_added_exprs(assign.expr_, tmp_expr))) {
LOG_WARN("erase inner cast expr failed", K(ret));
} else if (OB_ISNULL(tmp_expr)) {
@ -184,24 +191,26 @@ int ObUpdateStmtPrinter::print_simple_assign(const ObAssignment& assign)
return ret;
}
int ObUpdateStmtPrinter::print_vector_assign(const ObTableAssignment& assignments, ObRawExpr* query_ref_expr)
int ObUpdateStmtPrinter::print_vector_assign(const ObAssignments &assignments,
ObRawExpr *query_ref_expr)
{
int ret = OB_SUCCESS;
ObSelectStmt* stmt = NULL;
ObSEArray<ObRawExpr*, 4> left_columns;
if (OB_ISNULL(query_ref_expr) || OB_UNLIKELY(!query_ref_expr->is_query_ref_expr()) ||
OB_ISNULL(stmt = static_cast<ObQueryRefRawExpr*>(query_ref_expr)->get_ref_stmt())) {
ObSelectStmt *stmt = NULL;
ObSEArray<ObRawExpr *, 4> left_columns;
if (OB_ISNULL(query_ref_expr) ||
OB_UNLIKELY(!query_ref_expr->is_query_ref_expr()) ||
OB_ISNULL(stmt = static_cast<ObQueryRefRawExpr *>(query_ref_expr)->get_ref_stmt())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("query ref expr is null", K(ret), K(query_ref_expr), K(stmt));
} else if (OB_FAIL(left_columns.prepare_allocate(stmt->get_select_item_size()))) {
LOG_WARN("failed to prepare allocate select item size", K(ret));
}
for (int64_t i = 0; OB_SUCC(ret) && i < assignments.assignments_.count(); ++i) {
ObColumnRefRawExpr* col = NULL;
ObRawExpr* value_expr = NULL;
ObAliasRefRawExpr* alias = NULL;
if (OB_ISNULL(value_expr = assignments.assignments_.at(i).expr_) ||
OB_ISNULL(col = assignments.assignments_.at(i).column_expr_)) {
for (int64_t i = 0; OB_SUCC(ret) && i < assignments.count(); ++i) {
ObColumnRefRawExpr *col = NULL;
ObRawExpr *value_expr = NULL;
ObAliasRefRawExpr *alias = NULL;
if (OB_ISNULL(value_expr = assignments.at(i).expr_) ||
OB_ISNULL(col = assignments.at(i).column_expr_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("value expr is null", K(ret), K(col), K(value_expr));
} else if (col->is_generated_column()) {
@ -241,5 +250,9 @@ int ObUpdateStmtPrinter::print_vector_assign(const ObTableAssignment& assignment
return ret;
}
} // end of namespace sql
} // end of namespace oceanbase
} //end of namespace sql
} //end of namespace oceanbase