Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into shenli/fix-server-t…
Browse files Browse the repository at this point in the history
…estcase
  • Loading branch information
shenli committed Dec 16, 2015
2 parents 6422a12 + 826287a commit 91852d6
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 25 deletions.
7 changes: 6 additions & 1 deletion parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *testParserSuite) TestSimple(c *C) {
"date", "datetime", "deallocate", "do", "end", "engine", "engines", "execute", "first", "full",
"local", "names", "offset", "password", "prepare", "quick", "rollback", "session", "signed",
"start", "global", "tables", "text", "time", "timestamp", "transaction", "truncate", "unknown",
"value", "warnings", "year", "now", "substring", "mode", "any", "some", "user", "identified",
"value", "warnings", "year", "now", "substr", "substring", "mode", "any", "some", "user", "identified",
"collation", "comment", "avg_row_length", "checksum", "compression", "connection", "key_block_size",
"max_rows", "min_rows", "national", "row", "quarter", "escape", "grants", "status", "fields", "triggers",
"delay_key_write", "isolation", "repeatable", "committed", "uncommitted", "only", "serializable", "level",
Expand Down Expand Up @@ -333,6 +333,11 @@ func (s *testParserSuite) TestBuiltin(c *C) {
{"SELECT RAND();", true},
{"SELECT RAND(1);", true},

{"SELECT SUBSTR('Quadratically',5);", true},
{"SELECT SUBSTR('Quadratically',5, 3);", true},
{"SELECT SUBSTR('Quadratically' FROM 5);", true},
{"SELECT SUBSTR('Quadratically' FROM 5 FOR 3);", true},

{"SELECT SUBSTRING('Quadratically',5);", true},
{"SELECT SUBSTRING('Quadratically',5, 3);", true},
{"SELECT SUBSTRING('Quadratically' FROM 5);", true},
Expand Down
3 changes: 3 additions & 0 deletions parser/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ some {s}{o}{m}{e}
start {s}{t}{a}{r}{t}
status {s}{t}{a}{t}{u}{s}
subdate {s}{u}{b}{d}{a}{t}{e}
substr {s}{u}{b}{s}{t}{r}
substring {s}{u}{b}{s}{t}{r}{i}{n}{g}
substring_index {s}{u}{b}{s}{t}{r}{i}{n}{g}_{i}{n}{d}{e}{x}
sum {s}{u}{m}
Expand Down Expand Up @@ -904,6 +905,8 @@ year_month {y}{e}{a}{r}_{m}{o}{n}{t}{h}
{share} return share
{show} return show
{subdate} return subDate
{substr} lval.item = string(l.val)
return substring
{substring} lval.item = string(l.val)
return substring
{substring_index} lval.item = string(l.val)
Expand Down
6 changes: 3 additions & 3 deletions plan/plans/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,14 @@ func (r *indexPlan) Next(ctx context.Context) (*plan.Row, error) {
}

func (r *indexPlan) isPointLookup(span *indexSpan) bool {
equalOp := span.lowVal == span.highVal && !span.lowExclude && !span.highExclude
if !equalOp || !r.unique || span.lowVal == nil {
if span.lowExclude || span.highExclude || span.lowVal == nil || !r.unique {
return false
}
n, err := types.Compare(span.seekVal, span.lowVal)
n, err := types.Compare(span.seekVal, span.highVal)
if err != nil {
return false
}
// 'seekVal==highVal' means that 'seekVal==lowVal && lowVal==highVal'
return n == 0
}

Expand Down
12 changes: 0 additions & 12 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,6 @@ func (s *session) getExecRet(ctx context.Context, sql string) (string, error) {

// GetGlobalSysVar implements GlobalVarAccessor.GetGlobalSysVar interface.
func (s *session) GetGlobalSysVar(ctx context.Context, name string) (string, error) {
sessionVars := variable.GetSessionVars(ctx)
// We should check cache first.
// See: https://dev.mysql.com/doc/refman/5.7/en/using-system-variables.html
// The global variable change does not affect the session variable for any client that is currently connected.
// We do not want to load all variable values at session start time for performance issue. So we do lazy init here.
v, ok := sessionVars.Systems[name]
if ok {
return v, nil
}
sql := fmt.Sprintf(`SELECT VARIABLE_VALUE FROM %s.%s WHERE VARIABLE_NAME="%s";`,
mysql.SystemDB, mysql.GlobalVariablesTable, name)
sysVar, err := s.getExecRet(ctx, sql)
Expand All @@ -336,7 +327,6 @@ func (s *session) GetGlobalSysVar(ctx context.Context, name string) (string, err
}
return "", errors.Trace(err)
}
sessionVars.Systems[name] = sysVar
return sysVar, nil
}

Expand All @@ -345,8 +335,6 @@ func (s *session) SetGlobalSysVar(ctx context.Context, name string, value string
sql := fmt.Sprintf(`UPDATE %s.%s SET VARIABLE_VALUE="%s" WHERE VARIABLE_NAME="%s";`,
mysql.SystemDB, mysql.GlobalVariablesTable, value, strings.ToLower(name))
_, err := s.ExecRestrictedSQL(ctx, sql)
sessionVars := variable.GetSessionVars(ctx)
sessionVars.Systems[name] = value
return errors.Trace(err)
}

Expand Down
40 changes: 32 additions & 8 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,21 +1369,45 @@ func (s *testSessionSuite) TestMultiColumnIndex(c *C) {
}

func (s *testSessionSuite) TestGlobalVarAccessor(c *C) {

varName := "max_allowed_packet"
varValue := "4194304" // This is the default value for max_allowed_packet
varValue1 := "4194305"
varValue2 := "4194306"

store := newStore(c, s.dbName)
se := newSession(c, store, s.dbName).(*session)

v, err := se.GetGlobalSysVar(se, "max_allowed_packet")
// Get globalSysVar twice and get the same value
v, err := se.GetGlobalSysVar(se, varName)
c.Assert(err, IsNil)
c.Assert(v, Equals, varValue)
v, err = se.GetGlobalSysVar(se, varName)
c.Assert(err, IsNil)
c.Assert(v, Equals, "4194304")
v, err = se.GetGlobalSysVar(se, "max_allowed_packet")
c.Assert(v, Equals, varValue)
// Set global var to another value
err = se.SetGlobalSysVar(se, varName, varValue1)
c.Assert(err, IsNil)
c.Assert(v, Equals, "4194304")
v, err = se.GetGlobalSysVar(se, varName)
c.Assert(err, IsNil)
c.Assert(v, Equals, varValue1)
c.Assert(se.FinishTxn(false), IsNil)

err = se.SetGlobalSysVar(se, "max_allowed_packet", "4194305")
// Change global variable value in another session
se1 := newSession(c, store, s.dbName).(*session)
v, err = se1.GetGlobalSysVar(se1, varName)
c.Assert(err, IsNil)
c.Assert(v, Equals, varValue1)
err = se1.SetGlobalSysVar(se1, varName, varValue2)
c.Assert(err, IsNil)
v, err = se.GetGlobalSysVar(se, "max_allowed_packet")
v, err = se1.GetGlobalSysVar(se1, varName)
c.Assert(err, IsNil)
c.Assert(v, Equals, varValue2)
c.Assert(se1.FinishTxn(false), IsNil)

// Make sure the change is visible to any client that accesses that global variable.
v, err = se.GetGlobalSysVar(se, varName)
c.Assert(err, IsNil)
c.Assert(v, Equals, "4194305")
c.Assert(v, Equals, varValue2)
}

func checkPlan(c *C, se Session, sql, explain string) {
Expand Down
2 changes: 1 addition & 1 deletion store/hbase/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (d Driver) Open(dsn string) (kv.Storage, error) {
// Create new hbase table for store.
t := hbase.NewTableDesciptor(hbase.NewTableNameWithDefaultNS(tableName))
cf := hbase.NewColumnFamilyDescriptor(hbaseColFamily)
cf.AddStrAddr("THEMIS_ENABLE", "true")
cf.AddAttr("THEMIS_ENABLE", "true")
t.AddColumnDesc(cf)
//TODO: specify split?
if err := c.CreateTable(t, nil); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions util/types/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ func Convert(val interface{}, target *FieldType) (v interface{}, err error) {
return t.RoundFrac(fsp)
case string:
return mysql.ParseDuration(x, fsp)
case []byte:
return mysql.ParseDuration(string(x), fsp)
default:
return invConv(val, tp)
}
Expand All @@ -359,6 +361,8 @@ func Convert(val interface{}, target *FieldType) (v interface{}, err error) {
return t.RoundFrac(fsp)
case string:
return mysql.ParseTime(x, tp, fsp)
case []byte:
return mysql.ParseTime(string(x), tp, fsp)
case int64:
return mysql.ParseTimeFromNum(x, tp, fsp)
default:
Expand Down Expand Up @@ -407,6 +411,8 @@ func Convert(val interface{}, target *FieldType) (v interface{}, err error) {
switch x := val.(type) {
case string:
intVal, err = StrToInt(x)
case []byte:
intVal, err = StrToInt(string(x))
case mysql.Time:
return int64(x.Year()), nil
case mysql.Duration:
Expand Down

0 comments on commit 91852d6

Please sign in to comment.