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

executor, infoschema: Add cluster_statements_summary_evicted table to TiDB (#25418) #25587

Merged
merged 6 commits into from
Jul 23, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,7 @@ func (b *executorBuilder) buildMemTable(v *plannercore.PhysicalMemTable) Executo
strings.ToLower(infoschema.TableStatementsSummaryEvicted),
strings.ToLower(infoschema.ClusterTableStatementsSummary),
strings.ToLower(infoschema.ClusterTableStatementsSummaryHistory),
strings.ToLower(infoschema.ClusterTableStatementsSummaryEvicted),
strings.ToLower(infoschema.TablePlacementPolicy),
strings.ToLower(infoschema.TableClientErrorsSummaryGlobal),
strings.ToLower(infoschema.TableClientErrorsSummaryByUser),
Expand Down
16 changes: 8 additions & 8 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex
err = e.dataForTiKVStoreStatus(sctx)
case infoschema.TableStatementsSummary,
infoschema.TableStatementsSummaryHistory,
infoschema.TableStatementsSummaryEvicted,
infoschema.ClusterTableStatementsSummary,
infoschema.ClusterTableStatementsSummaryHistory:
infoschema.ClusterTableStatementsSummaryHistory,
infoschema.ClusterTableStatementsSummaryEvicted:
err = e.setDataForStatementsSummary(sctx, e.table.Name.O)
case infoschema.TableStatementsSummaryEvicted:
e.setDataForStatementsSummaryEvicted(sctx)
case infoschema.TablePlacementPolicy:
err = e.setDataForPlacementPolicy(sctx)
case infoschema.TableClientErrorsSummaryGlobal,
Expand Down Expand Up @@ -1941,10 +1941,14 @@ func (e *memtableRetriever) setDataForStatementsSummary(ctx sessionctx.Context,
case infoschema.TableStatementsSummaryHistory,
infoschema.ClusterTableStatementsSummaryHistory:
e.rows = stmtsummary.StmtSummaryByDigestMap.ToHistoryDatum(user, isSuper)
case infoschema.TableStatementsSummaryEvicted,
infoschema.ClusterTableStatementsSummaryEvicted:
e.rows = stmtsummary.StmtSummaryByDigestMap.ToEvictedCountDatum()
}
switch tableName {
case infoschema.ClusterTableStatementsSummary,
infoschema.ClusterTableStatementsSummaryHistory:
infoschema.ClusterTableStatementsSummaryHistory,
infoschema.ClusterTableStatementsSummaryEvicted:
rows, err := infoschema.AppendHostInfoToRows(ctx, e.rows)
if err != nil {
return err
Expand Down Expand Up @@ -2130,10 +2134,6 @@ func (e *memtableRetriever) setDataForClusterDeadlock(ctx sessionctx.Context) er
return nil
}

func (e *memtableRetriever) setDataForStatementsSummaryEvicted(ctx sessionctx.Context) {
e.rows = stmtsummary.StmtSummaryByDigestMap.ToEvictedCountDatum()
}

type hugeMemTableRetriever struct {
dummyCloser
table *model.TableInfo
Expand Down
3 changes: 3 additions & 0 deletions infoschema/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
ClusterTableStatementsSummary = "CLUSTER_STATEMENTS_SUMMARY"
// ClusterTableStatementsSummaryHistory is the string constant of cluster statement summary history table.
ClusterTableStatementsSummaryHistory = "CLUSTER_STATEMENTS_SUMMARY_HISTORY"
// ClusterTableStatementsSummaryEvicted is the string constant of cluster statement summary evict table.
ClusterTableStatementsSummaryEvicted = "CLUSTER_STATEMENTS_SUMMARY_EVICTED"
// ClusterTableTiDBTrx is the string constant of cluster transaction running table.
ClusterTableTiDBTrx = "CLUSTER_TIDB_TRX"
// ClusterTableDeadlocks is the string constant of cluster dead lock table.
Expand All @@ -49,6 +51,7 @@ var memTableToClusterTables = map[string]string{
TableProcesslist: ClusterTableProcesslist,
TableStatementsSummary: ClusterTableStatementsSummary,
TableStatementsSummaryHistory: ClusterTableStatementsSummaryHistory,
TableStatementsSummaryEvicted: ClusterTableStatementsSummaryEvicted,
TableTiDBTrx: ClusterTableTiDBTrx,
TableDeadlocks: ClusterTableDeadlocks,
}
Expand Down
1 change: 1 addition & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ var tableIDMap = map[string]int64{
ClusterTableDeadlocks: autoid.InformationSchemaDBID + 73,
TableDataLockWaits: autoid.InformationSchemaDBID + 74,
TableStatementsSummaryEvicted: autoid.InformationSchemaDBID + 75,
ClusterTableStatementsSummaryEvicted: autoid.InformationSchemaDBID + 76,
}

type columnInfo struct {
Expand Down
34 changes: 32 additions & 2 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,12 +1374,18 @@ func (s *testTableSuite) TestStmtSummarySensitiveQuery(c *C) {
))
}

// test stmtSummaryEvictedCount
func (s *testTableSuite) TestSimpleStmtSummaryEvictedCount(c *C) {
now := time.Now().Unix()
interval := int64(1800)
beginTimeForCurInterval := now - now%interval
tk := s.newTestKitWithPlanCache(c)
tk.MustExec(fmt.Sprintf("set global tidb_stmt_summary_refresh_interval = %v", interval))

// clean up side effects
defer tk.MustExec("set global tidb_stmt_summary_max_stmt_count = 100")
defer tk.MustExec("set global tidb_stmt_summary_refresh_interval = 1800")

tk.MustExec("set global tidb_enable_stmt_summary = 0")
tk.MustExec("set global tidb_enable_stmt_summary = 1")
// first sql
Expand All @@ -1395,10 +1401,34 @@ func (s *testTableSuite) TestSimpleStmtSummaryEvictedCount(c *C) {
int64(2)),
))
// TODO: Add more tests.
}

// test stmtSummaryEvictedCount cluster table
func (s *testClusterTableSuite) TestStmtSummaryEvictedCountTable(c *C) {
tk := s.newTestKitWithRoot(c)
// disable refreshing
tk.MustExec("set global tidb_stmt_summary_refresh_interval=9999")
// set information_schema.statements_summary's size to 1
tk.MustExec("set global tidb_stmt_summary_max_stmt_count = 1")
// clean up side effects
tk.MustExec("set global tidb_stmt_summary_max_stmt_count = 100")
tk.MustExec("set global tidb_stmt_summary_refresh_interval = 1800")
defer tk.MustExec("set global tidb_stmt_summary_max_stmt_count = 100")
defer tk.MustExec("set global tidb_stmt_summary_refresh_interval = 1800")
// clear information_schema.statements_summary
tk.MustExec("set global tidb_enable_stmt_summary=0")
tk.MustExec("set global tidb_enable_stmt_summary=1")

// make a new session for test...
tk = s.newTestKitWithRoot(c)
// first sql
tk.MustExec("show databases;")
// second sql, evict former sql from stmt_summary
tk.MustQuery("select evicted_count from information_schema.cluster_statements_summary_evicted;").
Check(testkit.Rows("1"))
// after executed the sql above
tk.MustQuery("select evicted_count from information_schema.cluster_statements_summary_evicted;").
Check(testkit.Rows("2"))
// TODO: Add more tests.

}

func (s *testTableSuite) TestPerformanceSchemaforPlanCache(c *C) {
Expand Down