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

Merged
merged 7 commits into from
Aug 15, 2023
Merged
Changes from 1 commit
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
Next Next commit
ddl: use the correct timezone to encode record for adding index
tangenta committed Aug 14, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
aitbw Angel Perez
commit d841247601ad7c49fb1fdf058fc2583c621bbd58
12 changes: 12 additions & 0 deletions ddl/index.go
Original file line number Diff line number Diff line change
@@ -1656,6 +1656,8 @@ func (w *addIndexIngestWorker) WriteLocal(rs *idxRecResult) (count int, nextKey
oprStartTime := time.Now()
copCtx := w.copReqSenderPool.copCtx
vars := w.sessCtx.GetSessionVars()
restore := setUTCTimezone(vars)
defer restore()
cnt, lastHandle, err := writeChunkToLocal(w.writer, w.index, copCtx, vars, rs.chunk)
if err != nil || cnt == 0 {
return 0, nil, err
@@ -1666,6 +1668,16 @@ func (w *addIndexIngestWorker) WriteLocal(rs *idxRecResult) (count int, nextKey
return cnt, nextKey, nil
}

// setUTCTimezone sets the timezone to UTC for the session variable.
// This is because the time value in coprocessor reader is in UTC.
func setUTCTimezone(vars *variable.SessionVars) (restore func()) {
originTZ := vars.TimeZone
vars.TimeZone = time.UTC
return func() {
vars.TimeZone = originTZ
}
}

func writeChunkToLocal(writer ingest.Writer,
index table.Index, copCtx *copContext, vars *variable.SessionVars,
copChunk *chunk.Chunk) (int, kv.Handle, error) {
13 changes: 13 additions & 0 deletions ddl/ingest/integration_test.go
Original file line number Diff line number Diff line change
@@ -323,3 +323,16 @@ func TestAddIndexIngestRecoverPartition(t *testing.T) {
tk.MustExec("alter table t add index idx(b);")
tk.MustExec("admin check table t;")
}

func TestAddIndexIngestTimezone(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
defer injectMockBackendMgr(t, store)()

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 -0600','2000-07-29 23:15:30 -0600','-6:00');")
tk.MustExec("alter table t add index idx(t);")
tk.MustExec("admin check table t;")
}