From 100a1d83719d605e44014e5a7a375d30e34987b8 Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Fri, 28 Dec 2018 22:43:55 +0800 Subject: [PATCH 1/2] clean up code --- executor/write.go | 4 +--- store/tikv/snapshot.go | 5 ++++- table/tables/tables.go | 8 +------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/executor/write.go b/executor/write.go index 0e95344617fd2..b514601d7d641 100644 --- a/executor/write.go +++ b/executor/write.go @@ -129,7 +129,6 @@ func updateRecord(ctx sessionctx.Context, h int64, oldData, newData []types.Datu // 5. If handle changed, remove the old then add the new record, otherwise update the record. var err error if handleChanged { - skipHandleCheck := false if sc.DupKeyAsWarning { // For `UPDATE IGNORE`/`INSERT IGNORE ON DUPLICATE KEY UPDATE` // If the new handle exists, this will avoid to remove the record. @@ -137,13 +136,12 @@ func updateRecord(ctx sessionctx.Context, h int64, oldData, newData []types.Datu if err != nil { return false, handleChanged, newHandle, errors.Trace(err) } - skipHandleCheck = true } if err = t.RemoveRecord(ctx, h, oldData); err != nil { return false, false, 0, errors.Trace(err) } // the `affectedRows` is increased when adding new record. - newHandle, err = t.AddRecord(ctx, newData, skipHandleCheck) + newHandle, err = t.AddRecord(ctx, newData, sc.DupKeyAsWarning) if err != nil { return false, false, 0, errors.Trace(err) } diff --git a/store/tikv/snapshot.go b/store/tikv/snapshot.go index f82d8326b9976..2bb28f04ed47e 100644 --- a/store/tikv/snapshot.go +++ b/store/tikv/snapshot.go @@ -67,6 +67,10 @@ func (s *tikvSnapshot) SetPriority(priority int) { // BatchGet gets all the keys' value from kv-server and returns a map contains key/value pairs. // The map will not contain nonexistent keys. func (s *tikvSnapshot) BatchGet(keys []kv.Key) (map[string][]byte, error) { + m := make(map[string][]byte) + if len(keys) == 0 { + return m, nil + } metrics.TiKVTxnCmdCounter.WithLabelValues("batch_get").Inc() start := time.Now() defer func() { metrics.TiKVTxnCmdHistogram.WithLabelValues("batch_get").Observe(time.Since(start).Seconds()) }() @@ -78,7 +82,6 @@ func (s *tikvSnapshot) BatchGet(keys []kv.Key) (map[string][]byte, error) { // Create a map to collect key-values from region servers. var mu sync.Mutex - m := make(map[string][]byte) err := s.batchGetKeysByRegions(bo, bytesKeys, func(k, v []byte) { if len(v) == 0 { return diff --git a/table/tables/tables.go b/table/tables/tables.go index 356099ac08b85..985a3cb465c20 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -447,12 +447,6 @@ func (t *tableCommon) AddRecord(ctx sessionctx.Context, r []types.Datum, skipHan } sessVars := ctx.GetSessionVars() - // when LightningMode or BatchCheck is true, - // no needs to check the key constrains, so we names the variable skipCheck. - skipCheck := sessVars.LightningMode || ctx.GetSessionVars().StmtCtx.BatchCheck - if skipCheck { - txn.SetOption(kv.SkipCheckForWrite, true) - } rm, err := t.getRollbackableMemStore(ctx) // Insert new entries into indices. @@ -565,7 +559,7 @@ func (t *tableCommon) addIndices(ctx sessionctx.Context, recordID int64, r []typ return 0, errors.Trace(err2) } var dupKeyErr error - if !skipCheck && (v.Meta().Unique || v.Meta().Primary) { + if !skipCheck && v.Meta().Unique { entryKey, err1 := t.genIndexKeyStr(indexVals) if err1 != nil { return 0, errors.Trace(err1) From de9fce9bc44979e20390743eacf3bc48c0a6fdb7 Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Sat, 29 Dec 2018 15:10:21 +0800 Subject: [PATCH 2/2] address comments --- kv/kv.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/kv/kv.go b/kv/kv.go index df01e842f619a..2f0efd4352291 100644 --- a/kv/kv.go +++ b/kv/kv.go @@ -32,8 +32,6 @@ const ( PresumeKeyNotExistsError // BinlogInfo contains the binlog data and client. BinlogInfo - // Skip existing check when "prewrite". - SkipCheckForWrite // SchemaChecker is used for checking schema-validity. SchemaChecker // IsolationLevel sets isolation level for current transaction. The default level is SI.