From c9e8d20eddcbe7c657fd9c5489125b8549f8a288 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 9 Nov 2023 14:16:10 +0800 Subject: [PATCH] update Signed-off-by: Weizhen Wang --- pkg/executor/historical_stats_test.go | 6 ++++-- pkg/session/session.go | 6 +++++- pkg/statistics/handle/storage/gc.go | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/executor/historical_stats_test.go b/pkg/executor/historical_stats_test.go index 7bae6baf819b1..65e54f20f5140 100644 --- a/pkg/executor/historical_stats_test.go +++ b/pkg/executor/historical_stats_test.go @@ -238,8 +238,10 @@ func TestAssertHistoricalStatsAfterAlterTable(t *testing.T) { } func TestGCOutdatedHistoryStats(t *testing.T) { - failpoint.Enable("github.com/pingcap/tidb/pkg/domain/sendHistoricalStats", "return(true)") - defer failpoint.Disable("github.com/pingcap/tidb/pkg/domain/sendHistoricalStats") + require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/domain/sendHistoricalStats", "return(true)")) + defer func() { + require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/domain/sendHistoricalStats")) + }() store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store) tk.MustExec("set global tidb_enable_historical_stats = 1") diff --git a/pkg/session/session.go b/pkg/session/session.go index 4c1a62e08e6ad..35dc9925f262f 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -1641,8 +1641,12 @@ func (s *session) ExecuteInternal(ctx context.Context, sql string, args ...inter if err != nil { return nil, err } + if sq, ok := stmtNode.(*ast.NonTransactionalDMLStmt); ok { + rs, err = HandleNonTransactionalDML(ctx, sq, s) + } else { + rs, err = s.ExecuteStmt(ctx, stmtNode) + } - rs, err = s.ExecuteStmt(ctx, stmtNode) if err != nil { s.sessionVars.StmtCtx.AppendError(err) } diff --git a/pkg/statistics/handle/storage/gc.go b/pkg/statistics/handle/storage/gc.go index dd340b6acb305..2bbb72bc2a92f 100644 --- a/pkg/statistics/handle/storage/gc.go +++ b/pkg/statistics/handle/storage/gc.go @@ -182,12 +182,12 @@ func ClearOutdatedHistoryStats(sctx sessionctx.Context) error { } count := rows[0].GetInt64(0) if count > 0 { - sql = "batch on table_id limit 100 delete from mysql.stats_meta_history use index (idx_create_time) where create_time <= NOW() - INTERVAL %? SECOND" + sql = "batch on create_time limit 10 delete from mysql.stats_meta_history use index (idx_create_time) where create_time <= NOW() - INTERVAL %? SECOND" _, err = util.Exec(sctx, sql, variable.HistoricalStatsDuration.Load().Seconds()) if err != nil { return err } - sql = "batch on table_id limit 100 delete from mysql.stats_history use index (idx_create_time) where create_time <= NOW() - INTERVAL %? SECOND" + sql = "batch on create_time limit 10 delete from mysql.stats_history use index (idx_create_time) where create_time <= NOW() - INTERVAL %? SECOND" _, err = util.Exec(sctx, sql, variable.HistoricalStatsDuration.Load().Seconds()) logutil.BgLogger().Info("clear outdated historical stats") return err