From 8e525d8d882241fabb902bdae0d2d3b79b5cf6a8 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Sat, 11 Dec 2021 14:45:57 +0800 Subject: [PATCH] ddl: remove unnecessary locking when adding an index (#29772) --- ddl/column.go | 2 +- ddl/index.go | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/ddl/column.go b/ddl/column.go index 0136ce40e315c..1507e7437982c 100644 --- a/ddl/column.go +++ b/ddl/column.go @@ -1427,7 +1427,7 @@ func (w *updateColumnWorker) cleanRowMap() { } } -// BackfillDataInTxn will backfill the table record in a transaction, lock corresponding rowKey, if the value of rowKey is changed. +// BackfillDataInTxn will backfill the table record in a transaction. func (w *updateColumnWorker) BackfillDataInTxn(handleRange reorgBackfillTask) (taskCtx backfillTaskContext, errInTxn error) { oprStartTime := time.Now() errInTxn = kv.RunInNewTxn(context.Background(), w.sessCtx.GetStore(), true, func(ctx context.Context, txn kv.Transaction) error { diff --git a/ddl/index.go b/ddl/index.go index b6a14dfa9eeb0..ffa9d069d4c09 100644 --- a/ddl/index.go +++ b/ddl/index.go @@ -1293,8 +1293,8 @@ func (w *addIndexWorker) batchCheckUniqueKey(txn kv.Transaction, idxRecords []*i return nil } -// BackfillDataInTxn will backfill table index in a transaction, lock corresponding rowKey, if the value of rowKey is changed, -// indicate that index columns values may changed, index is not allowed to be added, so the txn will rollback and retry. +// BackfillDataInTxn will backfill table index in a transaction. If the value of rowKey is changed, there must be some other transactions +// update the row, result in write conflict, so the txn will rollback and retry. // BackfillDataInTxn will add w.batchCnt indices once, default value of w.batchCnt is 128. func (w *addIndexWorker) BackfillDataInTxn(handleRange reorgBackfillTask) (taskCtx backfillTaskContext, errInTxn error) { failpoint.Inject("errorMockPanic", func(val failpoint.Value) { @@ -1329,13 +1329,6 @@ func (w *addIndexWorker) BackfillDataInTxn(handleRange reorgBackfillTask) (taskC continue } - // Lock the row key to notify us that someone delete or update the row, - // then we should not backfill the index of it, otherwise the adding index is redundant. - err := txn.LockKeys(context.Background(), new(kv.LockCtx), idxRecord.key) - if err != nil { - return errors.Trace(err) - } - // Create the index. handle, err := w.index.Create(w.sessCtx, txn, idxRecord.vals, idxRecord.handle, idxRecord.rsData) if err != nil {