Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: use the correct timezone to encode record for adding index (#46055) #46104

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ddl/index_cop.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,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.TimeZoneName, dagReq.TimeZoneOffset = timeutil.Zone(sCtx.GetSessionVars().Location())
_, dagReq.TimeZoneOffset = timeutil.Zone(sCtx.GetSessionVars().Location())
Copy link
Contributor

@zimulala zimulala Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we only need to change 'TimeZoneName' and not 'TimeZoneOffset'?

sc := sCtx.GetSessionVars().StmtCtx
dagReq.Flags = sc.PushDownFlags()
for i := range colInfos {
Expand Down
21 changes: 21 additions & 0 deletions tests/realtikvtest/addindextest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,24 @@ func TestAddIndexSplitTableRanges(t *testing.T) {
tk.MustExec("admin check table t;")
ddl.SetBackfillTaskChanSizeForTest(1024)
}

func TestAddIndexIngestTimezone(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists addindexlit;")
tk.MustExec("create database addindexlit;")
tk.MustExec("use addindexlit;")
tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`)

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');")
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("alter table t add index idx(t);")
tk.MustExec("admin check table t;")
}