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

add unique index may cause dangle index #40583

Closed
wjhuang2016 opened this issue Jan 13, 2023 · 1 comment
Closed

add unique index may cause dangle index #40583

wjhuang2016 opened this issue Jan 13, 2023 · 1 comment
Labels
fuzz/schrddl severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@wjhuang2016
Copy link
Member

wjhuang2016 commented Jan 13, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

There is no simple way to reproduce.
We need to modify the code.
Here is the test case:

func TestAddIndexMergeDeleteUniqueOnWriteOnly(t *testing.T) {
	store, dom := testkit.CreateMockStoreAndDomain(t)

	tk := testkit.NewTestKit(t, store)
	tk.MustExec("use test")
	tk.MustExec("create table t(a enum('a', 'b', 'c', 'd', 'e', 'f'), b int default 0, c int, primary key(b, a) clustered, unique key(c));")

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

	d := dom.DDL()
	originalCallback := d.GetHook()
	defer d.SetHook(originalCallback)
	callback := &ddl.TestDDLCallback{}
	onJobUpdatedExportedFunc := func(job *model.Job) {
		if t.Failed() {
			return
		}
		var err error
		switch job.SchemaState {
		case model.StateDeleteOnly:
		case model.StateWriteOnly:
			_, err = tk1.Exec("insert into t values ('b', 5, 4);")
			assert.NoError(t, err)
		}
	}
	callback.OnJobRunBeforeExported = onJobUpdatedExportedFunc
	d.SetHook(callback)
	tk.MustExec("alter table t add unique index idx(a);")
	tk.MustExec("admin check table t;")
}

besides:
in doReorgWorkForCreateIndex()

		case model.ReorgTypeTxnMerge:
			done, ver, err = runReorgJobAndHandleErr(w, d, t, job, tbl, indexInfo, false)
			if err != nil || !done {
				return false, ver, errors.Trace(err)
			}

			sess, _ := w.sessPool.get()
			defer w.sessPool.put(sess)
			se := newSession(sess)
			_, err = se.execute(w.ctx, "update test.t set b=7;", "")
			if err != nil {
				return false, 0, err
			}
			_, err = se.execute(w.ctx, "delete from test.t;", "")
			if err != nil {
				return false, 0, err
			}
		}
		indexInfo.BackfillState = model.BackfillStateReadyToMerge

Modify the code to execute these two queries before the index schema change to BackfillStateReadyToMerge.

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

test pass

3. What did you see instead (Required)

admin check table t;, [], error stack [admin:8223]data inconsistency in table: t, index: idx, handle: {5, 2}, index-values:"handle: {5, 2}, values: [KindMysqlEnum b KindInt64 5 KindMysqlEnum b]" != record-values:""

4. What is your TiDB version? (Required)

master

@wjhuang2016 wjhuang2016 added type/bug The issue is confirmed as a bug. sig/sql-infra SIG: SQL Infra severity/critical fuzz/schrddl labels Jan 13, 2023
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 may-affects-6.2 may-affects-6.3 may-affects-6.4 may-affects-6.5 labels Jan 13, 2023
@wjhuang2016 wjhuang2016 removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.0 may-affects-6.1 may-affects-6.2 may-affects-6.3 may-affects-6.4 may-affects-6.5 labels Jan 13, 2023
@wjhuang2016
Copy link
Member Author

closed by #40672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzz/schrddl severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

2 participants