Fix dblink bugs
This commit is contained in:
parent
941a6da494
commit
76e6f675b5
4
deps/oblib/src/common/object/ob_object.h
vendored
4
deps/oblib/src/common/object/ob_object.h
vendored
@ -1068,10 +1068,8 @@ struct ObObjPrintParams
|
||||
uint32_t beginning_space_:1;
|
||||
uint32_t for_dblink_:1;
|
||||
uint32_t binary_string_print_hex_:1;
|
||||
uint32_t print_with_cte_:1;
|
||||
uint32_t force_print_cte_:1;
|
||||
uint32_t need_print_converter_:1;
|
||||
uint32_t reserved_:23;
|
||||
uint32_t reserved_:24;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -360,12 +360,10 @@ int ObVariableSetExecutor::calc_subquery_expr_value(ObExecContext &ctx,
|
||||
ObSqlString tmp_expr_subquery;
|
||||
ObSqlString expr_subquery;
|
||||
ObObjPrintParams print_params(session_info->get_timezone_info());
|
||||
print_params.print_with_cte_ = true;
|
||||
print_params.force_print_cte_ = true;
|
||||
print_params.need_print_converter_ = false;
|
||||
ObRawExprPrinter expr_printer(expr_str_buf, OB_MAX_DEFAULT_VALUE_LENGTH,
|
||||
&pos, ctx.get_sql_ctx()->schema_guard_, print_params);
|
||||
if (OB_FAIL(expr_printer.do_print(expr, T_NONE_SCOPE, true))) {
|
||||
if (OB_FAIL(expr_printer.do_print(expr, T_NONE_SCOPE, true, true))) {
|
||||
LOG_WARN("print expr definition failed", K(ret));
|
||||
} else if (OB_FAIL(tmp_expr_subquery.assign_fmt("select %.*s from dual",
|
||||
static_cast<int32_t>(pos), expr_str_buf))) {
|
||||
|
@ -65,8 +65,7 @@ int ObDeleteStmtPrinter::print_basic_stmt()
|
||||
LOG_WARN("stmt_ should not be NULL", K(ret));
|
||||
} else if (OB_FAIL(print_with())) {
|
||||
LOG_WARN("failed to print with", K(ret));
|
||||
} else if ((print_params_.force_print_cte_ || print_params_.print_with_cte_) &&
|
||||
OB_FAIL(print_cte_define())) {
|
||||
} else if (OB_FAIL(print_temp_table_as_cte())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
} else if (OB_FAIL(print_delete())) {
|
||||
LOG_WARN("fail to print select", K(ret), K(*stmt_));
|
||||
|
@ -34,6 +34,7 @@ ObDMLStmtPrinter::ObDMLStmtPrinter(char *buf, int64_t buf_len, int64_t *pos, con
|
||||
pos_(pos),
|
||||
stmt_(stmt),
|
||||
is_root_(false),
|
||||
print_cte_(false),
|
||||
schema_guard_(schema_guard),
|
||||
print_params_(print_params),
|
||||
expr_printer_(buf, buf_len, pos, schema_guard_, print_params_, param_store),
|
||||
@ -51,10 +52,7 @@ void ObDMLStmtPrinter::init(char *buf, int64_t buf_len, int64_t *pos, ObDMLStmt
|
||||
buf_len_ = buf_len;
|
||||
pos_ = pos;
|
||||
stmt_ = stmt;
|
||||
print_params_.print_with_cte_ = true; // default true
|
||||
// force print with cte regardless of the value of print_with_cte_
|
||||
// this flag is not final solution, will be optimized later
|
||||
print_params_.force_print_cte_ = false;
|
||||
print_cte_ = false;
|
||||
}
|
||||
|
||||
int ObDMLStmtPrinter::print_hint()
|
||||
@ -1310,8 +1308,8 @@ int ObDMLStmtPrinter::print_subquery(const ObSelectStmt *subselect_stmt,
|
||||
schema_guard_,
|
||||
print_params_,
|
||||
subquery_print_params & FORCE_COL_ALIAS);
|
||||
if (!(subquery_print_params & PRINT_CTE)){
|
||||
printer.disable_print_cte();
|
||||
if (subquery_print_params & PRINT_CTE) {
|
||||
printer.enable_print_temp_table_as_cte();
|
||||
}
|
||||
if (subquery_print_params & PRINT_BRACKET) {
|
||||
DATA_PRINTF("(");
|
||||
@ -1325,12 +1323,17 @@ int ObDMLStmtPrinter::print_subquery(const ObSelectStmt *subselect_stmt,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDMLStmtPrinter::print_cte_define()
|
||||
int ObDMLStmtPrinter::print_temp_table_as_cte()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSEArray<ObDMLStmt::TempTableInfo, 8> temp_table_infos;
|
||||
if (print_params_.print_origin_stmt_) {
|
||||
//do nothing
|
||||
} else if (!print_cte_) {
|
||||
//do nothing
|
||||
} else if (print_params_.for_dblink_) {
|
||||
// always print temp table as generated table
|
||||
// do nothing
|
||||
} else if (OB_ISNULL(stmt_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpect null stmt", K(ret));
|
||||
|
@ -119,8 +119,8 @@ public:
|
||||
common::ObObjPrintParams print_params,
|
||||
const ParamStore *param_store = NULL);
|
||||
virtual ~ObDMLStmtPrinter();
|
||||
void enable_print_cte() { print_params_.print_with_cte_ = true; }
|
||||
void disable_print_cte() { print_params_.print_with_cte_ = false; }
|
||||
void enable_print_temp_table_as_cte() { print_cte_ = true; }
|
||||
void disable_print_temp_table_as_cte() { print_cte_ = false; }
|
||||
void init(char *buf, int64_t buf_len, int64_t *pos, ObDMLStmt *stmt);
|
||||
virtual int do_print() = 0;
|
||||
|
||||
@ -147,12 +147,12 @@ public:
|
||||
enum SubqueryPrintParam {
|
||||
PRINT_BRACKET = 1 << 0,
|
||||
FORCE_COL_ALIAS = 1 << 1,
|
||||
PRINT_CTE = 1 << 2
|
||||
PRINT_CTE = 1 << 2
|
||||
};
|
||||
|
||||
int print_subquery(const ObSelectStmt *subselect_stmt,
|
||||
uint64_t subquery_print_params);
|
||||
int print_cte_define();
|
||||
int print_temp_table_as_cte();
|
||||
|
||||
int print_quote_for_const(ObRawExpr* expr, bool &print_quote);
|
||||
int print_expr_except_const_number(ObRawExpr* expr, ObStmtScope scope);
|
||||
@ -177,6 +177,7 @@ protected:
|
||||
int64_t *pos_;
|
||||
const ObDMLStmt *stmt_;
|
||||
bool is_root_;
|
||||
bool print_cte_;
|
||||
ObSchemaGetterGuard *schema_guard_;
|
||||
ObObjPrintParams print_params_;
|
||||
ObRawExprPrinter expr_printer_;
|
||||
|
@ -71,8 +71,7 @@ int ObInsertAllStmtPrinter::print_multi_insert_stmt()
|
||||
} else if (OB_UNLIKELY(!stmt_->is_insert_all_stmt())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("Not a valid insert stmt", K(stmt_->get_stmt_type()), K(ret));
|
||||
} else if ((print_params_.force_print_cte_ || print_params_.print_with_cte_) &&
|
||||
OB_FAIL(print_cte_define())) {
|
||||
} else if (OB_FAIL(print_temp_table_as_cte())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
} else if (OB_FAIL(print_multi_insert(insert_stmt))) {
|
||||
LOG_WARN("fail to print select", K(ret), K(*stmt_));
|
||||
|
@ -66,8 +66,7 @@ int ObInsertStmtPrinter::print_basic_stmt()
|
||||
if (OB_ISNULL(stmt_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("stmt_ should not be NULL", K(ret));
|
||||
} else if ((print_params_.force_print_cte_ || print_params_.print_with_cte_) &&
|
||||
OB_FAIL(print_cte_define())) {
|
||||
} else if (OB_FAIL(print_temp_table_as_cte())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
} else if (OB_FAIL(print_insert())) {
|
||||
LOG_WARN("fail to print select", K(ret), K(*stmt_));
|
||||
|
@ -45,8 +45,6 @@ int ObMergeStmtPrinter::print()
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("stmt_ is NULL or buf_ is NULL or pos_ is NULL", K(ret),
|
||||
K(stmt_), K(buf_), K(pos_));
|
||||
} else if (print_params_.print_with_cte_ && OB_FAIL(print_cte_define())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
} else {
|
||||
const ObMergeStmt *merge_stmt = static_cast<const ObMergeStmt *>(stmt_);
|
||||
const TableItem *target_table = NULL;
|
||||
@ -60,8 +58,7 @@ int ObMergeStmtPrinter::print()
|
||||
LOG_WARN("target table or source table is null",
|
||||
K(ret), K(target_table), K(source_table));
|
||||
}
|
||||
if (OB_SUCC(ret) && (print_params_.force_print_cte_ || print_params_.print_with_cte_) &&
|
||||
OB_FAIL(print_cte_define())) {
|
||||
if (OB_SUCC(ret) && OB_FAIL(print_temp_table_as_cte())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
}
|
||||
DATA_PRINTF("merge ");
|
||||
|
@ -49,10 +49,7 @@ int ObSelectStmtPrinter::do_print()
|
||||
K(column_list_->count()), K(select_stmt->get_select_item_size()));
|
||||
} else {
|
||||
expr_printer_.init(buf_, buf_len_, pos_, schema_guard_, print_params_, param_store_);
|
||||
if ((print_params_.force_print_cte_ || print_params_.print_with_cte_) &&
|
||||
OB_FAIL(print_cte_define())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
} else if (stmt_->is_unpivot_select()) {
|
||||
if (stmt_->is_unpivot_select()) {
|
||||
if (OB_FAIL(print_unpivot())) {
|
||||
LOG_WARN("fail to print_unpivot",
|
||||
KPC(stmt_->get_transpose_item()), K(ret));
|
||||
@ -77,11 +74,9 @@ int ObSelectStmtPrinter::print()
|
||||
LOG_WARN("Not a valid select stmt", K(stmt_->get_stmt_type()), K(ret));
|
||||
} else {
|
||||
const ObSelectStmt *select_stmt = static_cast<const ObSelectStmt*>(stmt_);
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (OB_FAIL(print_with())) {
|
||||
if (OB_FAIL(print_with())) {
|
||||
LOG_WARN("print with failed");
|
||||
} else if (print_params_.print_with_cte_ &&
|
||||
OB_FAIL(print_cte_define())) {
|
||||
} else if (OB_FAIL(print_temp_table_as_cte())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
} else if (select_stmt->is_set_stmt()) {
|
||||
if (select_stmt->is_recursive_union() &&
|
||||
@ -119,7 +114,7 @@ int ObSelectStmtPrinter::print_unpivot()
|
||||
} else {
|
||||
const ObSelectStmt *select_stmt = static_cast<const ObSelectStmt*>(stmt_);
|
||||
|
||||
if (print_params_.print_with_cte_ && OB_FAIL(print_cte_define())) {
|
||||
if (OB_FAIL(print_temp_table_as_cte())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
}
|
||||
|
||||
@ -283,7 +278,6 @@ int ObSelectStmtPrinter::print_set_op_stmt()
|
||||
print_params_,
|
||||
/*force_col_alias*/true);
|
||||
stmt_printer.set_column_list(column_list_);
|
||||
stmt_printer.disable_print_cte();
|
||||
ObString set_op_str = ObString::make_string(
|
||||
ObSelectStmt::set_operator_str(select_stmt->get_set_op()));
|
||||
if (OB_FAIL(stmt_printer.do_print())) {
|
||||
|
@ -2062,6 +2062,7 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
||||
schema_guard,
|
||||
print_params);
|
||||
printer.set_is_root(true);
|
||||
printer.enable_print_temp_table_as_cte();
|
||||
if (OB_FAIL(printer.do_print())) {
|
||||
LOG_WARN("fail to print select stmt", K(ret));
|
||||
} else if (OB_FAIL(ob_write_string(allocator, ObString(pos, buf), sql))) {
|
||||
@ -2072,7 +2073,6 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
||||
case stmt::T_INSERT_ALL: {
|
||||
ObInsertAllStmtPrinter printer(buf, buf_len, &pos, static_cast<const ObInsertAllStmt*>(stmt),
|
||||
schema_guard, print_params);
|
||||
printer.disable_print_cte();
|
||||
printer.set_is_root(true);
|
||||
if (OB_FAIL(printer.do_print())) {
|
||||
LOG_WARN("fail to print insert stmt", K(ret));
|
||||
@ -2085,7 +2085,6 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
||||
case stmt::T_INSERT: {
|
||||
ObInsertStmtPrinter printer(buf, buf_len, &pos, static_cast<const ObInsertStmt*>(stmt),
|
||||
schema_guard, print_params);
|
||||
printer.disable_print_cte();
|
||||
printer.set_is_root(true);
|
||||
if (OB_FAIL(printer.do_print())) {
|
||||
LOG_WARN("fail to print insert stmt", K(ret));
|
||||
@ -2097,7 +2096,6 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
||||
case stmt::T_DELETE: {
|
||||
ObDeleteStmtPrinter printer(buf, buf_len, &pos, static_cast<const ObDeleteStmt*>(stmt),
|
||||
schema_guard, print_params);
|
||||
printer.disable_print_cte();
|
||||
printer.set_is_root(true);
|
||||
if (OB_FAIL(printer.do_print())) {
|
||||
LOG_WARN("fail to print delete stmt", K(ret));
|
||||
@ -2109,7 +2107,6 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
||||
case stmt::T_UPDATE: {
|
||||
ObUpdateStmtPrinter printer(buf, buf_len, &pos, static_cast<const ObUpdateStmt*>(stmt),
|
||||
schema_guard, print_params);
|
||||
printer.disable_print_cte();
|
||||
printer.set_is_root(true);
|
||||
if (OB_FAIL(printer.do_print())) {
|
||||
LOG_WARN("fail to print update stmt", K(ret));
|
||||
@ -2122,7 +2119,6 @@ int ObSQLUtils::print_sql(ObIAllocator &allocator,
|
||||
ObMergeStmtPrinter printer(buf, buf_len, &pos,
|
||||
static_cast<const ObMergeStmt*>(stmt),
|
||||
schema_guard, print_params);
|
||||
printer.disable_print_cte();
|
||||
printer.set_is_root(true);
|
||||
if (OB_FAIL(printer.do_print())) {
|
||||
LOG_WARN("failed to print merge stmt", K(ret));
|
||||
|
@ -67,8 +67,7 @@ int ObUpdateStmtPrinter::print_basic_stmt()
|
||||
LOG_WARN("stmt_ should not be NULL", K(ret));
|
||||
} else if (OB_FAIL(print_with())) {
|
||||
LOG_WARN("failed to print with", K(ret));
|
||||
} else if ((print_params_.force_print_cte_ || print_params_.print_with_cte_) &&
|
||||
OB_FAIL(print_cte_define())) {
|
||||
} else if (OB_FAIL(print_temp_table_as_cte())) {
|
||||
LOG_WARN("failed to print cte", K(ret));
|
||||
} else if (OB_FAIL(print_update())) {
|
||||
LOG_WARN("fail to print select", K(ret), K(*stmt_));
|
||||
|
@ -34,7 +34,8 @@ ObRawExprPrinter::ObRawExprPrinter()
|
||||
only_column_namespace_(false),
|
||||
tz_info_(NULL),
|
||||
param_store_(NULL),
|
||||
schema_guard_(NULL)
|
||||
schema_guard_(NULL),
|
||||
print_cte_(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -48,7 +49,8 @@ ObRawExprPrinter::ObRawExprPrinter(char *buf, int64_t buf_len, int64_t *pos, ObS
|
||||
tz_info_(NULL),
|
||||
print_params_(print_params),
|
||||
param_store_(param_store),
|
||||
schema_guard_(schema_guard)
|
||||
schema_guard_(schema_guard),
|
||||
print_cte_(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -68,7 +70,7 @@ void ObRawExprPrinter::init(char *buf, int64_t buf_len, int64_t *pos, ObSchemaGe
|
||||
param_store_ = param_store;
|
||||
}
|
||||
|
||||
int ObRawExprPrinter::do_print(ObRawExpr *expr, ObStmtScope scope, bool only_column_namespace)
|
||||
int ObRawExprPrinter::do_print(ObRawExpr *expr, ObStmtScope scope, bool only_column_namespace, bool print_cte)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(expr)) {
|
||||
@ -77,6 +79,7 @@ int ObRawExprPrinter::do_print(ObRawExpr *expr, ObStmtScope scope, bool only_col
|
||||
} else {
|
||||
scope_ = scope;
|
||||
only_column_namespace_ = only_column_namespace;
|
||||
print_cte_ = print_cte;
|
||||
PRINT_EXPR(expr);
|
||||
}
|
||||
return ret;
|
||||
@ -317,7 +320,9 @@ int ObRawExprPrinter::print(ObQueryRefRawExpr *expr)
|
||||
static_cast<ObSelectStmt*>(stmt),
|
||||
schema_guard_,
|
||||
print_params_);
|
||||
stmt_printer.disable_print_cte();
|
||||
if (print_cte_) {
|
||||
stmt_printer.enable_print_temp_table_as_cte();
|
||||
}
|
||||
if (OB_FAIL(stmt_printer.do_print())) {
|
||||
LOG_WARN("fail to print ref query", K(ret));
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public:
|
||||
void init(char *buf, int64_t buf_len, int64_t *pos, ObSchemaGetterGuard *schema_guard,
|
||||
ObObjPrintParams print_params, const ParamStore *param_store = NULL);
|
||||
// stmt中会出现若干expr, 为了避免反复实例化,这里将expr作为do_print的参数
|
||||
int do_print(ObRawExpr *expr, ObStmtScope scope, bool only_column_namespace = false);
|
||||
int do_print(ObRawExpr *expr, ObStmtScope scope, bool only_column_namespace = false, bool print_cte = false);
|
||||
int pre_check_treat_opt(ObRawExpr *expr, bool &is_treat);
|
||||
private:
|
||||
int print(ObRawExpr *expr);
|
||||
@ -161,6 +161,7 @@ private:
|
||||
ObObjPrintParams print_params_;
|
||||
const ParamStore *param_store_;
|
||||
ObSchemaGetterGuard *schema_guard_;
|
||||
bool print_cte_;
|
||||
};
|
||||
|
||||
} // end namespace sql
|
||||
|
@ -824,9 +824,20 @@ int ObTransformQueryPushDown::push_down_stmt_exprs(ObSelectStmt *select_stmt,
|
||||
/*do nothing*/
|
||||
}
|
||||
} else {
|
||||
view_stmt->get_select_items().reset();
|
||||
if (OB_FAIL(append(view_stmt->get_select_items(), select_stmt->get_select_items()))) {
|
||||
LOG_WARN("view stmt replace select items failed", K(ret));
|
||||
for (int64_t i = 0 ; i < view_stmt->get_select_item_size(); i ++) {
|
||||
ObRawExpr *expr = NULL;
|
||||
if (OB_ISNULL(expr = view_stmt->get_select_item(i).expr_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpect null expr", K(ret));
|
||||
} else {
|
||||
expr->set_alias_column_name(ObString::make_empty_string());
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
view_stmt->get_select_items().reset();
|
||||
if (OB_FAIL(append(view_stmt->get_select_items(), select_stmt->get_select_items()))) {
|
||||
LOG_WARN("view stmt replace select items failed", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user