Skip to content

Commit

Permalink
skip null row when deleting multiple tables
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <[email protected]>
  • Loading branch information
ekexium committed Jan 5, 2022
1 parent 397eb72 commit d6d7b2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 14 additions & 1 deletion executor/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,21 @@ func (e *DeleteExec) doBatchDelete(ctx context.Context) error {
}

func (e *DeleteExec) composeTblRowMap(tblRowMap tableRowMapType, colPosInfos []plannercore.TblColPosInfo, joinedRow []types.Datum) error {
// iterate all the joined tables, and got the copresonding rows in joinedRow.
// iterate all the joined tables, and got the corresonding rows in joinedRow.
for _, info := range colPosInfos {
// if row[start..end] is a null row, which is possible in an outer join, we should not delete it.
nullRow := true
for _, d := range joinedRow[info.Start:info.End] {
if d.IsNull() {
continue
}
nullRow = false
break
}
if nullRow {
continue
}

if tblRowMap[info.TblID] == nil {
tblRowMap[info.TblID] = kv.NewHandleMap()
}
Expand Down
14 changes: 14 additions & 0 deletions table/tables/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,17 @@ func TestConstraintCheckForOptimisticUntouched(t *testing.T) {
err = tk.ExecToErr("commit")
require.Error(t, err)
}

func TestAssertion(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table a (k1 int);")
tk.MustExec("create table b (id int primary key, k1 int);")
tk.MustExec("insert into a(k1) values(3);")
tk.MustExec("insert into b values(2, 2);")
tk.MustExec("insert into b values(0, 0);")
tk.MustExec("delete a,b from a left join b on a.k1 = b.k1")
tk.MustQuery("select * from b order by id").Check(testkit.Rows("0 0", "2 2"))
}

0 comments on commit d6d7b2b

Please sign in to comment.