Skip to content

Commit

Permalink
util/stmtsummary: add the network traffic related fields (#58101)
Browse files Browse the repository at this point in the history
ref #57543
  • Loading branch information
nolouch authored Jan 8, 2025
1 parent 6c9ee36 commit d966219
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 223 deletions.
8 changes: 8 additions & 0 deletions pkg/infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,14 @@ var tableStatementsSummaryCols = []columnInfo{
{name: stmtsummary.ResourceGroupName, tp: mysql.TypeVarchar, size: 64, comment: "Bind resource group name"},
{name: stmtsummary.PlanCacheUnqualifiedStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag, comment: "The number of times that these statements are not supported by the plan cache"},
{name: stmtsummary.PlanCacheUnqualifiedLastReasonStr, tp: mysql.TypeBlob, size: types.UnspecifiedLength, comment: "The last reason why the statement is not supported by the plan cache"},
{name: stmtsummary.SumUnpackedBytesSentKVTotalStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag | mysql.UnsignedFlag, comment: "Average bytes sent to KV"},
{name: stmtsummary.SumUnpackedBytesReceivedKVTotalStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag | mysql.UnsignedFlag, comment: "Average bytes received from KV"},
{name: stmtsummary.SumUnpackedBytesSentKVCrossZoneStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag | mysql.UnsignedFlag, comment: "Average bytes sent to KV cross zone"},
{name: stmtsummary.SumUnpackedBytesReceivedKVCrossZoneStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag | mysql.UnsignedFlag, comment: "Average bytes received from KV cross zone"},
{name: stmtsummary.SumUnpackedBytesSentMPPTotalStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag | mysql.UnsignedFlag, comment: "Average bytes sent to MPP"},
{name: stmtsummary.SumUnpackedBytesReceivedMPPTotalStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag | mysql.UnsignedFlag, comment: "Average bytes received from MPP"},
{name: stmtsummary.SumUnpackedBytesSentMPPCrossZoneStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag | mysql.UnsignedFlag, comment: "Average bytes sent to MPP cross zone"},
{name: stmtsummary.SumUnpackedBytesReceiveMPPCrossZoneStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag | mysql.UnsignedFlag, comment: "Average bytes received from MPP cross zone"},
}

var tableTiDBStatementsStatsCols = []columnInfo{
Expand Down
247 changes: 140 additions & 107 deletions pkg/util/stmtsummary/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,113 +256,121 @@ func (ssc *stmtSummaryChecker) isDigestValid(digest string) bool {

// Statements summary table column name.
const (
ClusterTableInstanceColumnNameStr = "INSTANCE"
SummaryBeginTimeStr = "SUMMARY_BEGIN_TIME"
SummaryEndTimeStr = "SUMMARY_END_TIME"
StmtTypeStr = "STMT_TYPE"
SchemaNameStr = "SCHEMA_NAME"
DigestStr = "DIGEST"
DigestTextStr = "DIGEST_TEXT"
TableNamesStr = "TABLE_NAMES"
IndexNamesStr = "INDEX_NAMES"
SampleUserStr = "SAMPLE_USER"
ExecCountStr = "EXEC_COUNT"
SumErrorsStr = "SUM_ERRORS"
SumWarningsStr = "SUM_WARNINGS"
SumLatencyStr = "SUM_LATENCY"
MaxLatencyStr = "MAX_LATENCY"
MinLatencyStr = "MIN_LATENCY"
AvgLatencyStr = "AVG_LATENCY"
AvgParseLatencyStr = "AVG_PARSE_LATENCY"
MaxParseLatencyStr = "MAX_PARSE_LATENCY"
AvgCompileLatencyStr = "AVG_COMPILE_LATENCY"
MaxCompileLatencyStr = "MAX_COMPILE_LATENCY"
SumCopTaskNumStr = "SUM_COP_TASK_NUM"
MaxCopProcessTimeStr = "MAX_COP_PROCESS_TIME"
MaxCopProcessAddressStr = "MAX_COP_PROCESS_ADDRESS"
MaxCopWaitTimeStr = "MAX_COP_WAIT_TIME" // #nosec G101
MaxCopWaitAddressStr = "MAX_COP_WAIT_ADDRESS" // #nosec G101
AvgProcessTimeStr = "AVG_PROCESS_TIME"
MaxProcessTimeStr = "MAX_PROCESS_TIME"
AvgWaitTimeStr = "AVG_WAIT_TIME"
MaxWaitTimeStr = "MAX_WAIT_TIME"
AvgBackoffTimeStr = "AVG_BACKOFF_TIME"
MaxBackoffTimeStr = "MAX_BACKOFF_TIME"
AvgTotalKeysStr = "AVG_TOTAL_KEYS"
MaxTotalKeysStr = "MAX_TOTAL_KEYS"
AvgProcessedKeysStr = "AVG_PROCESSED_KEYS"
MaxProcessedKeysStr = "MAX_PROCESSED_KEYS"
AvgRocksdbDeleteSkippedCountStr = "AVG_ROCKSDB_DELETE_SKIPPED_COUNT"
MaxRocksdbDeleteSkippedCountStr = "MAX_ROCKSDB_DELETE_SKIPPED_COUNT"
AvgRocksdbKeySkippedCountStr = "AVG_ROCKSDB_KEY_SKIPPED_COUNT"
MaxRocksdbKeySkippedCountStr = "MAX_ROCKSDB_KEY_SKIPPED_COUNT"
AvgRocksdbBlockCacheHitCountStr = "AVG_ROCKSDB_BLOCK_CACHE_HIT_COUNT"
MaxRocksdbBlockCacheHitCountStr = "MAX_ROCKSDB_BLOCK_CACHE_HIT_COUNT"
AvgRocksdbBlockReadCountStr = "AVG_ROCKSDB_BLOCK_READ_COUNT"
MaxRocksdbBlockReadCountStr = "MAX_ROCKSDB_BLOCK_READ_COUNT"
AvgRocksdbBlockReadByteStr = "AVG_ROCKSDB_BLOCK_READ_BYTE"
MaxRocksdbBlockReadByteStr = "MAX_ROCKSDB_BLOCK_READ_BYTE"
AvgPrewriteTimeStr = "AVG_PREWRITE_TIME"
MaxPrewriteTimeStr = "MAX_PREWRITE_TIME"
AvgCommitTimeStr = "AVG_COMMIT_TIME"
MaxCommitTimeStr = "MAX_COMMIT_TIME"
AvgGetCommitTsTimeStr = "AVG_GET_COMMIT_TS_TIME"
MaxGetCommitTsTimeStr = "MAX_GET_COMMIT_TS_TIME"
AvgCommitBackoffTimeStr = "AVG_COMMIT_BACKOFF_TIME"
MaxCommitBackoffTimeStr = "MAX_COMMIT_BACKOFF_TIME"
AvgResolveLockTimeStr = "AVG_RESOLVE_LOCK_TIME"
MaxResolveLockTimeStr = "MAX_RESOLVE_LOCK_TIME"
AvgLocalLatchWaitTimeStr = "AVG_LOCAL_LATCH_WAIT_TIME"
MaxLocalLatchWaitTimeStr = "MAX_LOCAL_LATCH_WAIT_TIME"
AvgWriteKeysStr = "AVG_WRITE_KEYS"
MaxWriteKeysStr = "MAX_WRITE_KEYS"
AvgWriteSizeStr = "AVG_WRITE_SIZE"
MaxWriteSizeStr = "MAX_WRITE_SIZE"
AvgPrewriteRegionsStr = "AVG_PREWRITE_REGIONS"
MaxPrewriteRegionsStr = "MAX_PREWRITE_REGIONS"
AvgTxnRetryStr = "AVG_TXN_RETRY"
MaxTxnRetryStr = "MAX_TXN_RETRY"
SumExecRetryStr = "SUM_EXEC_RETRY"
SumExecRetryTimeStr = "SUM_EXEC_RETRY_TIME"
SumBackoffTimesStr = "SUM_BACKOFF_TIMES"
BackoffTypesStr = "BACKOFF_TYPES"
AvgMemStr = "AVG_MEM"
MaxMemStr = "MAX_MEM"
AvgDiskStr = "AVG_DISK"
MaxDiskStr = "MAX_DISK"
AvgKvTimeStr = "AVG_KV_TIME"
AvgPdTimeStr = "AVG_PD_TIME"
AvgBackoffTotalTimeStr = "AVG_BACKOFF_TOTAL_TIME"
AvgWriteSQLRespTimeStr = "AVG_WRITE_SQL_RESP_TIME"
AvgTidbCPUTimeStr = "AVG_TIDB_CPU_TIME"
AvgTikvCPUTimeStr = "AVG_TIKV_CPU_TIME"
MaxResultRowsStr = "MAX_RESULT_ROWS"
MinResultRowsStr = "MIN_RESULT_ROWS"
AvgResultRowsStr = "AVG_RESULT_ROWS"
PreparedStr = "PREPARED"
AvgAffectedRowsStr = "AVG_AFFECTED_ROWS"
FirstSeenStr = "FIRST_SEEN"
LastSeenStr = "LAST_SEEN"
PlanInCacheStr = "PLAN_IN_CACHE"
PlanCacheHitsStr = "PLAN_CACHE_HITS"
PlanCacheUnqualifiedStr = "PLAN_CACHE_UNQUALIFIED"
PlanCacheUnqualifiedLastReasonStr = "PLAN_CACHE_UNQUALIFIED_LAST_REASON"
PlanInBindingStr = "PLAN_IN_BINDING"
QuerySampleTextStr = "QUERY_SAMPLE_TEXT"
PrevSampleTextStr = "PREV_SAMPLE_TEXT"
PlanDigestStr = "PLAN_DIGEST"
PlanStr = "PLAN"
BinaryPlan = "BINARY_PLAN"
Charset = "CHARSET"
Collation = "COLLATION"
PlanHint = "PLAN_HINT"
AvgRequestUnitReadStr = "AVG_REQUEST_UNIT_READ"
MaxRequestUnitReadStr = "MAX_REQUEST_UNIT_READ"
AvgRequestUnitWriteStr = "AVG_REQUEST_UNIT_WRITE"
MaxRequestUnitWriteStr = "MAX_REQUEST_UNIT_WRITE"
AvgQueuedRcTimeStr = "AVG_QUEUED_RC_TIME"
MaxQueuedRcTimeStr = "MAX_QUEUED_RC_TIME"
ResourceGroupName = "RESOURCE_GROUP"
ClusterTableInstanceColumnNameStr = "INSTANCE"
SummaryBeginTimeStr = "SUMMARY_BEGIN_TIME"
SummaryEndTimeStr = "SUMMARY_END_TIME"
StmtTypeStr = "STMT_TYPE"
SchemaNameStr = "SCHEMA_NAME"
DigestStr = "DIGEST"
DigestTextStr = "DIGEST_TEXT"
TableNamesStr = "TABLE_NAMES"
IndexNamesStr = "INDEX_NAMES"
SampleUserStr = "SAMPLE_USER"
ExecCountStr = "EXEC_COUNT"
SumErrorsStr = "SUM_ERRORS"
SumWarningsStr = "SUM_WARNINGS"
SumLatencyStr = "SUM_LATENCY"
MaxLatencyStr = "MAX_LATENCY"
MinLatencyStr = "MIN_LATENCY"
AvgLatencyStr = "AVG_LATENCY"
AvgParseLatencyStr = "AVG_PARSE_LATENCY"
MaxParseLatencyStr = "MAX_PARSE_LATENCY"
AvgCompileLatencyStr = "AVG_COMPILE_LATENCY"
MaxCompileLatencyStr = "MAX_COMPILE_LATENCY"
SumCopTaskNumStr = "SUM_COP_TASK_NUM"
MaxCopProcessTimeStr = "MAX_COP_PROCESS_TIME"
MaxCopProcessAddressStr = "MAX_COP_PROCESS_ADDRESS"
MaxCopWaitTimeStr = "MAX_COP_WAIT_TIME" // #nosec G101
MaxCopWaitAddressStr = "MAX_COP_WAIT_ADDRESS" // #nosec G101
AvgProcessTimeStr = "AVG_PROCESS_TIME"
MaxProcessTimeStr = "MAX_PROCESS_TIME"
AvgWaitTimeStr = "AVG_WAIT_TIME"
MaxWaitTimeStr = "MAX_WAIT_TIME"
AvgBackoffTimeStr = "AVG_BACKOFF_TIME"
MaxBackoffTimeStr = "MAX_BACKOFF_TIME"
AvgTotalKeysStr = "AVG_TOTAL_KEYS"
MaxTotalKeysStr = "MAX_TOTAL_KEYS"
AvgProcessedKeysStr = "AVG_PROCESSED_KEYS"
MaxProcessedKeysStr = "MAX_PROCESSED_KEYS"
AvgRocksdbDeleteSkippedCountStr = "AVG_ROCKSDB_DELETE_SKIPPED_COUNT"
MaxRocksdbDeleteSkippedCountStr = "MAX_ROCKSDB_DELETE_SKIPPED_COUNT"
AvgRocksdbKeySkippedCountStr = "AVG_ROCKSDB_KEY_SKIPPED_COUNT"
MaxRocksdbKeySkippedCountStr = "MAX_ROCKSDB_KEY_SKIPPED_COUNT"
AvgRocksdbBlockCacheHitCountStr = "AVG_ROCKSDB_BLOCK_CACHE_HIT_COUNT"
MaxRocksdbBlockCacheHitCountStr = "MAX_ROCKSDB_BLOCK_CACHE_HIT_COUNT"
AvgRocksdbBlockReadCountStr = "AVG_ROCKSDB_BLOCK_READ_COUNT"
MaxRocksdbBlockReadCountStr = "MAX_ROCKSDB_BLOCK_READ_COUNT"
AvgRocksdbBlockReadByteStr = "AVG_ROCKSDB_BLOCK_READ_BYTE"
MaxRocksdbBlockReadByteStr = "MAX_ROCKSDB_BLOCK_READ_BYTE"
AvgPrewriteTimeStr = "AVG_PREWRITE_TIME"
MaxPrewriteTimeStr = "MAX_PREWRITE_TIME"
AvgCommitTimeStr = "AVG_COMMIT_TIME"
MaxCommitTimeStr = "MAX_COMMIT_TIME"
AvgGetCommitTsTimeStr = "AVG_GET_COMMIT_TS_TIME"
MaxGetCommitTsTimeStr = "MAX_GET_COMMIT_TS_TIME"
AvgCommitBackoffTimeStr = "AVG_COMMIT_BACKOFF_TIME"
MaxCommitBackoffTimeStr = "MAX_COMMIT_BACKOFF_TIME"
AvgResolveLockTimeStr = "AVG_RESOLVE_LOCK_TIME"
MaxResolveLockTimeStr = "MAX_RESOLVE_LOCK_TIME"
AvgLocalLatchWaitTimeStr = "AVG_LOCAL_LATCH_WAIT_TIME"
MaxLocalLatchWaitTimeStr = "MAX_LOCAL_LATCH_WAIT_TIME"
AvgWriteKeysStr = "AVG_WRITE_KEYS"
MaxWriteKeysStr = "MAX_WRITE_KEYS"
AvgWriteSizeStr = "AVG_WRITE_SIZE"
MaxWriteSizeStr = "MAX_WRITE_SIZE"
AvgPrewriteRegionsStr = "AVG_PREWRITE_REGIONS"
MaxPrewriteRegionsStr = "MAX_PREWRITE_REGIONS"
AvgTxnRetryStr = "AVG_TXN_RETRY"
MaxTxnRetryStr = "MAX_TXN_RETRY"
SumExecRetryStr = "SUM_EXEC_RETRY"
SumExecRetryTimeStr = "SUM_EXEC_RETRY_TIME"
SumBackoffTimesStr = "SUM_BACKOFF_TIMES"
BackoffTypesStr = "BACKOFF_TYPES"
AvgMemStr = "AVG_MEM"
MaxMemStr = "MAX_MEM"
AvgDiskStr = "AVG_DISK"
MaxDiskStr = "MAX_DISK"
AvgKvTimeStr = "AVG_KV_TIME"
AvgPdTimeStr = "AVG_PD_TIME"
AvgBackoffTotalTimeStr = "AVG_BACKOFF_TOTAL_TIME"
AvgWriteSQLRespTimeStr = "AVG_WRITE_SQL_RESP_TIME"
AvgTidbCPUTimeStr = "AVG_TIDB_CPU_TIME"
AvgTikvCPUTimeStr = "AVG_TIKV_CPU_TIME"
MaxResultRowsStr = "MAX_RESULT_ROWS"
MinResultRowsStr = "MIN_RESULT_ROWS"
AvgResultRowsStr = "AVG_RESULT_ROWS"
PreparedStr = "PREPARED"
AvgAffectedRowsStr = "AVG_AFFECTED_ROWS"
FirstSeenStr = "FIRST_SEEN"
LastSeenStr = "LAST_SEEN"
PlanInCacheStr = "PLAN_IN_CACHE"
PlanCacheHitsStr = "PLAN_CACHE_HITS"
PlanCacheUnqualifiedStr = "PLAN_CACHE_UNQUALIFIED"
PlanCacheUnqualifiedLastReasonStr = "PLAN_CACHE_UNQUALIFIED_LAST_REASON"
PlanInBindingStr = "PLAN_IN_BINDING"
QuerySampleTextStr = "QUERY_SAMPLE_TEXT"
PrevSampleTextStr = "PREV_SAMPLE_TEXT"
PlanDigestStr = "PLAN_DIGEST"
PlanStr = "PLAN"
BinaryPlan = "BINARY_PLAN"
Charset = "CHARSET"
Collation = "COLLATION"
PlanHint = "PLAN_HINT"
AvgRequestUnitReadStr = "AVG_REQUEST_UNIT_READ"
MaxRequestUnitReadStr = "MAX_REQUEST_UNIT_READ"
AvgRequestUnitWriteStr = "AVG_REQUEST_UNIT_WRITE"
MaxRequestUnitWriteStr = "MAX_REQUEST_UNIT_WRITE"
AvgQueuedRcTimeStr = "AVG_QUEUED_RC_TIME"
MaxQueuedRcTimeStr = "MAX_QUEUED_RC_TIME"
ResourceGroupName = "RESOURCE_GROUP"
SumUnpackedBytesSentKVTotalStr = "SUM_UNPACKED_BYTES_SENT_KV_TOTAL"
SumUnpackedBytesReceivedKVTotalStr = "SUM_UNPACKED_BYTES_RECEIVED_KV_TOTAL"
SumUnpackedBytesSentKVCrossZoneStr = "SUM_UNPACKED_BYTES_SENT_KV_CROSS_ZONE"
SumUnpackedBytesReceivedKVCrossZoneStr = "SUM_UNPACKED_BYTES_RECEIVED_KV_CROSS_ZONE"
SumUnpackedBytesSentMPPTotalStr = "SUM_UNPACKED_BYTES_SENT_MPP_TOTAL"
SumUnpackedBytesReceivedMPPTotalStr = "SUM_UNPACKED_BYTES_RECEIVED_MPP_TOTAL"
SumUnpackedBytesSentMPPCrossZoneStr = "SUM_UNPACKED_BYTES_SENT_MPP_CROSS_ZONE"
SumUnpackedBytesReceiveMPPCrossZoneStr = "SUM_UNPACKED_BYTES_RECEIVED_MPP_CROSS_ZONE"
)

// Column names for the statement stats table, including columns that have been
Expand Down Expand Up @@ -888,4 +896,29 @@ var columnValueFactoryMap = map[string]columnValueFactory{
PlanCacheUnqualifiedLastReasonStr: func(_ *stmtSummaryReader, _ *stmtSummaryByDigestElement, _ *stmtSummaryByDigest, ssStats *stmtSummaryStats) any {
return ssStats.lastPlanCacheUnqualified
},
SumUnpackedBytesSentKVTotalStr: func(_ *stmtSummaryReader, _ *stmtSummaryByDigestElement, _ *stmtSummaryByDigest, ssStats *stmtSummaryStats) any {
return ssStats.UnpackedBytesSentKVTotal
},

SumUnpackedBytesReceivedKVTotalStr: func(_ *stmtSummaryReader, _ *stmtSummaryByDigestElement, _ *stmtSummaryByDigest, ssStats *stmtSummaryStats) any {
return ssStats.UnpackedBytesReceivedKVTotal
},
SumUnpackedBytesSentKVCrossZoneStr: func(_ *stmtSummaryReader, _ *stmtSummaryByDigestElement, _ *stmtSummaryByDigest, ssStats *stmtSummaryStats) any {
return ssStats.UnpackedBytesSentKVCrossZone
},
SumUnpackedBytesReceivedKVCrossZoneStr: func(_ *stmtSummaryReader, _ *stmtSummaryByDigestElement, _ *stmtSummaryByDigest, ssStats *stmtSummaryStats) any {
return ssStats.UnpackedBytesReceivedKVCrossZone
},
SumUnpackedBytesSentMPPTotalStr: func(_ *stmtSummaryReader, _ *stmtSummaryByDigestElement, _ *stmtSummaryByDigest, ssStats *stmtSummaryStats) any {
return ssStats.UnpackedBytesSentMPPTotal
},
SumUnpackedBytesReceivedMPPTotalStr: func(_ *stmtSummaryReader, _ *stmtSummaryByDigestElement, _ *stmtSummaryByDigest, ssStats *stmtSummaryStats) any {
return ssStats.UnpackedBytesReceivedMPPTotal
},
SumUnpackedBytesSentMPPCrossZoneStr: func(_ *stmtSummaryReader, _ *stmtSummaryByDigestElement, _ *stmtSummaryByDigest, ssStats *stmtSummaryStats) any {
return ssStats.UnpackedBytesSentMPPCrossZone
},
SumUnpackedBytesReceiveMPPCrossZoneStr: func(_ *stmtSummaryReader, _ *stmtSummaryByDigestElement, _ *stmtSummaryByDigest, ssStats *stmtSummaryStats) any {
return ssStats.UnpackedBytesReceivedMPPCrossZone
},
}
Loading

0 comments on commit d966219

Please sign in to comment.