Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stmtsummary: stmtsummary with keyspace #41882

Merged
merged 4 commits into from Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions executor/BUILD.bazel
Expand Up @@ -117,6 +117,7 @@ go_library(
"//expression",
"//expression/aggregation",
"//infoschema",
"//keyspace",
"//kv",
"//meta",
"//meta/autoid",
Expand Down
12 changes: 12 additions & 0 deletions executor/adapter.go
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/keyspace"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/parser"
Expand Down Expand Up @@ -1946,6 +1947,15 @@ func (a *ExecStmt) SummaryStmt(succ bool) {

resultRows := GetResultRowsCount(stmtCtx, a.Plan)

var (
keyspaceName string
keyspaceID uint32
)
keyspaceName = keyspace.GetKeyspaceNameBySettings()
if !keyspace.IsKeyspaceNameEmpty(keyspaceName) {
keyspaceID = uint32(a.Ctx.GetStore().GetCodec().GetKeyspaceID())
}

stmtExecInfo := &stmtsummary.StmtExecInfo{
SchemaName: strings.ToLower(sessVars.CurrentDB),
OriginalSQL: sql,
Expand Down Expand Up @@ -1978,6 +1988,8 @@ func (a *ExecStmt) SummaryStmt(succ bool) {
ResultRows: resultRows,
TiKVExecDetails: tikvExecDetail,
Prepared: a.isPreparedStmt,
KeyspaceName: keyspaceName,
KeyspaceID: keyspaceID,
}
if a.retryCount > 0 {
stmtExecInfo.ExecRetryTime = costTime - sessVars.DurationParse - sessVars.DurationCompile - time.Since(a.retryStartTime)
Expand Down
2 changes: 2 additions & 0 deletions util/stmtsummary/statement_summary.go
Expand Up @@ -246,6 +246,8 @@ type StmtExecInfo struct {
ResultRows int64
TiKVExecDetails util.ExecDetails
Prepared bool
KeyspaceName string
KeyspaceID uint32
}

// newStmtSummaryByDigestMap creates an empty stmtSummaryByDigestMap.
Expand Down
15 changes: 11 additions & 4 deletions util/stmtsummary/v2/record.go
Expand Up @@ -144,6 +144,9 @@ type StmtRecord struct {
// Pessimistic execution retry information.
ExecRetryCount uint `json:"exec_retry_count"`
ExecRetryTime time.Duration `json:"exec_retry_time"`

KeyspaceName string `json:"keyspace_name,omitempty"`
KeyspaceID uint32 `json:"keyspace_id,omitempty"`
}

// NewStmtRecord creates a new StmtRecord from StmtExecInfo.
Expand Down Expand Up @@ -209,6 +212,8 @@ func NewStmtRecord(info *stmtsummary.StmtExecInfo) *StmtRecord {
Prepared: info.Prepared,
FirstSeen: info.StartTime,
LastSeen: info.StartTime,
KeyspaceName: info.KeyspaceName,
KeyspaceID: info.KeyspaceID,
}
}

Expand Down Expand Up @@ -651,10 +656,12 @@ func GenerateStmtExecInfo4Test(digest string) *stmtsummary.StmtExecInfo {
Tables: tables,
IndexNames: indexes,
},
MemMax: 10000,
DiskMax: 10000,
StartTime: time.Date(2019, 1, 1, 10, 10, 10, 10, time.UTC),
Succeed: true,
MemMax: 10000,
DiskMax: 10000,
StartTime: time.Date(2019, 1, 1, 10, 10, 10, 10, time.UTC),
Succeed: true,
KeyspaceName: "keyspace_a",
KeyspaceID: 1,
}
stmtExecInfo.StmtCtx.AddAffectedRows(10000)
return stmtExecInfo
Expand Down
2 changes: 2 additions & 0 deletions util/stmtsummary/v2/record_test.go
Expand Up @@ -39,6 +39,8 @@ func TestStmtRecord(t *testing.T) {
require.Equal(t, info.Prepared, record1.Prepared)
require.Equal(t, info.StartTime, record1.FirstSeen)
require.Equal(t, info.StartTime, record1.LastSeen)
require.Equal(t, info.KeyspaceName, record1.KeyspaceName)
require.Equal(t, info.KeyspaceID, record1.KeyspaceID)
require.Empty(t, record1.AuthUsers)
require.Zero(t, record1.ExecCount)
require.Zero(t, record1.SumLatency)
Expand Down