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

insert ignore may cause data and index inconsistency #51784

Closed
wjhuang2016 opened this issue Mar 14, 2024 · 0 comments · Fixed by #51862
Closed

insert ignore may cause data and index inconsistency #51784

wjhuang2016 opened this issue Mar 14, 2024 · 0 comments · Fixed by #51862
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.0 component/ddl This issue is related to DDL of TiDB. fuzz/schrddl severity/critical type/bug The issue is confirmed as a bug.

Comments

@wjhuang2016
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

store, dom := testkit.CreateMockStoreAndDomain(t)

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

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

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

	d := dom.DDL()
	originalCallback := d.GetHook()
	defer d.SetHook(originalCallback)
	callback := &callback.TestDDLCallback{}
	//_, err := tk1.Exec("INSERT INTO t VALUES (-18585,'+zmNHMov7KF~tF*DFb',1), (-18585,'0',1), (-18585,'1',1), (-18585,'9k23s0uioddlcahb5qmd9mulds8hd6go0q6cxlsshbj3w9y08yuqcky1gv90eldi4ylbno8ofs15o2exlyka6vt653idyy84b0s8qxtnxq501',1), (-18585,'Q',1), (-18585,'s',1);;")
	//assert.NoError(t, err)

	onJobUpdatedExportedFunc := func(job *model.Job) {
		if t.Failed() {
			return
		}
		switch job.SchemaState {
		case model.StateDeleteOnly:
			_, err := tk1.Exec("INSERT INTO t VALUES (-18585,'+zmNHMov7KF~tF*DFb',1), (-18585,'0',1), (-18585,'1',1), (-18585,'9k23s0uioddlcahb5qmd9mulds8hd6go0q6cxlsshbj3w9y08yuqcky1gv90eldi4ylbno8ofs15o2exlyka6vt653idyy84b0s8qxtnxq501',1), (-18585,'Q',1), (-18585,'s',1);;")
			assert.NoError(t, err)
		case model.StateWriteReorganization:
			idx := testutil.FindIdxInfo(dom, "test", "t", "idx")
			if idx.BackfillState == model.BackfillStateReadyToMerge {
				_, err := tk1.Exec("insert ignore into `t`  values ( '06j$GwD*zizDUEEy&*-',null,-2028 ) ,( '((J)',0,17786 ) ,( 'SD$ruyO$%c',1,null ) ,( 'a3Ex',0,24877 ) ,( 'O=M',1,31913 ) ,( '7njQI*',0,17610 );")
				assert.NoError(t, err)
				return
			}
		}
	}
	callback.OnJobUpdatedExported.Store(&onJobUpdatedExportedFunc)
	d.SetHook(callback)

	tk.MustExec("alter table t add unique index idx(b);")
	tk.MustExec("admin check table t;")

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

test pass

3. What did you see instead (Required)

failed

4. What is your TiDB version? (Required)

master

@wjhuang2016 wjhuang2016 added type/bug The issue is confirmed as a bug. fuzz/schrddl labels Mar 14, 2024
@jebter jebter added component/ddl This issue is related to DDL of TiDB. and removed sig/transaction SIG:Transaction labels Mar 15, 2024
@wjhuang2016 wjhuang2016 added affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. and removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 labels Mar 18, 2024
ti-chi-bot bot pushed a commit that referenced this issue Mar 22, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this issue Mar 22, 2024
ti-chi-bot bot pushed a commit that referenced this issue Mar 25, 2024
ti-chi-bot bot pushed a commit that referenced this issue Apr 16, 2024
ti-chi-bot bot pushed a commit that referenced this issue May 27, 2024
@wjhuang2016 wjhuang2016 added the affects-6.5 This bug affects the 6.5.x(LTS) versions. label Sep 14, 2024
wjhuang2016 pushed a commit to ti-chi-bot/tidb that referenced this issue Sep 14, 2024
ti-chi-bot bot pushed a commit that referenced this issue Sep 17, 2024
@tangenta tangenta changed the title insert ignore may cause data and index inconsistence insert ignore may cause data and index inconsistency Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.0 component/ddl This issue is related to DDL of TiDB. fuzz/schrddl severity/critical type/bug The issue is confirmed as a bug.
Projects
None yet
3 participants