From 460fdf9fc4992ed875a0ea7cbc6905942b48a795 Mon Sep 17 00:00:00 2001 From: raywill Date: Tue, 10 Jan 2023 08:38:04 +0000 Subject: [PATCH] [bugfix] get wrong db_time when subplan filter is used in the plan --- src/sql/engine/ob_operator.cpp | 18 ++++++++++++++---- src/sql/engine/ob_operator.h | 13 ++++++++++--- src/sql/engine/px/ob_px_worker_stat.cpp | 15 ++++++--------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/sql/engine/ob_operator.cpp b/src/sql/engine/ob_operator.cpp index 225719ad56..67426488b0 100644 --- a/src/sql/engine/ob_operator.cpp +++ b/src/sql/engine/ob_operator.cpp @@ -906,10 +906,11 @@ int ObOperator::submit_op_monitor_node() int ObOperator::get_next_row() { int ret = OB_SUCCESS; + begin_cpu_time_counting(); + begin_ash_line_id_reg(); if (OB_FAIL(check_stack_once())) { LOG_WARN("too deep recusive", K(ret)); } else { - begin_cpu_time_counting(); if (ctx_.get_my_session()->is_user_session() || spec_.plan_->get_phy_plan_hint().monitor_) { IGNORE_RETURN try_register_rt_monitor_node(1); } @@ -918,9 +919,11 @@ int ObOperator::get_next_row() } else if (OB_UNLIKELY(get_spec().is_vectorized())) { // Operator itself supports vectorization, while parent operator does NOT. // Use vectorize method to get next row. + end_cpu_time_counting(); if (OB_FAIL(get_next_row_vectorizely())) { // do nothing } + begin_cpu_time_counting(); } else { if (OB_UNLIKELY(!startup_passed_)) { bool filtered = false; @@ -987,18 +990,21 @@ int ObOperator::get_next_row() } } } - end_cpu_time_counting(); } + end_ash_line_id_reg(); + end_cpu_time_counting(); return ret; } int ObOperator::get_next_batch(const int64_t max_row_cnt, const ObBatchRows *&batch_rows) { int ret = OB_SUCCESS; + begin_cpu_time_counting(); + begin_ash_line_id_reg(); + if (OB_FAIL(check_stack_once())) { LOG_WARN("too deep recusive", K(ret)); } else { - begin_cpu_time_counting(); if (OB_UNLIKELY(spec_.need_check_output_datum_ && brs_checker_)) { if (OB_FAIL(brs_checker_->check_datum_modified())) { LOG_WARN("check output datum failed", K(ret), "id", spec_.get_id(), "op_name", op_name()); @@ -1101,11 +1107,13 @@ int ObOperator::get_next_batch(const int64_t max_row_cnt, const ObBatchRows *&ba } } } else { + end_cpu_time_counting(); // Operator does NOT support vectorization, while its parent does. Return // the batch with only 1 row if (OB_FAIL(get_next_batch_with_onlyone_row())) { // do nothing } + begin_cpu_time_counting(); } if (OB_SUCC(ret)) { if (OB_UNLIKELY(spec_.need_check_output_datum_) && brs_checker_ && !brs_.end_ && brs_.size_ > 0) { @@ -1113,8 +1121,10 @@ int ObOperator::get_next_batch(const int64_t max_row_cnt, const ObBatchRows *&ba } LOG_DEBUG("get next batch", "id", spec_.get_id(), "op_name", op_name(), K(brs_)); } - end_cpu_time_counting(); } + + end_ash_line_id_reg(); + end_cpu_time_counting(); return ret; } diff --git a/src/sql/engine/ob_operator.h b/src/sql/engine/ob_operator.h index 01f6f1df21..70cb0abfd0 100644 --- a/src/sql/engine/ob_operator.h +++ b/src/sql/engine/ob_operator.h @@ -601,21 +601,28 @@ protected: inline void begin_cpu_time_counting() { - // begin with current operator - ObActiveSessionGuard::get_stat().plan_line_id_ = spec_.id_; cpu_begin_time_ = rdtsc(); } inline void end_cpu_time_counting() { total_time_ += (rdtsc() - cpu_begin_time_); + } + inline void begin_ash_line_id_reg() + { + // begin with current operator + ObActiveSessionGuard::get_stat().plan_line_id_ = spec_.id_; + } + inline void end_ash_line_id_reg() + { // move back to parent operator + // known issue: when switch from batch to row in same op, + // we shift line id to parent op un-intently. but we tolerate this inaccuracy if (OB_LIKELY(spec_.get_parent())) { common::ObActiveSessionGuard::get_stat().plan_line_id_ = spec_.get_parent()->id_; } else { common::ObActiveSessionGuard::get_stat().plan_line_id_ = -1; } } - uint64_t cpu_begin_time_; // start of counting cpu time uint64_t total_time_; // total time cost on this op, including io & cpu time protected: diff --git a/src/sql/engine/px/ob_px_worker_stat.cpp b/src/sql/engine/px/ob_px_worker_stat.cpp index 5147b3ec94..ea7fa1ea45 100644 --- a/src/sql/engine/px/ob_px_worker_stat.cpp +++ b/src/sql/engine/px/ob_px_worker_stat.cpp @@ -85,17 +85,14 @@ int ObPxWorkerStatList::list_to_array(ObArray &stat_array, ObSpinLockGuard guard(lock_); stat_array.reserve(worker_stat_list_.get_size()); DLIST_FOREACH(cur,worker_stat_list_) { + if (!is_sys_tenant(target_tenant_id) && cur->get_tenant_id() != target_tenant_id) { + continue; + } // sys tenant list all tenant stat // non-sys tennat list self tenant stat - if (is_sys_tenant(target_tenant_id) || cur->get_tenant_id() == target_tenant_id) { - if(OB_SUCCESS != stat_array.push_back(*cur)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("failed to change stat_list to array", K(ret)); - } - } - - if (!is_sys_tenant(target_tenant_id) && cur->get_tenant_id() == target_tenant_id) { - break; + if(OB_SUCCESS != stat_array.push_back(*cur)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("failed to change stat_list to array", K(ret)); } } return ret;