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

Merged
merged 2 commits into from
Jul 20, 2020

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Jul 18, 2020

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.

@tiancaiamao tiancaiamao requested a review from a team as a code owner July 18, 2020 16:12
@tiancaiamao tiancaiamao requested review from XuHuaiyu and removed request for a team July 18, 2020 16:12
@tiancaiamao tiancaiamao added type/bugfix This PR fixes a bug. sig/execution SIG execution labels Jul 18, 2020
@tiancaiamao
Copy link
Contributor Author

PTAL @bb7133 @lonng

@codecov
Copy link

codecov bot commented Jul 18, 2020

Codecov Report

Merging #18676 into master will decrease coverage by 0.0208%.
The diff coverage is 100.0000%.

@@               Coverage Diff                @@
##             master     #18676        +/-   ##
================================================
- Coverage   79.2845%   79.2637%   -0.0208%     
================================================
  Files           542        542                
  Lines        146707     146039       -668     
================================================
- Hits         116316     115756       -560     
+ Misses        21051      20964        -87     
+ Partials       9340       9319        -21     

Copy link
Contributor

@lonng lonng left a comment

Choose a reason for hiding this comment

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

Please add some tests for it, thanks.

@zyguan
Copy link
Contributor

zyguan commented Jul 20, 2020

@lonng @tiancaiamao An integration test case has been added. https://github.com/pingcap/automated-tests/pull/423

@bb7133
Copy link
Member

bb7133 commented Jul 20, 2020

LGTM

@bb7133 bb7133 added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 20, 2020
@pingcap pingcap deleted a comment from ti-srebot Jul 20, 2020
@lonng
Copy link
Contributor

lonng commented Jul 20, 2020

/approve

@ti-srebot
Copy link
Contributor

@lonng,Thanks for your review. However, LGTM is restricted to Reviewers or higher roles.See the corresponding SIG page for more information. Related SIGs: execution(slack).

@bb7133
Copy link
Member

bb7133 commented Jul 20, 2020

/merge

@ti-srebot
Copy link
Contributor

@bb7133 Oops! auto merge is restricted to Committers of the SIG.See the corresponding SIG page for more information. Related SIGs: execution(slack).

@ti-srebot
Copy link
Contributor

@bb7133,Thanks for your review. However, LGTM is restricted to Reviewers or higher roles.See the corresponding SIG page for more information. Related SIGs: execution(slack).

@bb7133
Copy link
Member

bb7133 commented Jul 20, 2020

/run-all-tests

1 similar comment
@bb7133
Copy link
Member

bb7133 commented Jul 20, 2020

/run-all-tests

@bb7133 bb7133 added status/LGT2 Indicates that a PR has LGTM 2. needs-cherry-pick-3.0 and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 20, 2020
Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added status/LGT1 Indicates that a PR has LGTM 1. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Jul 20, 2020
@bb7133 bb7133 merged commit 8e4575e into pingcap:master Jul 20, 2020
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Jul 20, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-3.0 in PR #18690

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Jul 20, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-3.1 in PR #18691

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Jul 20, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #18692

@tiancaiamao tiancaiamao deleted the snapshot-infoschema branch July 20, 2020 14:47
ti-srebot added a commit that referenced this pull request Jul 28, 2020
…g @@tidb_snapshot (#18676) (#18692)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@crazycs520
Copy link
Contributor

/run-cherry-picker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/LGT1 Indicates that a PR has LGTM 1. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants