Skip to content

Commit

Permalink
*: enable gosimple linter
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed May 13, 2021
1 parent f2c2fbd commit 772d05f
Show file tree
Hide file tree
Showing 49 changed files with 106 additions and 172 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ check-static: tools/bin/golangci-lint
--enable=unused \
--enable=structcheck \
--enable=deadcode \
--enable=gosimple \
$$($(PACKAGE_DIRECTORIES))

check-slow:tools/bin/gometalinter tools/bin/gosec
Expand Down
8 changes: 3 additions & 5 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2280,10 +2280,8 @@ func (s *testDBSuite6) TestDropColumn(c *C) {
testddlutil.ExecMultiSQLInGoroutine(c, s.store, "drop_col_db", []string{"insert into t2 set c1 = 1, c2 = 1, c3 = 1, c4 = 1"}, dmlDone)
}
for i := 0; i < num; i++ {
select {
case err := <-ddlDone:
c.Assert(err, IsNil, Commentf("err:%v", errors.ErrorStack(err)))
}
err := <-ddlDone
c.Assert(err, IsNil, Commentf("err:%v", errors.ErrorStack(err)))
}

// Test for drop partition table column.
Expand Down Expand Up @@ -6575,7 +6573,7 @@ func (s *testSerialDBSuite) TestModifyColumnTypeWhenInterception(c *C) {

count := defaultBatchSize * 4
// Add some rows.
dml := fmt.Sprintf("insert into t values")
dml := "insert into t values"
for i := 1; i <= count; i++ {
dml += fmt.Sprintf("(%d, %f)", i, 11.22)
if i != count {
Expand Down
2 changes: 1 addition & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4040,7 +4040,7 @@ func checkAutoRandom(tableInfo *model.TableInfo, originCol *table.Column, specNe
autoid.MaxAutoRandomBits, newRandBits, specNewColumn.Name.Name.O)
return 0, ErrInvalidAutoRandom.GenWithStackByArgs(errMsg)
}
break // Increasing auto_random shard bits is allowed.
// increasing auto_random shard bits is allowed.
case oldRandBits > newRandBits:
if newRandBits == 0 {
return 0, ErrInvalidAutoRandom.GenWithStackByArgs(autoid.AutoRandomAlterErrMsg)
Expand Down
10 changes: 5 additions & 5 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,15 @@ func (s *testSerialSuite) TestCreateTableWithLike(c *C) {

// for failure table cases
tk.MustExec("use ctwl_db")
failSQL := fmt.Sprintf("create table t1 like test_not_exist.t")
failSQL := "create table t1 like test_not_exist.t"
tk.MustGetErrCode(failSQL, mysql.ErrNoSuchTable)
failSQL = fmt.Sprintf("create table t1 like test.t_not_exist")
failSQL = "create table t1 like test.t_not_exist"
tk.MustGetErrCode(failSQL, mysql.ErrNoSuchTable)
failSQL = fmt.Sprintf("create table t1 (like test_not_exist.t)")
failSQL = "create table t1 (like test_not_exist.t)"
tk.MustGetErrCode(failSQL, mysql.ErrNoSuchTable)
failSQL = fmt.Sprintf("create table test_not_exis.t1 like ctwl_db.t")
failSQL = "create table test_not_exis.t1 like ctwl_db.t"
tk.MustGetErrCode(failSQL, mysql.ErrBadDB)
failSQL = fmt.Sprintf("create table t1 like ctwl_db.t")
failSQL = "create table t1 like ctwl_db.t"
tk.MustGetErrCode(failSQL, mysql.ErrTableExists)

// test failure for wrong object cases
Expand Down
4 changes: 1 addition & 3 deletions executor/aggfuncs/func_percentile.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ func (e *basePercentile) AllocPartialResult() (pr PartialResult, memDelta int64)
return
}

func (e *basePercentile) ResetPartialResult(pr PartialResult) {
return
}
func (e *basePercentile) ResetPartialResult(pr PartialResult) {}

func (e *basePercentile) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, pr PartialResult) (memDelta int64, err error) {
return
Expand Down
1 change: 0 additions & 1 deletion executor/concurrent_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (m concurrentMap) Insert(key uint64, value *entry) {
shard.items[key] = value
}
shard.Unlock()
return
}

// UpsertCb : Callback to return new element to be inserted into the map
Expand Down
5 changes: 1 addition & 4 deletions executor/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,7 @@ func (e *DeleteExec) removeRowsInTblRowMap(tblRowMap tableRowMapType) error {
var err error
rowMap.Range(func(h kv.Handle, val interface{}) bool {
err = e.removeRow(e.ctx, e.tblID2Table[id], h, val.([]types.Datum))
if err != nil {
return false
}
return true
return err == nil
})
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5809,7 +5809,7 @@ func (s *testRecoverTable) TestRecoverTable(c *C) {
// Test for recover one table multiple time.
tk.MustExec("drop table t_recover")
tk.MustExec("flashback table t_recover to t_recover_tmp")
_, err = tk.Exec(fmt.Sprintf("recover table t_recover"))
_, err = tk.Exec("recover table t_recover")
c.Assert(infoschema.ErrTableExists.Equal(err), IsTrue)

gcEnable, err := gcutil.CheckGCEnable(tk.Se)
Expand Down Expand Up @@ -5876,7 +5876,7 @@ func (s *testRecoverTable) TestFlashbackTable(c *C) {
tk.MustQuery("select a,_tidb_rowid from t_flashback2;").Check(testkit.Rows("1 1", "2 2", "3 3", "4 5001", "5 5002", "6 5003", "7 10001", "8 10002", "9 10003"))

// Test for flashback one table multiple time.
_, err = tk.Exec(fmt.Sprintf("flashback table t_flashback to t_flashback4"))
_, err = tk.Exec("flashback table t_flashback to t_flashback4")
c.Assert(infoschema.ErrTableExists.Equal(err), IsTrue)

// Test for flashback truncated table to new table.
Expand Down
24 changes: 12 additions & 12 deletions executor/explainfor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ func (s *testSuite) TestExplainMemTablePredicate(c *C) {

func (s *testSuite) TestExplainClusterTable(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustQuery(fmt.Sprintf("desc select * from information_schema.cluster_config where type in ('tikv', 'tidb')")).Check(testkit.Rows(
tk.MustQuery("desc select * from information_schema.cluster_config where type in ('tikv', 'tidb')").Check(testkit.Rows(
`MemTableScan_5 10000.00 root table:CLUSTER_CONFIG node_types:["tidb","tikv"]`))
tk.MustQuery(fmt.Sprintf("desc select * from information_schema.cluster_config where instance='192.168.1.7:2379'")).Check(testkit.Rows(
tk.MustQuery("desc select * from information_schema.cluster_config where instance='192.168.1.7:2379'").Check(testkit.Rows(
`MemTableScan_5 10000.00 root table:CLUSTER_CONFIG instances:["192.168.1.7:2379"]`))
tk.MustQuery(fmt.Sprintf("desc select * from information_schema.cluster_config where type='tidb' and instance='192.168.1.7:2379'")).Check(testkit.Rows(
tk.MustQuery("desc select * from information_schema.cluster_config where type='tidb' and instance='192.168.1.7:2379'").Check(testkit.Rows(
`MemTableScan_5 10000.00 root table:CLUSTER_CONFIG node_types:["tidb"], instances:["192.168.1.7:2379"]`))
}

Expand All @@ -203,11 +203,11 @@ func (s *testSuite) TestInspectionResultTable(c *C) {

func (s *testSuite) TestInspectionRuleTable(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustQuery(fmt.Sprintf("desc select * from information_schema.inspection_rules where type='inspection'")).Check(testkit.Rows(
tk.MustQuery("desc select * from information_schema.inspection_rules where type='inspection'").Check(testkit.Rows(
`MemTableScan_5 10000.00 root table:INSPECTION_RULES node_types:["inspection"]`))
tk.MustQuery(fmt.Sprintf("desc select * from information_schema.inspection_rules where type='inspection' or type='summary'")).Check(testkit.Rows(
tk.MustQuery("desc select * from information_schema.inspection_rules where type='inspection' or type='summary'").Check(testkit.Rows(
`MemTableScan_5 10000.00 root table:INSPECTION_RULES node_types:["inspection","summary"]`))
tk.MustQuery(fmt.Sprintf("desc select * from information_schema.inspection_rules where type='inspection' and type='summary'")).Check(testkit.Rows(
tk.MustQuery("desc select * from information_schema.inspection_rules where type='inspection' and type='summary'").Check(testkit.Rows(
`MemTableScan_5 10000.00 root table:INSPECTION_RULES skip_request: true`))
}

Expand Down Expand Up @@ -355,12 +355,12 @@ func (s *testPrepareSerialSuite) TestExplainDotForQuery(c *C) {

func (s *testSuite) TestExplainTableStorage(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustQuery(fmt.Sprintf("desc select * from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'information_schema'")).Check(testkit.Rows(
fmt.Sprintf("MemTableScan_5 10000.00 root table:TABLE_STORAGE_STATS schema:[\"information_schema\"]")))
tk.MustQuery(fmt.Sprintf("desc select * from information_schema.TABLE_STORAGE_STATS where TABLE_NAME = 'schemata'")).Check(testkit.Rows(
fmt.Sprintf("MemTableScan_5 10000.00 root table:TABLE_STORAGE_STATS table:[\"schemata\"]")))
tk.MustQuery(fmt.Sprintf("desc select * from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'information_schema' and TABLE_NAME = 'schemata'")).Check(testkit.Rows(
fmt.Sprintf("MemTableScan_5 10000.00 root table:TABLE_STORAGE_STATS schema:[\"information_schema\"], table:[\"schemata\"]")))
tk.MustQuery("desc select * from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'information_schema'").Check(testkit.Rows(
"MemTableScan_5 10000.00 root table:TABLE_STORAGE_STATS schema:[\"information_schema\"]"))
tk.MustQuery("desc select * from information_schema.TABLE_STORAGE_STATS where TABLE_NAME = 'schemata'").Check(testkit.Rows(
"MemTableScan_5 10000.00 root table:TABLE_STORAGE_STATS table:[\"schemata\"]"))
tk.MustQuery("desc select * from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'information_schema' and TABLE_NAME = 'schemata'").Check(testkit.Rows(
"MemTableScan_5 10000.00 root table:TABLE_STORAGE_STATS schema:[\"information_schema\"], table:[\"schemata\"]"))
}

func (s *testSuite) TestInspectionSummaryTable(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions executor/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s *testSuite3) TestGrantDBScope(c *C) {
createUserSQL := `CREATE USER 'testDB'@'localhost' IDENTIFIED BY '123';`
tk.MustExec(createUserSQL)
// Make sure all the db privs for new user is empty.
sql := fmt.Sprintf("SELECT * FROM mysql.db WHERE User=\"testDB\" and host=\"localhost\"")
sql := `"SELECT * FROM mysql.db WHERE User="testDB" and host="localhost"`
tk.MustQuery(sql).Check(testkit.Rows())

// Grant each priv to the user.
Expand Down Expand Up @@ -101,7 +101,7 @@ func (s *testSuite3) TestWithGrantOption(c *C) {
createUserSQL := `CREATE USER 'testWithGrant'@'localhost' IDENTIFIED BY '123';`
tk.MustExec(createUserSQL)
// Make sure all the db privs for new user is empty.
sql := fmt.Sprintf("SELECT * FROM mysql.db WHERE User=\"testWithGrant\" and host=\"localhost\"")
sql := `SELECT * FROM mysql.db WHERE User="testWithGrant" and host="localhost"`
tk.MustQuery(sql).Check(testkit.Rows())

// Grant select priv to the user, with grant option.
Expand Down
1 change: 0 additions & 1 deletion executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,6 @@ func (e *memtableRetriever) dataForTableTiFlashReplica(ctx sessionctx.Context, s
}
}
e.rows = rows
return
}

func (e *memtableRetriever) setDataForStatementsSummary(ctx sessionctx.Context, tableName string) error {
Expand Down
2 changes: 1 addition & 1 deletion executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (s *testSuite3) TestInsertDateTimeWithTimeZone(c *C) {
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (ts timestamp)")
tk.MustExec("insert into t values ('2020-10-22T12:00:00Z'), ('2020-10-22T13:00:00Z'), ('2020-10-22T14:00:00Z')")
tk.MustQuery(fmt.Sprintf("select count(*) from t where ts > '2020-10-22T12:00:00Z'")).Check(testkit.Rows("2"))
tk.MustQuery("select count(*) from t where ts > '2020-10-22T12:00:00Z'").Check(testkit.Rows("2"))

// test for datetime with fsp
fspCases := []struct {
Expand Down
2 changes: 1 addition & 1 deletion executor/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ func (e *joinRuntimeStats) String() string {
if e.cache.useCache {
buf.WriteString(fmt.Sprintf(", cache:ON, cacheHitRatio:%.3f%%", e.cache.hitRatio*100))
} else {
buf.WriteString(fmt.Sprintf(", cache:OFF"))
buf.WriteString(", cache:OFF")
}
}
if e.hasHashStat {
Expand Down
4 changes: 2 additions & 2 deletions executor/memtable_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ func fetchClusterConfig(sctx sessionctx.Context, nodeTypes, nodeAddrs set.String
continue
}
var str string
switch val.(type) {
switch val := val.(type) {
case string: // remove quotes
str = val.(string)
str = val
default:
tmp, err := json.Marshal(val)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions executor/merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:gosimple // generates false positive fmt.Sprintf warnings which keep aligned
package executor_test

import (
Expand Down Expand Up @@ -277,7 +278,6 @@ func (s *testSerialSuite1) TestShuffleMergeJoinInDisk(c *C) {
c.Assert(tk.Se.GetSessionVars().StmtCtx.MemTracker.MaxConsumed(), Greater, int64(0))
c.Assert(tk.Se.GetSessionVars().StmtCtx.DiskTracker.BytesConsumed(), Equals, int64(0))
c.Assert(tk.Se.GetSessionVars().StmtCtx.DiskTracker.MaxConsumed(), Greater, int64(0))
return
}
func (s *testSerialSuite1) TestMergeJoinInDisk(c *C) {
defer config.RestoreFunc()()
Expand Down Expand Up @@ -313,7 +313,6 @@ func (s *testSerialSuite1) TestMergeJoinInDisk(c *C) {
c.Assert(tk.Se.GetSessionVars().StmtCtx.MemTracker.MaxConsumed(), Greater, int64(0))
c.Assert(tk.Se.GetSessionVars().StmtCtx.DiskTracker.BytesConsumed(), Equals, int64(0))
c.Assert(tk.Se.GetSessionVars().StmtCtx.DiskTracker.MaxConsumed(), Greater, int64(0))
return
}

func (s *testSuite2) TestMergeJoin(c *C) {
Expand Down
1 change: 0 additions & 1 deletion executor/parallel_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func checkApplyPlan(c *C, tk *testkit.TestKit, sql string, parallel int) {
}
}
c.Assert(containApply, IsTrue)
return
}

func (s *testSuite) TestParallelApply(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion executor/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (s *partitionTableSuite) TestBatchGetandPointGetwithHashPartition(c *C) {
}

// test empty PointGet
queryHash := fmt.Sprintf("select a from thash where a=200")
queryHash := "select a from thash where a=200"
c.Assert(tk.HasPlan(queryHash, "Point_Get"), IsTrue) // check if PointGet is used
tk.MustQuery(queryHash).Check(testkit.Rows())

Expand Down
8 changes: 4 additions & 4 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,10 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
}

if pkCol != nil {
// If PKIsHanle, pk info is not in tb.Indices(). We should handle it here.
// If PKIsHandle, pk info is not in tb.Indices(). We should handle it here.
buf.WriteString(",\n")
fmt.Fprintf(buf, " PRIMARY KEY (%s)", stringutil.Escape(pkCol.Name.O, sqlMode))
buf.WriteString(fmt.Sprintf(" /*T![clustered_index] CLUSTERED */"))
buf.WriteString(" /*T![clustered_index] CLUSTERED */")
}

publicIndices := make([]*model.IndexInfo, 0, len(tableInfo.Indices))
Expand Down Expand Up @@ -906,9 +906,9 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
}
if idxInfo.Primary {
if tableInfo.PKIsHandle || tableInfo.IsCommonHandle {
buf.WriteString(fmt.Sprintf(" /*T![clustered_index] CLUSTERED */"))
buf.WriteString(" /*T![clustered_index] CLUSTERED */")
} else {
buf.WriteString(fmt.Sprintf(" /*T![clustered_index] NONCLUSTERED */"))
buf.WriteString(" /*T![clustered_index] NONCLUSTERED */")
}
}
if i != len(publicIndices)-1 {
Expand Down
2 changes: 1 addition & 1 deletion expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5833,7 +5833,7 @@ func (s *testIntegrationSuite) TestDecodetoChunkReuse(c *C) {
tk.MustExec("create table chk (a int,b varchar(20))")
for i := 0; i < 200; i++ {
if i%5 == 0 {
tk.MustExec(fmt.Sprintf("insert chk values (NULL,NULL)"))
tk.MustExec("insert chk values (NULL,NULL)")
continue
}
tk.MustExec(fmt.Sprintf("insert chk values (%d,'%s')", i, strconv.Itoa(i)))
Expand Down
14 changes: 3 additions & 11 deletions infoschema/metrics_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,9 @@ func (def *MetricTableDef) genColumnInfos() []columnInfo {
// GenPromQL generates the promQL.
func (def *MetricTableDef) GenPromQL(sctx sessionctx.Context, labels map[string]set.StringSet, quantile float64) string {
promQL := def.PromQL
if strings.Contains(promQL, promQLQuantileKey) {
promQL = strings.Replace(promQL, promQLQuantileKey, strconv.FormatFloat(quantile, 'f', -1, 64), -1)
}

if strings.Contains(promQL, promQLLabelConditionKey) {
promQL = strings.Replace(promQL, promQLLabelConditionKey, def.genLabelCondition(labels), -1)
}

if strings.Contains(promQL, promQRangeDurationKey) {
promQL = strings.Replace(promQL, promQRangeDurationKey, strconv.FormatInt(sctx.GetSessionVars().MetricSchemaRangeDuration, 10)+"s", -1)
}
promQL = strings.Replace(promQL, promQLQuantileKey, strconv.FormatFloat(quantile, 'f', -1, 64), -1)
promQL = strings.Replace(promQL, promQLLabelConditionKey, def.genLabelCondition(labels), -1)
promQL = strings.Replace(promQL, promQRangeDurationKey, strconv.FormatInt(sctx.GetSessionVars().MetricSchemaRangeDuration, 10)+"s", -1)
return promQL
}

Expand Down
10 changes: 2 additions & 8 deletions planner/cascades/implementation_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ type ImplTableDual struct {

// Match implements ImplementationRule Match interface.
func (r *ImplTableDual) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool) {
if !prop.IsEmpty() {
return false
}
return true
return prop.IsEmpty()
}

// OnImplement implements ImplementationRule OnImplement interface.
Expand All @@ -116,10 +113,7 @@ type ImplMemTableScan struct {

// Match implements ImplementationRule Match interface.
func (r *ImplMemTableScan) Match(expr *memo.GroupExpr, prop *property.PhysicalProperty) (matched bool) {
if !prop.IsEmpty() {
return false
}
return true
return prop.IsEmpty()
}

// OnImplement implements ImplementationRule OnImplement interface.
Expand Down
5 changes: 1 addition & 4 deletions planner/cascades/transformation_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,10 +1503,7 @@ func NewRuleMergeAggregationProjection() Transformation {
// Match implements Transformation interface.
func (r *MergeAggregationProjection) Match(old *memo.ExprIter) bool {
proj := old.Children[0].GetExpr().ExprNode.(*plannercore.LogicalProjection)
if plannercore.ExprsHasSideEffects(proj.Exprs) {
return false
}
return true
return !plannercore.ExprsHasSideEffects(proj.Exprs)
}

// OnTransform implements Transformation interface.
Expand Down
8 changes: 4 additions & 4 deletions planner/core/partition_pruner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (s *testPartitionPruneSuit) TestListColumnsPartitionPrunerRandom(c *C) {
tk1.MustExec(insert)

// Test query without condition
query := fmt.Sprintf("select * from t1 order by id,a,b")
query := "select * from t1 order by id,a,b"
tk.MustQuery(query).Check(tk1.MustQuery(query).Rows())
}

Expand Down Expand Up @@ -467,9 +467,9 @@ func (s *testPartitionPruneSuit) TestRangePartitionPredicatePruner(c *C) {
tk.Se.GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeIntOnly
tk.MustExec(`create table t (a int(11) default null) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
partition by range(a) (
partition p0 values less than (1),
partition p1 values less than (2),
partition p2 values less than (3),
partition p0 values less than (1),
partition p1 values less than (2),
partition p2 values less than (3),
partition p_max values less than (maxvalue));`)

var input []string
Expand Down
Loading

0 comments on commit 772d05f

Please sign in to comment.