diff --git a/src/sql/optimizer/ob_log_link.cpp b/src/sql/optimizer/ob_log_link.cpp index a5a24cc76..ccecf6061 100644 --- a/src/sql/optimizer/ob_log_link.cpp +++ b/src/sql/optimizer/ob_log_link.cpp @@ -191,10 +191,24 @@ int ObLogLink::set_link_stmt(const ObDMLStmt* stmt) ObObjPrintParams print_param; print_param.for_dblink_ = 1; ObOptimizerContext *opt_ctx = NULL; + ObQueryCtx *query_ctx = NULL; + ObSQLSessionInfo *session = NULL; + int64_t session_query_timeout_us = 0; + int64_t hint_query_timeout_us = 0; if (OB_ISNULL(stmt) || OB_ISNULL(plan) || - OB_ISNULL(opt_ctx = &get_plan()->get_optimizer_context())) { + OB_ISNULL(opt_ctx = &get_plan()->get_optimizer_context()) || + OB_ISNULL(session = opt_ctx->get_session_info())) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("get unexpected null", KP(opt_ctx), KP(stmt), KP(plan), K(ret)); + LOG_WARN("get unexpected null", KP(opt_ctx), KP(stmt), KP(session), KP(plan), K(ret)); + } else if (NULL == (query_ctx = stmt->get_query_ctx())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("get unexpected null", K(ret)); + } else if (FALSE_IT(hint_query_timeout_us = query_ctx->get_query_hint_for_update().get_global_hint().query_timeout_)) { + } else if (OB_FAIL(session->get_query_timeout(session_query_timeout_us))) { + LOG_WARN("failed to get session query timeout", K(ret)); + } else if (-1 == hint_query_timeout_us && + FALSE_IT(query_ctx->get_query_hint_for_update().get_global_hint().merge_query_timeout_hint(session_query_timeout_us))) { + // do nothing } else if (OB_FAIL(mark_exec_params(const_cast(stmt)))) { LOG_WARN("failed to mark exec params", K(ret)); } else if (OB_FAIL(ObSQLUtils::reconstruct_sql(plan->get_allocator(), stmt, sql, opt_ctx->get_schema_guard(), print_param))) { @@ -204,6 +218,9 @@ int ObLogLink::set_link_stmt(const ObDMLStmt* stmt) stmt_fmt_len_ = sql.length(); LOG_DEBUG("loglink succ to reconstruct link sql", K(sql)); } + if (-1 == hint_query_timeout_us) { // restore query_timeout_hint + query_ctx->get_query_hint_for_update().get_global_hint().reset_query_timeout_hint(); + } return ret; } diff --git a/src/sql/resolver/dml/ob_hint.h b/src/sql/resolver/dml/ob_hint.h index 4886dc227..5e8b52db3 100644 --- a/src/sql/resolver/dml/ob_hint.h +++ b/src/sql/resolver/dml/ob_hint.h @@ -133,6 +133,7 @@ struct ObGlobalHint { int merge_dop_hint(uint64_t dfo, uint64_t dop); int merge_dop_hint(const ObIArray &dop_hints); void merge_query_timeout_hint(int64_t hint_time); + void reset_query_timeout_hint() { query_timeout_ = -1; } void merge_dblink_info_hint(int64_t tx_id, int64_t tm_sessid); void reset_dblink_info_hint(); void merge_max_concurrent_hint(int64_t max_concurrent);