From 76953b2e526eb6d466ccbcd68f6d3d2ab27e7155 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Fri, 18 Aug 2023 01:41:01 +0800 Subject: [PATCH] ddl: use the correct timezone to encode record for adding index (#46055) (#46104) close pingcap/tidb#46033 --- ddl/index_cop.go | 2 +- .../addindextest/integration_test.go | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ddl/index_cop.go b/ddl/index_cop.go index 56bc7ab42ac25..9c29d7ce5abad 100644 --- a/ddl/index_cop.go +++ b/ddl/index_cop.go @@ -492,7 +492,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()) sc := sCtx.GetSessionVars().StmtCtx dagReq.Flags = sc.PushDownFlags() for i := range colInfos { diff --git a/tests/realtikvtest/addindextest/integration_test.go b/tests/realtikvtest/addindextest/integration_test.go index 7fe3378fc08a7..d5159450c50c5 100644 --- a/tests/realtikvtest/addindextest/integration_test.go +++ b/tests/realtikvtest/addindextest/integration_test.go @@ -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;") +}