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

data inconsistency during adding unique index #52874

Open
wjhuang2016 opened this issue Apr 24, 2024 · 0 comments · May be fixed by #52900
Open

data inconsistency during adding unique index #52874

wjhuang2016 opened this issue Apr 24, 2024 · 0 comments · May be fixed by #52900
Assignees
Labels

Comments

@wjhuang2016
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

func TestInsertIgnore2(t *testing.T) {
	store, dom := testkit.CreateMockStoreAndDomain(t)
	defer ingesttestutil.InjectMockBackendMgr(t, store)()

	tk := testkit.NewTestKit(t, store)
	tk.MustExec("use test")
	tk.MustExec("create table t(a int DEFAULT '-13202', b varchar(221) NOT NULL DEFAULT 'duplicatevalue', " +
		"c int NOT NULL DEFAULT '0', PRIMARY KEY (c, b));")

	tk1 := testkit.NewTestKit(t, store)
	tk1.MustExec("use test")

	d := dom.DDL()
	originalCallback := d.GetHook()
	defer d.SetHook(originalCallback)
	callback := &callback.TestDDLCallback{}

	tk1.Exec("INSERT INTO t VALUES (-18585,'duplicatevalue',0);")

	onJobUpdatedExportedFunc := func(job *model.Job) {
		switch job.SchemaState {
		case model.StateDeleteOnly:
			_, err := tk1.Exec("REPLACE INTO t VALUES (-18585,'duplicatevalue',1);")
			assert.NoError(t, err)
		}
	}
	callback.OnJobUpdatedExported.Store(&onJobUpdatedExportedFunc)
	d.SetHook(callback)

	tk3 := testkit.NewTestKit(t, store)
	tk3.MustExec("use test")
	ddl.MockDMLExecutionStateBeforeImport = func() {
		tk3.MustExec("insert ignore INTO t VALUES (-18585,'duplicatevalue',1), (-18585,'duplicatevalue',3);")
	}

	require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionStateBeforeImport", "return(true)"))
	tk.MustExec("alter table t add unique index idx(b);")
	tk.MustExec("admin check table t;")
	require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionStateBeforeImport"))
}

2. What did you expect to see? (Required)

Test passes.

3. What did you see instead (Required)

[admin:8223]data inconsistency in table: t, index: idx, handle: {0, duplicatevalue}, index-values:"" != record-values:"handle: {0, duplicatevalue}, values: [KindString duplicatevalue]"

4. What is your TiDB version? (Required)

nightly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants