From 03809198e185fee6cbcbdb1a0c688e26b4c7bc17 Mon Sep 17 00:00:00 2001 From: raywill Date: Mon, 3 Apr 2023 19:41:28 +0000 Subject: [PATCH] support collecting table scan info into sql_plan_monitor --- src/share/diagnosis/ob_sql_monitor_statname.h | 5 +++++ src/sql/engine/table/ob_table_scan_op.cpp | 21 +++++++++++++++++++ src/sql/engine/table/ob_table_scan_op.h | 1 + 3 files changed, 27 insertions(+) diff --git a/src/share/diagnosis/ob_sql_monitor_statname.h b/src/share/diagnosis/ob_sql_monitor_statname.h index 98c1b6ba10..620d728efd 100644 --- a/src/share/diagnosis/ob_sql_monitor_statname.h +++ b/src/share/diagnosis/ob_sql_monitor_statname.h @@ -52,6 +52,11 @@ SQL_MONITOR_STATNAME_DEF(SORT_DUMP_DATA_TIME, sql_monitor_statname::INT, "sort d // SSTABLE INSERT SQL_MONITOR_STATNAME_DEF(DDL_TASK_ID, sql_monitor_statname::INT, "ddl task id", "sort ddl task id") SQL_MONITOR_STATNAME_DEF(SSTABLE_INSERT_ROW_COUNT, sql_monitor_statname::INT, "sstable insert row count", "sstable insert row count") +// Table Scan stat +SQL_MONITOR_STATNAME_DEF(IO_READ_BYTES, sql_monitor_statname::CAPACITY, "total io bytes read from disk", "total io bytes read from storage") +SQL_MONITOR_STATNAME_DEF(TOTAL_READ_BYTES, sql_monitor_statname::CAPACITY, "total bytes processed by storage", "total bytes processed by storage, including memtable") +SQL_MONITOR_STATNAME_DEF(TOTAL_READ_ROW_COUNT, sql_monitor_statname::INT, "total rows processed by storage", "total rows processed by storage, including memtable") + //end SQL_MONITOR_STATNAME_DEF(MONITOR_STATNAME_END, sql_monitor_statname::INVALID, "monitor end", "monitor stat name end") #endif diff --git a/src/sql/engine/table/ob_table_scan_op.cpp b/src/sql/engine/table/ob_table_scan_op.cpp index 4cd30532b2..51c0d0f3dc 100644 --- a/src/sql/engine/table/ob_table_scan_op.cpp +++ b/src/sql/engine/table/ob_table_scan_op.cpp @@ -1305,6 +1305,9 @@ int ObTableScanOp::inner_close() LOG_WARN("failed to get next batch",K(ret)); } } + if (OB_SUCC(ret)) { + fill_sql_plan_monitor_info(); + } if (OB_SUCC(ret)) { iter_end_ = false; need_init_before_get_row_ = true; @@ -1313,6 +1316,24 @@ int ObTableScanOp::inner_close() return ret; } +void ObTableScanOp::fill_sql_plan_monitor_info() +{ + oceanbase::common::ObDiagnoseSessionInfo *di = oceanbase::common::ObDiagnoseSessionInfo::get_local_diagnose_info(); + if (OB_LIKELY(di)) { + // Hope to demostrate: + // 1. how many bytes read from io (IO_READ_BYTES) + // 2. how many bytes in total (DATA_BLOCK_READ_CNT + INDEX_BLOCK_READ_CNT) * 16K (approximately, many diff for each table) + // 3. how many rows processed before filtering (MEMSTORE_READ_ROW_COUNT + SSSTORE_READ_ROW_COUNT) + op_monitor_info_.otherstat_1_id_ = ObSqlMonitorStatIds::IO_READ_BYTES; + op_monitor_info_.otherstat_2_id_ = ObSqlMonitorStatIds::TOTAL_READ_BYTES; + op_monitor_info_.otherstat_3_id_ = ObSqlMonitorStatIds::TOTAL_READ_ROW_COUNT; + op_monitor_info_.otherstat_1_value_ = EVENT_GET(ObStatEventIds::IO_READ_BYTES, di); + // NOTE: this is not always accurate, as block size change be change from default 16K to any value + op_monitor_info_.otherstat_2_value_ = (EVENT_GET(ObStatEventIds::DATA_BLOCK_READ_CNT, di) + EVENT_GET(ObStatEventIds::INDEX_BLOCK_READ_CNT, di)) * 16 * 1024; + op_monitor_info_.otherstat_3_value_ = EVENT_GET(ObStatEventIds::MEMSTORE_READ_ROW_COUNT, di) + EVENT_GET(ObStatEventIds::SSSTORE_READ_ROW_COUNT, di); + } +} + int ObTableScanOp::do_init_before_get_row() { int ret = OB_SUCCESS; diff --git a/src/sql/engine/table/ob_table_scan_op.h b/src/sql/engine/table/ob_table_scan_op.h index 6027d7a945..e9622cf674 100644 --- a/src/sql/engine/table/ob_table_scan_op.h +++ b/src/sql/engine/table/ob_table_scan_op.h @@ -427,6 +427,7 @@ protected: ObNewRange &part_range); int fill_storage_feedback_info(); + void fill_sql_plan_monitor_info(); //int extract_scan_ranges(); void fill_table_scan_stat(const ObTableScanStatistic &statistic, ObTableScanStat &scan_stat) const;