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

executor: 'select * from information_schema.tables' fail after setting @@tidb_snapshot (#18676) #18691

Closed

Conversation

ti-srebot
Copy link
Contributor

cherry-pick #18676 to release-3.1


What problem does this PR solve?

Issue Number: close #18347

Problem Summary:

The reproduce steps:

	create database gzj_test_db
	create table gzj_test_db.ad_account_record_log (id int auto_increment primary key)
	select now()
	drop database gzj_test_db
        set @@tidb_snapshot = '2020-07-18 23:56:05'   // now() 
	select * from information_schema.tables

'Table gzj_test_db.ad_account_record_log' doesn't exist

What is changed and how it works?

What's Changed:

getAutoIncrementID should consider the @@tidb_snapshot variable, use infoschema.GetInfoSchema(ctx)

How it Works:

func GetInfoSchemaBySessionVars(sessVar *variable.SessionVars) InfoSchema {
	var is InfoSchema
	if snap := sessVar.SnapshotInfoschema; snap != nil {
		is = snap.(InfoSchema)
		logutil.BgLogger().Info("use snapshot schema", zap.Uint64("conn", sessVar.ConnectionID), zap.Int64("schemaVersion", is.SchemaMetaVersion()))
	} else {
		is = sessVar.TxnCtx.InfoSchema.(InfoSchema)
	}
	return is
}

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Manual test (add detailed scripts or steps below)

It's not written as an unit test, because the test case depends on TiKV.

func (s *testInfoschemaTableSuite) TestWrongSnapshotSchema(c *C) {
	// Test case for https://github.com/pingcap/tidb/issues/18347
	// getAutoIncrementID does not use the snapshot infoschema and cause this bug.
	tk := testkit.NewTestKit(c, s.store)
	tk.MustExec("create database gzj_test_db")
	tk.MustExec("create table gzj_test_db.ad_account_record_log (id int auto_increment primary key)")
	rs := tk.MustQuery("select now()").Rows()
	tk.MustExec("drop database gzj_test_db")

	tk.MustExec("set @@tidb_snapshot = ?", rs[0][0])
	// Before the bug fix, this query get "'Table gzj_test_db.ad_account_record_log' doesn't exist"
	tk.MustQuery("select * from information_schema.tables;")
}

Release note

  • Fix a bug `getAutoIncrementID()` function does not consider the `tidb_snapshot` session variable, this bug may cause dumper tool fail with 'table not exist' error.

@ti-srebot
Copy link
Contributor Author

/run-all-tests

@tiancaiamao
Copy link
Contributor

The bug does not exist in 3.x, so no need to cherry pick here.

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 this pull request may close these issues.

2 participants