From 7c620dda79b2612fa721c775d04a046dae4d2c15 Mon Sep 17 00:00:00 2001 From: tangenta Date: Wed, 7 Dec 2022 20:02:03 +0800 Subject: [PATCH] This is an automated cherry-pick of #39683 Signed-off-by: ti-chi-bot --- ddl/backfilling.go | 9 ++++++++- .../realtikvtest/addindextest/integration_test.go | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ddl/backfilling.go b/ddl/backfilling.go index be120e18c1465..6214a50b4a2e9 100644 --- a/ddl/backfilling.go +++ b/ddl/backfilling.go @@ -503,6 +503,7 @@ func (dc *ddlCtx) handleRangeTasks(scheduler *backfillScheduler, t table.Table, job := reorgInfo.Job source := getDDLRequestSource(job) for i, keyRange := range kvRanges { + startKey := keyRange.StartKey endKey := keyRange.EndKey endK, err := getRangeEndKey(scheduler.jobCtx, dc.store, job.Priority, prefix, keyRange.StartKey, endKey) if err != nil { @@ -512,11 +513,17 @@ func (dc *ddlCtx) handleRangeTasks(scheduler *backfillScheduler, t table.Table, zap.String("end key", hex.EncodeToString(endKey)), zap.String("current end key", hex.EncodeToString(endK))) endKey = endK } + if len(startKey) == 0 { + startKey = prefix + } + if len(endKey) == 0 { + endKey = prefix.PrefixNext() + } task := &reorgBackfillTask{ id: i, physicalTableID: physicalTableID, - startKey: keyRange.StartKey, + startKey: startKey, endKey: endKey, // If the boundaries overlap, we should ignore the preceding endKey. endInclude: endK.Cmp(keyRange.EndKey) != 0 || i == len(kvRanges)-1, diff --git a/tests/realtikvtest/addindextest/integration_test.go b/tests/realtikvtest/addindextest/integration_test.go index d5159450c50c5..aa3bb0d0f68ba 100644 --- a/tests/realtikvtest/addindextest/integration_test.go +++ b/tests/realtikvtest/addindextest/integration_test.go @@ -261,12 +261,17 @@ func TestAddIndexIngestGeneratedColumns(t *testing.T) { assertLastNDDLUseIngest(4) } +<<<<<<< HEAD func TestAddIndexIngestRestoredData(t *testing.T) { +======= +func TestAddIndexIngestEmptyTable(t *testing.T) { +>>>>>>> b6098ef6925 (ddl: assign table record prefix to start/end key if it is empty (#39683)) 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;") +<<<<<<< HEAD tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`) tk.MustExec(` @@ -283,11 +288,18 @@ func TestAddIndexIngestRestoredData(t *testing.T) { tk.MustExec("INSERT INTO tbl_5 VALUES ('15:33:15','&U+x1',2007,'','Bob');") tk.MustExec("alter table tbl_5 add unique key idx_13 ( col_23 );") tk.MustExec("admin check table tbl_5;") +======= + tk.MustExec("create table t (a int);") + tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`) + tk.MustExec("alter table t add index idx(a);") + +>>>>>>> b6098ef6925 (ddl: assign table record prefix to start/end key if it is empty (#39683)) rows := tk.MustQuery("admin show ddl jobs 1;").Rows() require.Len(t, rows, 1) jobTp := rows[0][3].(string) require.True(t, strings.Contains(jobTp, "ingest"), jobTp) } +<<<<<<< HEAD func TestAddIndexIngestPanicOnCopRead(t *testing.T) { store := realtikvtest.CreateMockStoreAndSetup(t) @@ -388,3 +400,5 @@ func TestAddIndexIngestTimezone(t *testing.T) { tk.MustExec("alter table t add index idx(t);") tk.MustExec("admin check table t;") } +======= +>>>>>>> b6098ef6925 (ddl: assign table record prefix to start/end key if it is empty (#39683))