Skip to content

Commit

Permalink
*: check delete unique key's handle to handle corner case (#52975) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jun 6, 2024
1 parent 460a563 commit 702c864
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions table/tables/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,28 @@ func (c *index) Delete(sc *stmtctx.StatementContext, txn kv.Transaction, indexed

if distinct {
if len(key) > 0 {
err = txn.GetMemBuffer().DeleteWithFlags(key, kv.SetNeedLocked)
if err != nil {
return err
okToDelete := true
if c.idxInfo.BackfillState != model.BackfillStateInapplicable {
// #52914: the delete key is covered by the new ingested key, which shouldn't be deleted.
originVal, err := getKeyInTxn(context.TODO(), txn, key)
if err != nil {
return err
}
if len(originVal) > 0 {
oh, err := tablecodec.DecodeHandleInUniqueIndexValue(originVal, c.tblInfo.IsCommonHandle)
if err != nil {
return err
}
if !h.Equal(oh) {
okToDelete = false
}
}
}
if okToDelete {
err = txn.GetMemBuffer().DeleteWithFlags(key, kv.SetNeedLocked)
if err != nil {
return err
}
}
}
if len(tempKey) > 0 {
Expand Down

0 comments on commit 702c864

Please sign in to comment.