-
Notifications
You must be signed in to change notification settings - Fork 6.2k
planner, executor: supports select statement with AS OF #24613
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
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
f9b49db
planner, exector: supports select statement with AS OF
nolouch 2ff63cf
update proto
nolouch 6afe3b9
fix
nolouch 25f55ec
format
nolouch 5fad63c
add more tests
nolouch c0a561a
Merge remote-tracking branch 'origin/master' into stale-select
nolouch b658219
clean up
nolouch a06b1a3
Merge remote-tracking branch 'origin/master' into stale-select
nolouch 0f99648
update parser
nolouch c522744
address comments
nolouch 09e0a2e
Merge remote-tracking branch 'origin/master' into stale-select
nolouch 8446742
address comments
nolouch 03e8455
*: use preprocessor to get timestamp
xhebox 2c7113e
*: remove asofResolver, rename as WithPreprocessorReturn
xhebox 758fe74
use millisecond precision
nolouch d3c9647
*: fix tests
xhebox 11f2c16
*: fix remaining tests
xhebox aee7755
Merge branch 'master' into stale-select
nolouch 5d745ef
Merge remote-tracking branch 'origin/master' into stale-select
nolouch 3fa95e5
extract calculateTsExpr
nolouch 8ce9e5f
fix test
nolouch f0aefdc
update mod
nolouch 7e9a859
Merge branch 'master' into stale-select
xhebox e929ee6
Merge remote-tracking branch 'origin' into stale-select
nolouch 47c20b4
fix conflict
nolouch 6dbf8ef
try to fix test
nolouch ab2825b
address comment
nolouch 0fc6fb5
Merge remote-tracking branch 'origin/master' into stale-select
nolouch 4eeb62c
fix test
nolouch 58c3c0d
*: try to fix
xhebox 865db75
Merge remote-tracking branch 'pingcap/master' into stale_1
xhebox 880541b
try fix
nolouch c0b5145
add comment
nolouch 0713d8f
Merge branch 'master' into stale-select
nolouch c88bd2f
clean
nolouch 82674a7
Merge remote-tracking branch 'nolouch/stale-select' into stale-select
nolouch 36477da
try stable
nolouch 8fb38a1
address comment
nolouch e42f736
Merge branch 'master' into stale-select
nolouch 55966f9
Merge branch 'master' into stale-select
nolouch 0f56721
address comment
nolouch c7a8a96
Merge remote-tracking branch 'nolouch/stale-select' into stale-select
nolouch df4850f
Merge branch 'master' into stale-select
ti-chi-bot 6837ab5
Merge branch 'master' into stale-select
ti-chi-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import ( | |
| "time" | ||
|
|
||
| . "github.com/pingcap/check" | ||
| "github.com/pingcap/errors" | ||
| "github.com/pingcap/failpoint" | ||
| "github.com/pingcap/tidb/ddl/placement" | ||
| "github.com/pingcap/tidb/store/tikv/oracle" | ||
|
|
@@ -93,6 +94,118 @@ func (s *testStaleTxnSerialSuite) TestExactStalenessTransaction(c *C) { | |
| failpoint.Disable("github.com/pingcap/tidb/config/injectTxnScope") | ||
| } | ||
|
|
||
| func (s *testStaleTxnSerialSuite) TestSelectAsOf(c *C) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should test this case:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, let us handle it in another PR. |
||
| tk := testkit.NewTestKit(c, s.store) | ||
| tk.MustExec("use test") | ||
| tk.MustExec("drop table if exists t") | ||
| tk.MustExec(`drop table if exists b`) | ||
| tk.MustExec("create table t (id int primary key);") | ||
| tk.MustExec("create table b (pid int primary key);") | ||
| defer func() { | ||
| tk.MustExec(`drop table if exists b`) | ||
| tk.MustExec(`drop table if exists t`) | ||
| }() | ||
| time.Sleep(2 * time.Second) | ||
| now := time.Now() | ||
| time.Sleep(2 * time.Second) | ||
|
|
||
| testcases := []struct { | ||
| name string | ||
| sql string | ||
| expectPhysicalTS int64 | ||
| preSec int64 | ||
| // IsStaleness is auto cleanup in select stmt. | ||
| errorStr string | ||
| }{ | ||
| { | ||
| name: "TimestampExactRead1", | ||
| sql: fmt.Sprintf("select * from t as of timestamp '%s';", now.Format("2006-1-2 15:04:05")), | ||
| expectPhysicalTS: now.Unix(), | ||
| }, | ||
| { | ||
| name: "NomalRead", | ||
| sql: `select * from b;`, | ||
| preSec: 0, | ||
| }, | ||
| { | ||
| name: "TimestampExactRead2", | ||
| sql: fmt.Sprintf("select * from t as of timestamp TIMESTAMP('%s');", now.Format("2006-1-2 15:04:05")), | ||
| expectPhysicalTS: now.Unix(), | ||
| }, | ||
| { | ||
| name: "TimestampExactRead3", | ||
| sql: `select * from t as of timestamp NOW() - INTERVAL 2 SECOND;`, | ||
| preSec: 2, | ||
| }, | ||
| { | ||
| name: "TimestampExactRead4", | ||
| sql: `select * from t as of timestamp TIMESTAMP(NOW() - INTERVAL 2 SECOND);`, | ||
| preSec: 2, | ||
| }, | ||
| { | ||
| name: "TimestampExactRead5", | ||
| sql: `select * from t as of timestamp TIMESTAMP(NOW() - INTERVAL 1 SECOND), b as of timestamp TIMESTAMP(NOW() - INTERVAL 1 SECOND);`, | ||
| preSec: 1, | ||
| }, | ||
| { | ||
| name: "TimestampExactRead6", | ||
| sql: `select * from t as of timestamp TIMESTAMP(NOW() - INTERVAL 1 SECOND), b as of timestamp TIMESTAMP('2020-09-06 00:00:00');`, | ||
| errorStr: ".*can not set different time in the as of.*", | ||
| }, | ||
| { | ||
| name: "TimestampExactRead7", | ||
| sql: `select * from t as of timestamp TIMESTAMP(NOW() - INTERVAL 1 SECOND), b;`, | ||
| errorStr: ".*can not set different time in the as of.*", | ||
| }, | ||
| { | ||
| name: "TimestampExactRead8", | ||
| sql: `select * from t, b as of timestamp TIMESTAMP(NOW() - INTERVAL 1 SECOND);`, | ||
| errorStr: ".*can not set different time in the as of.*", | ||
| }, | ||
| { | ||
| name: "NomalRead", | ||
| sql: `select * from t, b;`, | ||
| preSec: 0, | ||
| }, | ||
| { | ||
| name: "TimestampExactRead9", | ||
| sql: `select * from (select * from t as of timestamp TIMESTAMP(NOW() - INTERVAL 1 SECOND), b as of timestamp TIMESTAMP(NOW() - INTERVAL 1 SECOND)) as c, b;`, | ||
| errorStr: ".*can not set different time in the as of.*", | ||
| }, | ||
| { | ||
| name: "TimestampExactRead10", | ||
| sql: `select * from (select * from t as of timestamp TIMESTAMP(NOW() - INTERVAL 2 SECOND), b as of timestamp TIMESTAMP(NOW() - INTERVAL 2 SECOND)) as c;`, | ||
| preSec: 2, | ||
| }, | ||
| // Cannot be supported the SubSelect | ||
| { | ||
| name: "TimestampExactRead11", | ||
| sql: `select * from (select * from t as of timestamp TIMESTAMP(NOW() - INTERVAL 20 SECOND), b as of timestamp TIMESTAMP(NOW() - INTERVAL 20 SECOND)) as c as of timestamp Now();`, | ||
| errorStr: ".*You have an error in your SQL syntax.*", | ||
| }, | ||
| } | ||
|
|
||
| for _, testcase := range testcases { | ||
| c.Log(testcase.name) | ||
| if testcase.expectPhysicalTS > 0 { | ||
| c.Assert(failpoint.Enable("github.com/pingcap/tidb/executor/assertStaleTSO", fmt.Sprintf(`return(%d)`, testcase.expectPhysicalTS)), IsNil) | ||
| } else if testcase.preSec > 0 { | ||
| c.Assert(failpoint.Enable("github.com/pingcap/tidb/executor/assertStaleTSOWithTolerance", fmt.Sprintf(`return(%d)`, time.Now().Unix()-testcase.preSec)), IsNil) | ||
| } | ||
| _, err := tk.Exec(testcase.sql) | ||
| if len(testcase.errorStr) != 0 { | ||
| c.Assert(err, ErrorMatches, testcase.errorStr) | ||
| continue | ||
| } | ||
| c.Assert(err, IsNil, Commentf("sql:%s, error stack %v", testcase.sql, errors.ErrorStack(err))) | ||
| if testcase.expectPhysicalTS > 0 { | ||
| c.Assert(failpoint.Disable("github.com/pingcap/tidb/executor/assertStaleTSO"), IsNil) | ||
| } else if testcase.preSec > 0 { | ||
| c.Assert(failpoint.Disable("github.com/pingcap/tidb/executor/assertStaleTSOWithTolerance"), IsNil) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (s *testStaleTxnSerialSuite) TestStaleReadKVRequest(c *C) { | ||
| tk := testkit.NewTestKit(c, s.store) | ||
| tk.MustExec("use test") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.