code: func CheckHandleExists(ctx sessionctx.Context, t table.Table, recordID int64, data []types.Datum) error {
  	if pt, ok := t.(*partitionedTable); ok {
  		info := t.Meta().GetPartitionInfo()
  		pid, err := pt.locatePartition(ctx, info, data)
  		if err != nil {
  			return err
  		}
  		t = pt.GetPartition(pid)
  	}
  	txn, err := ctx.Txn(true)
  	if err != nil {
  		return err
  	}
  	// Check key exists.
  	recordKey := t.RecordKey(recordID)
  	e := kv.ErrKeyExists.FastGen("Duplicate entry '%d' for key 'PRIMARY'", recordID)
  	txn.SetOption(kv.PresumeKeyNotExistsError, e)
  	defer txn.DelOption(kv.PresumeKeyNotExistsError)
  	_, err = txn.Get(recordKey)
  	if err == nil {
  		return e
  	} else if !kv.ErrNotExist.Equal(err) {
  		return err
  	}
  	return nil
  }
docs: // CheckHandleExists check whether recordID key exists. if not exists, return nil,
  // otherwise return kv.ErrKeyExists error.