Skip to content

Commit

Permalink
session,parser: make MAX_EXECUTION_TIME sql hint and global variable …
Browse files Browse the repository at this point in the history
…work (pingcap#10999)
  • Loading branch information
tiancaiamao authored and ngaut committed Jul 1, 2019
1 parent 8d757ee commit db151cc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
15 changes: 13 additions & 2 deletions domain/global_vars_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type GlobalVariableCache struct {
lastModify time.Time
rows []chunk.Row
fields []*ast.ResultField

// Unit test may like to disable it.
disable bool
}

const globalVariableCacheExpiry time.Duration = 2 * time.Second
Expand All @@ -44,14 +47,22 @@ func (gvc *GlobalVariableCache) Update(rows []chunk.Row, fields []*ast.ResultFie
func (gvc *GlobalVariableCache) Get() (succ bool, rows []chunk.Row, fields []*ast.ResultField) {
gvc.RLock()
defer gvc.RUnlock()
if time.Now().Sub(gvc.lastModify) < globalVariableCacheExpiry {
succ, rows, fields = true, gvc.rows, gvc.fields
if time.Since(gvc.lastModify) < globalVariableCacheExpiry {
succ, rows, fields = !gvc.disable, gvc.rows, gvc.fields
return
}
succ = false
return
}

// Disable disables the global variabe cache, used in test only.
func (gvc *GlobalVariableCache) Disable() {
gvc.Lock()
defer gvc.Unlock()
gvc.disable = true
return
}

// GetGlobalVarsCache gets the global variable cache.
func (do *Domain) GetGlobalVarsCache() *GlobalVariableCache {
return &do.gvc
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20171020084629-8d44bfdf1030
github.com/pingcap/kvproto v0.0.0-20190429124202-32a5ba2af0f7
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596
github.com/pingcap/parser v0.0.0-20190620042621-a13211687e55
github.com/pingcap/parser v0.0.0-20190701060323-a2aa507d6352
github.com/pingcap/pd v2.1.12+incompatible
github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible
github.com/pingcap/tipb v0.0.0-20180910045846-371b48b15d93
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ github.com/pingcap/kvproto v0.0.0-20190429124202-32a5ba2af0f7 h1:+wEqJTc74Jvoxen
github.com/pingcap/kvproto v0.0.0-20190429124202-32a5ba2af0f7/go.mod h1:0gwbe1F2iBIjuQ9AH0DbQhL+Dpr5GofU8fgYyXk+ykk=
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 h1:t2OQTpPJnrPDGlvA+3FwJptMTt6MEPdzK1Wt99oaefQ=
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw=
github.com/pingcap/parser v0.0.0-20190620042621-a13211687e55 h1:JSr9saxYwDyIte70taWbKX83fCUww80HjrcyDnFokBg=
github.com/pingcap/parser v0.0.0-20190620042621-a13211687e55/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/parser v0.0.0-20190701060323-a2aa507d6352 h1:bqNncrTvLJyxLx8rHr5tDe4wYhfVFoegj+LrOoFwwuM=
github.com/pingcap/parser v0.0.0-20190701060323-a2aa507d6352/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/pd v2.1.12+incompatible h1:6N3LBxx2aSZqT+IWEG730EDNDttP7dXO8J6yvBh+HXw=
github.com/pingcap/pd v2.1.12+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E=
github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible h1:e9Gi/LP9181HT3gBfSOeSBA+5JfemuE4aEAhqNgoE4k=
Expand Down
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ var builtinGlobalVariable = []string{
variable.MaxAllowedPacket,
variable.TimeZone,
variable.BlockEncryptionMode,
variable.MaxExecutionTime,
/* TiDB specific global variables: */
variable.TiDBSkipUTF8Check,
variable.TiDBIndexJoinBatchSize,
Expand Down
7 changes: 7 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ func (s *testSessionSuite) TestGlobalVarAccessor(c *C) {
c.Assert(err, IsNil)
c.Assert(v, Equals, varValue2)

// For issue 10955, make sure the new session load `max_execution_time` into sessionVars.
s.dom.GetGlobalVarsCache().Disable()
tk1.MustExec("set @@global.max_execution_time = 100")
tk2 := testkit.NewTestKitWithInit(c, s.store)
c.Assert(tk2.Se.GetSessionVars().MaxExecutionTime, Equals, uint64(100))
tk1.MustExec("set @@global.max_execution_time = 0")

result := tk.MustQuery("show global variables where variable_name='sql_select_limit';")
result.Check(testkit.Rows("sql_select_limit 18446744073709551615"))
result = tk.MustQuery("show session variables where variable_name='sql_select_limit';")
Expand Down

0 comments on commit db151cc

Please sign in to comment.