code: func (e *ReplaceExec) replaceRow(r toBeCheckedRow) error {
  	if r.handleKey != nil {
  		if _, found := e.dupKVs[string(r.handleKey.newKV.key)]; found {
  			handle, err := tablecodec.DecodeRowKey(r.handleKey.newKV.key)
  			if err != nil {
  				return err
  			}
  			rowUnchanged, err := e.removeRow(handle, r)
  			if err != nil {
  				return err
  			}
  			if rowUnchanged {
  				return nil
  			}
  		}
  	}
  
  	// Keep on removing duplicated rows.
  	for {
  		rowUnchanged, foundDupKey, err := e.removeIndexRow(r)
  		if err != nil {
  			return err
  		}
  		if rowUnchanged {
  			return nil
  		}
  		if foundDupKey {
  			continue
  		}
  		break
  	}
  
  	// No duplicated rows now, insert the row.
  	newHandle, err := e.addRecord(r.row)
  	if err != nil {
  		return err
  	}
  	e.fillBackKeys(r.t, r, newHandle)
  	return nil
  }
docs: // replaceRow removes all duplicate rows for one row, then inserts it.