*: use session time_zone for is.tables and show table status (#32449)

ref pingcap/tidb#26642
This commit is contained in:
Mattias Jonsson
2022-02-28 23:09:45 +01:00
committed by GitHub
parent f9a324829b
commit 584ae75df5
5 changed files with 41 additions and 5 deletions

View File

@ -1672,12 +1672,18 @@ func (s *session) useCurrentSession(execOption sqlexec.ExecOption) (*session, fu
if execOption.AnalyzeVer != 0 {
s.sessionVars.AnalyzeVersion = execOption.AnalyzeVer
}
prevSQL := s.sessionVars.StmtCtx.OriginalSQL
prevStmtType := s.sessionVars.StmtCtx.StmtType
prevTables := s.sessionVars.StmtCtx.Tables
return s, func() {
s.sessionVars.AnalyzeVersion = prevStatsVer
if err := s.sessionVars.SetSystemVar(variable.TiDBSnapshot, ""); err != nil {
logutil.BgLogger().Error("set tidbSnapshot error", zap.Error(err))
}
s.sessionVars.SnapshotInfoschema = nil
s.sessionVars.StmtCtx.OriginalSQL = prevSQL
s.sessionVars.StmtCtx.StmtType = prevStmtType
s.sessionVars.StmtCtx.Tables = prevTables
}, nil
}

View File

@ -2132,17 +2132,30 @@ func (s *testSessionSuite2) TestDeletePanic(c *C) {
func (s *testSessionSuite2) TestInformationSchemaCreateTime(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("create table t (c int)")
tk.MustExec(`set @@time_zone = 'Asia/Shanghai'`)
ret := tk.MustQuery("select create_time from information_schema.tables where table_name='t';")
// Make sure t1 is greater than t.
time.Sleep(time.Second)
tk.MustExec("alter table t modify c int default 11")
ret1 := tk.MustQuery("select create_time from information_schema.tables where table_name='t';")
ret2 := tk.MustQuery("show table status like 't'")
c.Assert(ret1.Rows()[0][0].(string), Equals, ret2.Rows()[0][11].(string))
t, err := types.ParseDatetime(nil, ret.Rows()[0][0].(string))
c.Assert(err, IsNil)
t1, err := types.ParseDatetime(nil, ret1.Rows()[0][0].(string))
c.Assert(err, IsNil)
r := t1.Compare(t)
c.Assert(r, Equals, 1)
// Check that time_zone changes makes the create_time different
tk.MustExec(`set @@time_zone = 'Europe/Amsterdam'`)
ret = tk.MustQuery(`select create_time from information_schema.tables where table_name='t'`)
ret2 = tk.MustQuery(`show table status like 't'`)
c.Assert(ret.Rows()[0][0].(string), Equals, ret2.Rows()[0][11].(string))
t, err = types.ParseDatetime(nil, ret.Rows()[0][0].(string))
c.Assert(err, IsNil)
// Asia/Shanghai 2022-02-17 17:40:05 > Europe/Amsterdam 2022-02-17 10:40:05
r = t1.Compare(t)
c.Assert(r, Equals, 1)
}
type testSchemaSuiteBase struct {