From 62cf19d53b5882afa330a6f60b2b169390296f65 Mon Sep 17 00:00:00 2001 From: Yang Keao Date: Tue, 22 Oct 2024 21:04:49 +0800 Subject: [PATCH] replace session in statsHistoryHandler with types.Context Signed-off-by: Yang Keao --- pkg/server/handler/optimizor/BUILD.bazel | 1 - pkg/server/handler/optimizor/statistics_handler.go | 12 +++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/pkg/server/handler/optimizor/BUILD.bazel b/pkg/server/handler/optimizor/BUILD.bazel index f1281d3456b1e..cccf9b5498c63 100644 --- a/pkg/server/handler/optimizor/BUILD.bazel +++ b/pkg/server/handler/optimizor/BUILD.bazel @@ -17,7 +17,6 @@ go_library( "//pkg/parser/model", "//pkg/parser/mysql", "//pkg/server/handler", - "//pkg/session", "//pkg/sessionctx/variable", "//pkg/statistics/handle", "//pkg/statistics/handle/util", diff --git a/pkg/server/handler/optimizor/statistics_handler.go b/pkg/server/handler/optimizor/statistics_handler.go index 462ca8cb73978..897b91309ea46 100644 --- a/pkg/server/handler/optimizor/statistics_handler.go +++ b/pkg/server/handler/optimizor/statistics_handler.go @@ -26,7 +26,6 @@ import ( "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/server/handler" - "github.com/pingcap/tidb/pkg/session" "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/table" "github.com/pingcap/tidb/pkg/types" @@ -95,12 +94,6 @@ func (sh StatsHistoryHandler) ServeHTTP(w http.ResponseWriter, req *http.Request w.Header().Set("Content-Type", "application/json") params := mux.Vars(req) - se, err := session.CreateSession(sh.do.Store()) - if err != nil { - handler.WriteError(w, err) - return - } - defer se.Close() enabeld, err := sh.do.StatsHandle().CheckHistoricalStatsEnable() if err != nil { handler.WriteError(w, err) @@ -111,8 +104,9 @@ func (sh StatsHistoryHandler) ServeHTTP(w http.ResponseWriter, req *http.Request return } - se.GetSessionVars().StmtCtx.SetTimeZone(time.Local) - t, err := types.ParseTime(se.GetSessionVars().StmtCtx.TypeCtx(), params[handler.Snapshot], mysql.TypeTimestamp, 6) + typeCtx := types.DefaultStmtNoWarningContext + typeCtx = typeCtx.WithLocation(time.Local) + t, err := types.ParseTime(typeCtx, params[handler.Snapshot], mysql.TypeTimestamp, 6) if err != nil { handler.WriteError(w, err) return