Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pingcap/tidb into winkyao…
Browse files Browse the repository at this point in the history
…/cast_compability
  • Loading branch information
winkyao committed Jul 31, 2017
2 parents 8d98e4d + 58dca67 commit 68f0a1d
Show file tree
Hide file tree
Showing 61 changed files with 646 additions and 797 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ git remote set-url --push upstream no_push
# origin git@github.com:$(user)/tidb.git (fetch)
# origin git@github.com:$(user)/tidb.git (push)
# upstream https://github.com/pingcap/tidb (fetch)
# upstream https://github.com/pingcap/tidb (push)
# upstream no_push (push)
git remote -v
```

Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ GOVERALLS := goveralls
ARCH := "`uname -s`"
LINUX := "Linux"
MAC := "Darwin"
PACKAGES := $$(go list ./...| grep -vE 'vendor')
FILES := $$(find . -name '*.go' | grep -vE 'vendor')
PACKAGES := $$(go list ./...| grep -vE "vendor")
FILES := $$(find . -name "*.go" | grep -vE "vendor")
TOPDIRS := $$(ls -d */ | grep -vE "vendor")

LDFLAGS += -X "github.com/pingcap/tidb/util/printer.TiDBBuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "github.com/pingcap/tidb/util/printer.TiDBGitHash=$(shell git rev-parse HEAD)"
Expand Down Expand Up @@ -74,9 +75,8 @@ check:
go get github.com/golang/lint/golint

@echo "vet"
@ go tool vet $(FILES) 2>&1 | awk '{print} END{if(NR>0) {exit 1}}'
@echo "vet --shadow"
@ go tool vet --shadow $(FILES) 2>&1 | awk '{print} END{if(NR>0) {exit 1}}'
@ go tool vet -all -shadow $(TOPDIRS) 2>&1 | awk '{print} END{if(NR>0) {exit 1}}'
@ go tool vet -all -shadow *.go 2>&1 | awk '{print} END{if(NR>0) {exit 1}}'
@echo "golint"
@ golint ./... 2>&1 | grep -vE 'context\.Context|LastInsertId|NewLexer|\.pb\.go' | awk '{print} END{if(NR>0) {exit 1}}'
@echo "gofmt (simplify)"
Expand Down
7 changes: 4 additions & 3 deletions bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,14 @@ func upgradeToVer12(s Session) {
user := row.Data[0].GetString()
host := row.Data[1].GetString()
pass := row.Data[2].GetString()
newpass, err := oldPasswordUpgrade(pass)
var newPass string
newPass, err = oldPasswordUpgrade(pass)
if err != nil {
log.Fatal(err)
return
}
sql := fmt.Sprintf(`UPDATE mysql.user set password = "%s" where user="%s" and host="%s"`, newpass, user, host)
sqls = append(sqls, sql)
updateSQL := fmt.Sprintf(`UPDATE mysql.user set password = "%s" where user="%s" and host="%s"`, newPass, user, host)
sqls = append(sqls, updateSQL)
row, err = r.Next()
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/benchfilesort/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ func main() {
flag.Parse()

if len(os.Args) == 1 {
fmt.Println("Usage:\n")
fmt.Println("\tbenchfilesort command [arguments]\n")
fmt.Println("The commands are:\n")
fmt.Printf("Usage:\n\n")
fmt.Printf("\tbenchfilesort command [arguments]\n\n")
fmt.Printf("The commands are:\n\n")
fmt.Println("\tgen\t", "generate rows")
fmt.Println("\trun\t", "run tests")
fmt.Println("")
Expand Down
5 changes: 4 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ var once sync.Once
// Other parts of the system can read the global configuration use this function.
func GetGlobalConfig() *Config {
once.Do(func() {
cfg = &Config{}
cfg = &Config{
SlowThreshold: 300,
QueryLogMaxlen: 2048,
}
})
return cfg
}
6 changes: 4 additions & 2 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ func (d *ddl) onAddColumn(t *meta.Meta, job *model.Job) (ver int64, _ error) {
case model.StateWriteReorganization:
// reorganization -> public
// Get the current version for reorganization if we don't have it.
reorgInfo, err := d.getReorgInfo(t, job)
var reorgInfo *reorgInfo
reorgInfo, err = d.getReorgInfo(t, job)
if err != nil || reorgInfo.first {
// If we run reorg firstly, we should update the job snapshot version
// and then run the reorg next time.
Expand Down Expand Up @@ -233,7 +234,8 @@ func (d *ddl) onDropColumn(t *meta.Meta, job *model.Job) (ver int64, _ error) {
ver, err = updateTableInfo(t, job, tblInfo, originalState)
case model.StateDeleteReorganization:
// reorganization -> absent
reorgInfo, err := d.getReorgInfo(t, job)
var reorgInfo *reorgInfo
reorgInfo, err = d.getReorgInfo(t, job)
if err != nil || reorgInfo.first {
// If we run reorg firstly, we should update the job snapshot version
// and then run the reorg next time.
Expand Down
8 changes: 4 additions & 4 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ func (d *ddl) AddColumn(ctx context.Context, ti ast.Ident, spec *ast.AlterTableS
referableColNames[col.Name.L] = struct{}{}
}
_, dependColNames := findDependedColumnNames(spec.NewColumn)
if err := columnNamesCover(referableColNames, dependColNames); err != nil {
if err = columnNamesCover(referableColNames, dependColNames); err != nil {
return errors.Trace(err)
}
}
Expand Down Expand Up @@ -1158,7 +1158,7 @@ func (d *ddl) getModifiableColumnJob(ctx context.Context, ident ast.Ident, origi
if err != nil {
return nil, errors.Trace(err)
}
if err := setDefaultAndComment(ctx, newCol, spec.NewColumn.Options); err != nil {
if err = setDefaultAndComment(ctx, newCol, spec.NewColumn.Options); err != nil {
return nil, errors.Trace(err)
}

Expand Down Expand Up @@ -1261,12 +1261,12 @@ func (d *ddl) AlterColumn(ctx context.Context, ident ast.Ident, spec *ast.AlterT
}

// Clean the NoDefaultValueFlag value.
col.Flag &= (^uint(mysql.NoDefaultValueFlag))
col.Flag &= ^uint(mysql.NoDefaultValueFlag)
if len(spec.NewColumn.Options) == 0 {
col.DefaultValue = nil
setNoDefaultValueFlag(col, false)
} else {
err := setDefaultValue(ctx, col, spec.NewColumn.Options[0])
err = setDefaultValue(ctx, col, spec.NewColumn.Options[0])
if err != nil {
return errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ LOOP:
matchRows(c, rows, [][]interface{}{{count - int64(step)}})

for i := num; i < num+step; i++ {
rows := s.mustQuery(c, "select c4 from t2 where c4 = ?", i)
rows = s.mustQuery(c, "select c4 from t2 where c4 = ?", i)
matchRows(c, rows, [][]interface{}{{i}})
}

Expand Down
6 changes: 4 additions & 2 deletions ddl/foreign_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func (s *testForeighKeySuite) TestForeignKey(c *C) {
}
mu.Lock()
defer mu.Unlock()
t, err := testGetTableWithError(d, s.dbInfo.ID, tblInfo.ID)
var t table.Table
t, err = testGetTableWithError(d, s.dbInfo.ID, tblInfo.ID)
if err != nil {
hookErr = errors.Trace(err)
return
Expand Down Expand Up @@ -178,7 +179,8 @@ func (s *testForeighKeySuite) TestForeignKey(c *C) {
}
mu.Lock()
defer mu.Unlock()
t, err := testGetTableWithError(d, s.dbInfo.ID, tblInfo.ID)
var t table.Table
t, err = testGetTableWithError(d, s.dbInfo.ID, tblInfo.ID)
if err != nil {
hookErr = errors.Trace(err)
return
Expand Down
3 changes: 2 additions & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ func (d *ddl) onCreateIndex(t *meta.Meta, job *model.Job) (ver int64, err error)
ver, err = updateTableInfo(t, job, tblInfo, originalState)
case model.StateWriteReorganization:
// reorganization -> public
reorgInfo, err := d.getReorgInfo(t, job)
var reorgInfo *reorgInfo
reorgInfo, err = d.getReorgInfo(t, job)
if err != nil || reorgInfo.first {
// If we run reorg firstly, we should update the job snapshot version
// and then run the reorg next time.
Expand Down
4 changes: 2 additions & 2 deletions ddl/owner_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ func (m *ownerManager) campaignLoop(ctx goctx.Context, etcdSession *concurrency.
case <-ctx.Done():
// Revoke the session lease.
// If revoke takes longer than the ttl, lease is expired anyway.
ctx, cancel := goctx.WithTimeout(goctx.Background(),
cancelCtx, cancel := goctx.WithTimeout(goctx.Background(),
time.Duration(ManagerSessionTTL)*time.Second)
_, err = m.etcdCli.Revoke(ctx, etcdSession.Lease())
_, err = m.etcdCli.Revoke(cancelCtx, etcdSession.Lease())
cancel()
log.Infof("[ddl] %s break campaign loop err %v", idInfo, err)
return
Expand Down
3 changes: 2 additions & 1 deletion ddl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func (d *ddl) onDropSchema(t *meta.Meta, job *model.Job) (ver int64, _ error) {
err = t.UpdateDatabase(dbInfo)
case model.StateDeleteOnly:
dbInfo.State = model.StateNone
tables, err := t.ListTables(job.SchemaID)
var tables []*model.TableInfo
tables, err = t.ListTables(job.SchemaID)
if err != nil {
return ver, errors.Trace(err)
}
Expand Down
3 changes: 2 additions & 1 deletion distsql/xeval/eval_control_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (e *Evaluator) evalIf(expr *tipb.Expr) (d types.Datum, err error) {
return d, errors.Trace(err)
}
if !child1.IsNull() {
x, err := child1.ToBool(e.StatementCtx)
var x int64
x, err = child1.ToBool(e.StatementCtx)
if err != nil {
return d, errors.Trace(err)
}
Expand Down
3 changes: 2 additions & 1 deletion distsql/xeval/eval_data_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (e *Evaluator) evalColumnRef(val []byte) (types.Datum, error) {

// TODO: Remove this case.
if e.ColVals == nil {
d, ok := e.Row[i]
var ok bool
d, ok = e.Row[i]
if !ok {
return d, ErrInvalid.Gen("column % x not found", val)
}
Expand Down
3 changes: 2 additions & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio

if ebd, ok := store.(etcdBackend); ok {
if addrs := ebd.EtcdAddrs(); addrs != nil {
cli, err := clientv3.New(clientv3.Config{
var cli *clientv3.Client
cli, err = clientv3.New(clientv3.Config{
Endpoints: addrs,
DialTimeout: 5 * time.Second,
})
Expand Down
2 changes: 1 addition & 1 deletion executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func CollectSamplesAndEstimateNDVs(ctx context.Context, e ast.RecordSet, numCols
return collectors, pkBuilder, nil
}
if pkInfo != nil {
err := pkBuilder.Iterate(row.Data)
err = pkBuilder.Iterate(row.Data)
if err != nil {
return nil, nil, errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ func (b *executorBuilder) buildTableScanForAnalyze(tblInfo *model.TableInfo, pk
cols = append([]*model.ColumnInfo{pk}, cols...)
}
schema := expression.NewSchema(expression.ColumnInfos2Columns(tblInfo.Name, cols)...)
ranges := []types.IntColumnRange{{math.MinInt64, math.MaxInt64}}
ranges := []types.IntColumnRange{{LowVal: math.MinInt64, HighVal: math.MaxInt64}}
if b.ctx.GetClient().IsRequestTypeSupported(kv.ReqTypeDAG, kv.ReqSubTypeBasic) {
e := &TableReaderExecutor{
table: table,
Expand Down
6 changes: 5 additions & 1 deletion executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,11 @@ func (e *SelectionExec) initController() error {
}
x.ranges = ranges
case *XSelectIndexExec:
accessCondition, newConds, _, accessInAndEqCount := ranger.DetachIndexScanConditions(newConds, x.index)
var (
accessCondition []expression.Expression
accessInAndEqCount int
)
accessCondition, newConds, _, accessInAndEqCount = ranger.DetachIndexScanConditions(newConds, x.index)
idxConds, tblConds := ranger.DetachIndexFilterConditions(newConds, x.index.Columns, x.tableInfo)
x.indexConditionPBExpr, _, _ = expression.ExpressionsToPB(sc, idxConds, client)
tableConditionPBExpr, _, _ := expression.ExpressionsToPB(sc, tblConds, client)
Expand Down
11 changes: 9 additions & 2 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ func (s *testSuite) TestIssue2612(c *C) {
c.Assert(err, IsNil)
row, err := rs.Next()
c.Assert(err, IsNil)
row.Data[0].GetMysqlDuration().String()
str := row.Data[0].GetMysqlDuration().String()
c.Assert(str, Equals, "-46:09:02")
}

// TestIssue345 is related with https://github.com/pingcap/tidb/issues/345
Expand Down Expand Up @@ -976,6 +977,12 @@ func (s *testSuite) TestStringBuiltin(c *C) {
result.Check(testkit.Rows("MySQL 123 123 "))
result = tk.MustQuery(`select unhex('string'), unhex('你好'), unhex(123.4), unhex(null)`)
result.Check(testkit.Rows("<nil> <nil> <nil> <nil>"))

// for ltrim and rtrim
result = tk.MustQuery(`select ltrim(' bar '), ltrim('bar'), ltrim(''), ltrim(null)`)
result.Check(testutil.RowsWithSep(",", "bar ,bar,,<nil>"))
result = tk.MustQuery(`select rtrim(' bar '), rtrim('bar'), rtrim(''), rtrim(null)`)
result.Check(testutil.RowsWithSep(",", " bar,bar,,<nil>"))
}

func (s *testSuite) TestEncryptionBuiltin(c *C) {
Expand Down Expand Up @@ -1301,7 +1308,7 @@ func (s *testSuite) TestBuiltin(c *C) {
tk.MustExec("create table t (a varchar(255), b int)")
for i, d := range data {
tk.MustExec(fmt.Sprintf("insert into t values('%s', %d)", d.val, i))
result := tk.MustQuery(fmt.Sprintf("select * from t where a %s '%s'", queryOp, d.pattern))
result = tk.MustQuery(fmt.Sprintf("select * from t where a %s '%s'", queryOp, d.pattern))
if d.result == 1 {
rowStr := fmt.Sprintf("%s %d", d.val, i)
result.Check(testkit.Rows(rowStr))
Expand Down
Loading

0 comments on commit 68f0a1d

Please sign in to comment.