From a58de120303cf451bdbc288dfd1167f50c2372d8 Mon Sep 17 00:00:00 2001 From: xianyu-w <707512433@qq.com> Date: Mon, 24 Apr 2023 07:48:15 +0000 Subject: [PATCH] disable write udf to remote dblink tables --- deps/easy/src/io/easy_negotiation.c | 12 +++--- src/sql/resolver/expr/ob_raw_expr_printer.cpp | 2 +- src/sql/rewrite/ob_transform_dblink.cpp | 38 ++++++++++++------- src/sql/rewrite/ob_transform_dblink.h | 2 + 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/deps/easy/src/io/easy_negotiation.c b/deps/easy/src/io/easy_negotiation.c index c7189253f..b6d8ff2a4 100644 --- a/deps/easy/src/io/easy_negotiation.c +++ b/deps/easy/src/io/easy_negotiation.c @@ -103,9 +103,9 @@ static int easy_decode_uint16(char *buf, const int64_t data_len, int64_t *pos, u return ret; } -static int easy_encode_negotiation_msg(easy_negotiation_msg_t *ne_msg, char *buf, int buf_len, int64_t *encode_len) -{ - int ret = EASY_OK; +static int easy_encode_negotiation_msg(easy_negotiation_msg_t *ne_msg, char *buf, int buf_len, int64_t *encode_len) +{ + int ret = EASY_OK; int64_t pos = 0; if (NULL == ne_msg || NULL == buf || NULL == encode_len) { @@ -125,9 +125,9 @@ static int easy_encode_negotiation_msg(easy_negotiation_msg_t *ne_msg, char *buf return ret; } - ret = easy_encode_uint64(buf, buf_len, &pos, ne_msg->msg_body.eio_magic); - if (ret != EASY_OK) { - easy_error_log("send negotiation msg, encode eio magic failed!"); + ret = easy_encode_uint64(buf, buf_len, &pos, ne_msg->msg_body.eio_magic); + if (ret != EASY_OK) { + easy_error_log("send negotiation msg, encode eio magic failed!"); return ret; } diff --git a/src/sql/resolver/expr/ob_raw_expr_printer.cpp b/src/sql/resolver/expr/ob_raw_expr_printer.cpp index 89b5fd1ad..2c9efef0e 100644 --- a/src/sql/resolver/expr/ob_raw_expr_printer.cpp +++ b/src/sql/resolver/expr/ob_raw_expr_printer.cpp @@ -1072,7 +1072,7 @@ int ObRawExprPrinter::print(ObAggFunRawExpr *expr) } } if (OB_SUCC(ret)) { - if (!print_params_.for_dblink_ && !database_name.empty()) { + if (!database_name.empty()) { DATA_PRINTF("%.*s.", LEN_AND_PTR(database_name)); } if (!package_name.empty()) { diff --git a/src/sql/rewrite/ob_transform_dblink.cpp b/src/sql/rewrite/ob_transform_dblink.cpp index ce388592b..f81b06c8d 100644 --- a/src/sql/rewrite/ob_transform_dblink.cpp +++ b/src/sql/rewrite/ob_transform_dblink.cpp @@ -272,6 +272,7 @@ int ObTransformDBlink::inner_reverse_link_table(ObDMLStmt *stmt, uint64_t target { int ret = OB_SUCCESS; ObSEArray child_stmts; + bool has_invalid_expr = false; if (OB_ISNULL(stmt)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("unexpect null stmt", K(ret)); @@ -284,6 +285,12 @@ int ObTransformDBlink::inner_reverse_link_table(ObDMLStmt *stmt, uint64_t target } } if (OB_FAIL(ret)) { + } else if (has_invalid_link_expr(*stmt, has_invalid_expr)) { + LOG_WARN("failed to check stmt has invalid link expr", K(ret)); + } else if (has_invalid_expr) { + ret = OB_NOT_SUPPORTED; + LOG_WARN("dblink write udf or user variable not supported", K(ret)); + LOG_USER_ERROR(OB_NOT_SUPPORTED, "dblink write udf or user variable"); } else if (OB_FAIL(reverse_link_tables(stmt->get_table_items(), target_dblink_id))) { LOG_WARN("failed to reverse link table", K(ret)); } else if (OB_FAIL(formalize_link_table(stmt))) { @@ -443,6 +450,21 @@ int ObTransformDBlink::pack_link_table(ObDMLStmt *stmt, bool &trans_happened) return ret; } +int ObTransformDBlink::has_invalid_link_expr(ObDMLStmt &stmt, bool &has_invalid_expr) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(stmt.has_special_expr(CNT_PL_UDF, has_invalid_expr))) { + LOG_WARN("failed to check stmt has special expr", K(ret)); + } else if (has_invalid_expr) { + } else if (OB_FAIL(stmt.has_special_expr(CNT_SO_UDF, has_invalid_expr))) { + LOG_WARN("failed to check stmt has special expr", K(ret)); + } else if (has_invalid_expr) { + } else if (OB_FAIL(stmt.has_special_expr(CNT_USER_VARIABLE, has_invalid_expr))) { + LOG_WARN("failed to check stmt has special expr", K(ret)); + } + return ret; +} + int ObTransformDBlink::collect_link_table(ObDMLStmt *stmt, ObIArray &helpers, uint64_t &dblink_id, @@ -458,20 +480,8 @@ int ObTransformDBlink::collect_link_table(ObDMLStmt *stmt, LOG_WARN("unexpect null stmt", K(ret)); } else if (stmt->has_sequence() || stmt->is_hierarchical_query() || stmt->is_unpivot_select()) { all_table_from_one_dblink = false; - } else if (OB_FAIL(stmt->has_special_expr(CNT_PL_UDF, has_special_expr))) { - LOG_WARN("failed to check stmt has special expr", K(ret)); - } else if (has_special_expr) { - all_table_from_one_dblink = false; - } else if (OB_FAIL(stmt->has_special_expr(CNT_SO_UDF, has_special_expr))) { - LOG_WARN("failed to check stmt has special expr", K(ret)); - } else if (has_special_expr) { - all_table_from_one_dblink = false; - } else if (OB_FAIL(stmt->has_special_expr(CNT_SO_UDF, has_special_expr))) { - LOG_WARN("failed to check stmt has special expr", K(ret)); - } else if (has_special_expr) { - all_table_from_one_dblink = false; - } else if (OB_FAIL(stmt->has_special_expr(CNT_USER_VARIABLE, has_special_expr))) { - LOG_WARN("failed to check stmt has special expr", K(ret)); + } else if (has_invalid_link_expr(*stmt, has_special_expr)) { + LOG_WARN("failed to check stmt has invalid link expr", K(ret)); } else if (has_special_expr) { all_table_from_one_dblink = false; } diff --git a/src/sql/rewrite/ob_transform_dblink.h b/src/sql/rewrite/ob_transform_dblink.h index cdb0ae774..d94822335 100644 --- a/src/sql/rewrite/ob_transform_dblink.h +++ b/src/sql/rewrite/ob_transform_dblink.h @@ -162,6 +162,8 @@ private: int check_link_oracle(int64_t dblink_id, bool &link_oracle); + int has_invalid_link_expr(ObDMLStmt &stmt, bool &has_invalid_expr); + DISALLOW_COPY_AND_ASSIGN(ObTransformDBlink); private: