From 8bba5293c009db26ac32498227e2530ff9ab105e Mon Sep 17 00:00:00 2001 From: tangenta Date: Sun, 8 Oct 2023 15:33:22 +0800 Subject: [PATCH] ddl: fix DST times for adding index (#47425) ref pingcap/tidb#46033, close pingcap/tidb#47426 --- ddl/db_test.go | 10 +++++----- ddl/index_cop.go | 2 +- ddl/ingest/integration_test.go | 3 +++ ddl/util/util.go | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ddl/db_test.go b/ddl/db_test.go index 64a0442063e0f..aefcad56e751a 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -139,12 +139,12 @@ func TestGetTimeZone(t *testing.T) { offset int err string }{ - {"set time_zone = '+00:00'", "", "UTC", 0, ""}, - {"set time_zone = '-00:00'", "", "UTC", 0, ""}, + {"set time_zone = '+00:00'", "", "", 0, ""}, + {"set time_zone = '-00:00'", "", "", 0, ""}, {"set time_zone = 'UTC'", "UTC", "UTC", 0, ""}, - {"set time_zone = '+05:00'", "", "UTC", 18000, ""}, - {"set time_zone = '-08:00'", "", "UTC", -28800, ""}, - {"set time_zone = '+08:00'", "", "UTC", 28800, ""}, + {"set time_zone = '+05:00'", "", "", 18000, ""}, + {"set time_zone = '-08:00'", "", "", -28800, ""}, + {"set time_zone = '+08:00'", "", "", 28800, ""}, {"set time_zone = 'Asia/Shanghai'", "Asia/Shanghai", "Asia/Shanghai", 0, ""}, {"set time_zone = 'SYSTEM'", "Asia/Shanghai", "Asia/Shanghai", 0, ""}, {"set time_zone = DEFAULT", "Asia/Shanghai", "Asia/Shanghai", 0, ""}, diff --git a/ddl/index_cop.go b/ddl/index_cop.go index d90b88cae8fd9..8098855cb79ef 100644 --- a/ddl/index_cop.go +++ b/ddl/index_cop.go @@ -482,7 +482,7 @@ func getRestoreData(tblInfo *model.TableInfo, targetIdx, pkIdx *model.IndexInfo, func buildDAGPB(sCtx sessionctx.Context, tblInfo *model.TableInfo, colInfos []*model.ColumnInfo) (*tipb.DAGRequest, error) { dagReq := &tipb.DAGRequest{} - _, dagReq.TimeZoneOffset = timeutil.Zone(sCtx.GetSessionVars().Location()) + dagReq.TimeZoneName, dagReq.TimeZoneOffset = timeutil.Zone(sCtx.GetSessionVars().Location()) sc := sCtx.GetSessionVars().StmtCtx dagReq.Flags = sc.PushDownFlags() for i := range colInfos { diff --git a/ddl/ingest/integration_test.go b/ddl/ingest/integration_test.go index ca1871f0dcfde..8c0f22c9a3509 100644 --- a/ddl/ingest/integration_test.go +++ b/ddl/ingest/integration_test.go @@ -199,12 +199,15 @@ func TestAddIndexIngestTimezone(t *testing.T) { tk.MustExec("SET time_zone = '-06:00';") tk.MustExec("create table t (`src` varchar(48),`t` timestamp,`timezone` varchar(100));") tk.MustExec("insert into t values('2000-07-29 23:15:30','2000-07-29 23:15:30','-6:00');") + // Test Daylight time. + tk.MustExec("insert into t values('1991-07-21 00:00:00','1991-07-21 00:00:00','-6:00');") tk.MustExec("alter table t add index idx(t);") tk.MustExec("admin check table t;") tk.MustExec("alter table t drop index idx;") tk.MustExec("SET time_zone = 'Asia/Shanghai';") tk.MustExec("insert into t values('2000-07-29 23:15:30','2000-07-29 23:15:30', '+8:00');") + tk.MustExec("insert into t values('1991-07-21 00:00:00','1991-07-21 00:00:00','+8:00');") tk.MustExec("alter table t add index idx(t);") tk.MustExec("admin check table t;") } diff --git a/ddl/util/util.go b/ddl/util/util.go index c0765e6fbe9bb..525aade903966 100644 --- a/ddl/util/util.go +++ b/ddl/util/util.go @@ -230,7 +230,7 @@ func GetTimeZone(sctx sessionctx.Context) (string, int) { } } _, offset := time.Now().In(loc).Zone() - return "UTC", offset + return "", offset } // enableEmulatorGC means whether to enable emulator GC. The default is enable.