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
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -1666,10 +1666,22 @@
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 *stmtctx.StatementContext) (restore func()) {
originTZ := vars.TimeZone
vars.TimeZone = time.UTC
return func() {
vars.TimeZone = originTZ
}

Check warning on line 1676 in ddl/index.go

View check run for this annotation

Codecov / codecov/patch

ddl/index.go#L1671-L1676

Added lines #L1671 - L1676 were not covered by tests
}

func writeChunkToLocal(writer ingest.Writer,
index table.Index, copCtx *copContext, vars *variable.SessionVars,
copChunk *chunk.Chunk) (int, kv.Handle, error) {
sCtx, writeBufs := vars.StmtCtx, vars.GetWriteStmtBufs()
restore := setUTCTimezone(sCtx)
defer restore()

Check warning on line 1684 in ddl/index.go

View check run for this annotation

Codecov / codecov/patch

ddl/index.go#L1683-L1684

Added lines #L1683 - L1684 were not covered by tests
iter := chunk.NewIterator4Chunk(copChunk)
idxDataBuf := make([]types.Datum, len(copCtx.idxColOutputOffsets))
handleDataBuf := make([]types.Datum, len(copCtx.handleOutputOffsets))
Expand Down
2 changes: 1 addition & 1 deletion ddl/ingest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ go_test(
embed = [":ingest"],
flaky = True,
race = "on",
shard_count = 14,
shard_count = 15,
deps = [
"//config",
"//ddl",
Expand Down
13 changes: 13 additions & 0 deletions ddl/ingest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;")
}