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

planner: check index valid while forUpdateRead #21596

Merged
merged 15 commits into from
Dec 22, 2020

Conversation

you06
Copy link
Contributor

@you06 you06 commented Dec 9, 2020

Signed-off-by: you06 you1474600@gmail.com

What problem does this PR solve?

Issue Number: workaround for #21498

Problem Summary:

ForUpdateRead will read data using schema version of startTS, this may lead to incorrectness, the cases are listed in #21498

What is changed and how it works?

What's Changed:

For RC and forUpdateRead in RR, check if index's state is still StatePublic.

How it Works:

This check confirms index between snapshotTS and forUpdateTS is not changed, otherwise, the index should not be used.

Check List

Tests

  • Unit test

Side effects

  • Performance regression
    • Consumes more CPU, there is a little regression testing with tpc-c

Release note

  • Fix a bug that schema change will lead to incorrectness when forUpdateRead

@MyonKeminta
Copy link
Contributor

🤔 Is it ok to fix it directly to release-4.0 without changing master?

@you06
Copy link
Contributor Author

you06 commented Dec 10, 2020

thinking Is it ok to fix it directly to release-4.0 without changing master?

IMO, there should be a better solution in master.

@you06
Copy link
Contributor Author

you06 commented Dec 12, 2020

tpcc 1000 warehouses, 128 threads
before this PR: tpmC: 16906.1, efficiency: 131.5%
this PR: tpmC: 16607.8, efficiency: 129.1%

It's about 1.8% of regression.

@lysu lysu self-requested a review December 14, 2020 03:25
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
planner/core/planbuilder.go Outdated Show resolved Hide resolved
planner/core/planbuilder.go Outdated Show resolved Hide resolved
planner/core/point_get_plan.go Outdated Show resolved Hide resolved
planner/core/point_get_plan.go Outdated Show resolved Hide resolved
@@ -1903,3 +1903,106 @@ func (s *testPessimisticSuite) TestResolveStalePessimisticPrimaryLock(c *C) {

c.Assert(tk2.ExecToErr("admin check table t1"), IsNil)
}

func (s *testPessimisticSuite) TestIssue21498(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to add some unique key uk(varchar_column) case using the IndexLookUp executor fetching data from unique index and look up data in main table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added snapshot read and for update read cases for IndexLookUp.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about the insert into table select from anothertable, we have another issue #21506, what is the expecting behaviour for this case?

@cfzjywxk cfzjywxk added type/bugfix This PR fixes a bug. sig/transaction SIG:Transaction labels Dec 16, 2020
@cfzjywxk cfzjywxk added this to the v4.0.10 milestone Dec 16, 2020
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
@you06
Copy link
Contributor Author

you06 commented Dec 16, 2020

I wonder there will be a better solution for this issue in master and future release versions, do we need to cherry pick this hotfix to master?

@cfzjywxk
Copy link
Contributor

I wonder there will be a better solution for this issue in master and future release versions, do we need to cherry pick this hotfix to master?

Yes, on master maybe we need a better mechanism to solve the concurrent ddl and dml problem so we won't meet this problem.

planner/core/planbuilder.go Outdated Show resolved Hide resolved
planner/core/planbuilder.go Show resolved Hide resolved
@cfzjywxk cfzjywxk added the sig/planner SIG: Planner label Dec 17, 2020
Signed-off-by: you06 <you1474600@gmail.com>
planner/core/logical_plan_builder.go Outdated Show resolved Hide resolved
planner/core/point_get_plan.go Outdated Show resolved Hide resolved
@@ -1903,3 +1903,106 @@ func (s *testPessimisticSuite) TestResolveStalePessimisticPrimaryLock(c *C) {

c.Assert(tk2.ExecToErr("admin check table t1"), IsNil)
}

func (s *testPessimisticSuite) TestIssue21498(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about the insert into table select from anothertable, we have another issue #21506, what is the expecting behaviour for this case?

// amend transaction does not support partition table
tk.MustExec("insert into t(id, v, v2) select 6, v + 20, v2 + 200 from t where id = 4") // insert ... select with index unchanged
}
err = tk.ExecToErr("insert into t(id, v, v2) select 7, v + 30, v2 + 300 from t use index (iv) where id = 4") // insert ... select with index changed
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe need add more test: prepare plan cache (maybe have question) and plan binding (maybe have no question)

@lysu
Copy link
Contributor

lysu commented Dec 21, 2020

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 21, 2020
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
@cfzjywxk
Copy link
Contributor

LGTM

@ti-srebot ti-srebot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 21, 2020
@cfzjywxk
Copy link
Contributor

/merge

@ti-srebot
Copy link
Contributor

Sorry @cfzjywxk, this branch cannot be merged without an approval of release maintainers.

@cfzjywxk
Copy link
Contributor

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 22, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@you06 merge failed.

@you06
Copy link
Contributor Author

you06 commented Dec 22, 2020

/run-unit-test

@cfzjywxk
Copy link
Contributor

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit a6f2643 into pingcap:release-4.0 Dec 22, 2020
@you06 you06 deleted the check-index-valid branch December 22, 2020 06:13
you06 added a commit to you06/tidb that referenced this pull request Jan 7, 2021
Signed-off-by: you06 <you1474600@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner sig/transaction SIG:Transaction status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants