Skip to content

Commit

Permalink
ddl: fix DST times for adding index (pingcap#47425)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored and ti-chi-bot committed Oct 8, 2023
1 parent 753fb3d commit 8bba529
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
10 changes: 5 additions & 5 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""},
Expand Down
2 changes: 1 addition & 1 deletion ddl/index_cop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions ddl/ingest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
}
2 changes: 1 addition & 1 deletion ddl/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8bba529

Please sign in to comment.