Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table: don't compare different types of handles #29600

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions table/tables/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,14 @@ func buildTableInfo(t *testing.T, sql string) *model.TableInfo {
require.NoError(t, err)
return tblInfo
}

func TestIssue29520(t *testing.T) {
store, close := testkit.CreateMockStore(t)
defer close()
tk := testkit.NewTestKit(t, store)
tk.MustExec("set @@tidb_enable_mutation_checker=1")
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(c year, PRIMARY KEY (c) CLUSTERED, KEY i1(c))")
tk.MustExec("insert into t values('2020')")
}
3 changes: 2 additions & 1 deletion table/tables/mutation_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ func checkHandleConsistency(rowInsertion mutation, indexMutations []mutation, in
if err != nil {
return errors.Trace(err)
}
if indexHandle.Compare(insertionHandle) != 0 {
// NOTE: handle type can be different, see issue 29520
if indexHandle.IsInt() == insertionHandle.IsInt() && indexHandle.Compare(insertionHandle) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the common handle type?

Copy link
Contributor Author

@ekexium ekexium Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indexHandle.IsInt() == insertionHandle.IsInt()
will evaluate to
false == false

Copy link
Contributor

@cfzjywxk cfzjywxk Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to compare and check if indexHandle.IsCommon() == insertionHandle.IsCommon() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no such a method. I think we are only using IsInt() to distinguish handle types.

Copy link
Contributor

@MyonKeminta MyonKeminta Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just notice there is an Equal method in the Handle interface which checks the type:

func (ih IntHandle) Equal(h Handle) bool {
	return h.IsInt() && int64(ih) == h.IntValue()
}

@ekexium Can we use this instead?

In this way the third kind of handle i.e. PartitionHandle (which is not used currently) can also be handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the problem is what we should do if Equal returns false. We can't tell if it's type mismatch or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have only two kind of handles that are usable now, I think indexHandle.IsInt() == insertionHandle.IsInt() is enough.
Maybe a better way is to add a method to get the kind, and check something like indexHandle.Kind() == insertionHandle.Kind().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we check the handle content if it's int type, if it's clustered index handle type or common type do we need to check if the content does match?

Copy link
Contributor

@MyonKeminta MyonKeminta Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cfzjywxk The expression indexHandle.IsInt() == insertionHandle.IsInt() checks equality of two bools, rather than AND. Two falses evaluates to true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds some implicit dependencies that there are two types of handle, as this constraint will not change very much seems it's fine.

return errors.Errorf("inconsistent handles in row and index insertions. index handle = %v, "+
"row handle = %v, index = %+v, row = %+v",
indexHandle, insertionHandle, m, rowInsertion)
Expand Down