-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: support read and write operations for the global temporary table #24196
Changes from all commits
0e52f9e
45c9c9f
b47b46b
27f5230
a0a2cf9
35a9374
044afad
871533e
f38d74f
a4b305e
9924957
e7eedb4
98afaed
351d871
bc31510
0e8cd60
26a19a7
9a9b738
fb500ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -967,7 +967,7 @@ func (s *seqTestSuite) TestBatchInsertDelete(c *C) { | |
atomic.StoreUint64(&kv.TxnTotalSizeLimit, originLimit) | ||
}() | ||
// Set the limitation to a small value, make it easier to reach the limitation. | ||
atomic.StoreUint64(&kv.TxnTotalSizeLimit, 5000) | ||
atomic.StoreUint64(&kv.TxnTotalSizeLimit, 5500) | ||
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. This change is because we update the parser, and marshal table info use more bytes (add a new temporary field, now it's 5038 byte). |
||
|
||
tk := testkit.NewTestKit(c, s.store) | ||
tk.MustExec("use test") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ import ( | |
tikvstore "github.com/pingcap/tidb/store/tikv/kv" | ||
"github.com/pingcap/tidb/store/tikv/oracle" | ||
tikvutil "github.com/pingcap/tidb/store/tikv/util" | ||
"github.com/pingcap/tidb/tablecodec" | ||
"github.com/pingcap/tidb/telemetry" | ||
"github.com/pingcap/tidb/types" | ||
"github.com/pingcap/tidb/util" | ||
|
@@ -509,6 +510,27 @@ func (s *session) doCommit(ctx context.Context) error { | |
s.GetSessionVars().TxnCtx.IsExplicit && s.GetSessionVars().GuaranteeLinearizability) | ||
} | ||
|
||
// Filter out the temporary table key-values. | ||
coocood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if tables := s.sessionVars.TxnCtx.GlobalTemporaryTables; tables != nil { | ||
memBuffer := s.txn.GetMemBuffer() | ||
for tid := range tables { | ||
seekKey := tablecodec.EncodeTablePrefix(tid) | ||
endKey := tablecodec.EncodeTablePrefix(tid + 1) | ||
iter, err := memBuffer.Iter(seekKey, endKey) | ||
if err != nil { | ||
return err | ||
} | ||
for iter.Valid() && iter.Key().HasPrefix(seekKey) { | ||
if err = memBuffer.Delete(iter.Key()); err != nil { | ||
return errors.Trace(err) | ||
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 have a question, why err here be traced and return but the other errs directly return? 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. When the error is not already wrapped with |
||
} | ||
if err = iter.Next(); err != nil { | ||
return errors.Trace(err) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return s.txn.Commit(tikvutil.SetSessionID(ctx, s.GetSessionVars().ConnectionID)) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4243,3 +4243,24 @@ func (s *testSessionSerialSuite) TestParseWithParams(c *C) { | |
c.Assert(err, IsNil) | ||
c.Assert(sb.String(), Equals, "SELECT 3") | ||
} | ||
|
||
func (s *testSessionSuite3) TestGlobalTemporaryTable(c *C) { | ||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
tk.MustExec("create global temporary table g_tmp (a int primary key, b int, c int, index i_b(b)) on commit delete rows") | ||
tk.MustExec("begin") | ||
tk.MustExec("insert into g_tmp values (3, 3, 3)") | ||
tk.MustExec("insert into g_tmp values (4, 7, 9)") | ||
|
||
// Cover table scan. | ||
tk.MustQuery("select * from g_tmp").Check(testkit.Rows("3 3 3", "4 7 9")) | ||
// Cover index reader. | ||
tk.MustQuery("select b from g_tmp where b > 3").Check(testkit.Rows("7")) | ||
// Cover index lookup. | ||
tk.MustQuery("select c from g_tmp where b = 3").Check(testkit.Rows("3")) | ||
// Cover point get. | ||
tk.MustQuery("select * from g_tmp where a = 3").Check(testkit.Rows("3 3 3")) | ||
tk.MustExec("commit") | ||
|
||
// The global temporary table data is discard after the transaction commit. | ||
tk.MustQuery("select * from g_tmp").Check(testkit.Rows()) | ||
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. Need test case for not supporting 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. Those will be banned in the following PRs. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is because we use the latest parser and it change the String() method
https://github.com/pingcap/parser/pull/1210/files#diff-a5ce247e55d5a20707517e34bef620f2eb369b4f9b8fa44fdfb2c18a702418e8R72