Skip to content

Commit

Permalink
*: fix ineffectual assignments pingcap#4713 (pingcap#4746)
Browse files Browse the repository at this point in the history
  • Loading branch information
mccxj authored and XuHuaiyu committed Oct 12, 2017
1 parent 83ace4f commit 51a6e6f
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 20 deletions.
1 change: 1 addition & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ func (s *testSuite) TestDelete(c *C) {
_, err := tk.Exec("delete from delete_test where id = (select '2a')")
c.Assert(err, NotNil)
_, err = tk.Exec("delete ignore from delete_test where id = (select '2a')")
c.Assert(err, IsNil)
tk.CheckExecResult(1, 0)
r := tk.MustQuery("SHOW WARNINGS;")
r.Check(testkit.Rows("Warning 1265 Data Truncated", "Warning 1265 Data Truncated"))
Expand Down
16 changes: 10 additions & 6 deletions expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,13 @@ func (b *builtinCeilDecToIntSig) evalInt(row []types.Datum) (int64, bool, error)
}
// err here will only be ErrOverFlow(will never happen) or ErrTruncate(can be ignored).
res, err := val.ToInt()
if err == types.ErrTruncated && !val.IsNegative() {
if err == types.ErrTruncated {
err = nil
res = res + 1
if !val.IsNegative() {
res = res + 1
}
}
return res, false, nil
return res, false, errors.Trace(err)
}

type builtinCeilDecToDecSig struct {
Expand Down Expand Up @@ -600,11 +602,13 @@ func (b *builtinFloorDecToIntSig) evalInt(row []types.Datum) (int64, bool, error
}
// err here will only be ErrOverFlow(will never happen) or ErrTruncate(can be ignored).
res, err := val.ToInt()
if err == types.ErrTruncated && val.IsNegative() {
if err == types.ErrTruncated {
err = nil
res--
if val.IsNegative() {
res--
}
}
return res, false, nil
return res, false, errors.Trace(err)
}

type builtinFloorDecToDecSig struct {
Expand Down
4 changes: 4 additions & 0 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ func (s *testEvaluatorSuite) TestUTCTime(c *C) {
c.Assert(err, IsNil)
c.Assert(f.canBeFolded(), IsTrue)
v, err := f.eval(nil)
c.Assert(err, IsNil)
n := v.GetMysqlDuration()
c.Assert(n.String(), HasLen, 8)
c.Assert(n.String(), GreaterEqual, last.Format(tfStr))
Expand Down Expand Up @@ -1307,6 +1308,7 @@ func (s *testEvaluatorSuite) TestDateDiff(c *C) {
c.Assert(f.canBeFolded(), IsTrue)
c.Assert(err, IsNil)
d, err := f.eval(nil)
c.Assert(err, IsNil)
c.Assert(d.IsNull(), IsTrue)
}
}
Expand Down Expand Up @@ -1780,6 +1782,7 @@ func (s *testEvaluatorSuite) TestMakeTime(c *C) {
got, err := f.eval(nil)
c.Assert(err, NotNil)
want, err := t["Want"][0].ToString()
c.Assert(err, IsNil)
c.Assert(got.GetMysqlDuration().String(), Equals, want, Commentf("[%v] - args:%v", idx, t["Args"]))
}
}
Expand Down Expand Up @@ -2278,6 +2281,7 @@ func (s *testEvaluatorSuite) TestLastDay(c *C) {
c.Assert(f.canBeFolded(), IsTrue)
c.Assert(err, IsNil)
d, err := f.eval(nil)
c.Assert(err, IsNil)
c.Assert(d.IsNull(), IsTrue)
}
}
2 changes: 2 additions & 0 deletions expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,11 @@ func (s *testEvaluatorSuite) TestSortByItem2Pb(c *C) {
pbByItem = SortByItemToPB(sc, client, item, false)
js, err = json.Marshal(pbByItem)
c.Assert(err, IsNil)
c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0},\"desc\":false}")

item = dg.genColumn(mysql.TypeDouble, 1)
pbByItem = SortByItemToPB(sc, client, item, true)
js, err = json.Marshal(pbByItem)
c.Assert(err, IsNil)
c.Assert(string(js), Equals, "{\"expr\":{\"tp\":201,\"val\":\"gAAAAAAAAAE=\",\"sig\":0},\"desc\":true}")
}
3 changes: 3 additions & 0 deletions plan/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (s *testAnalyzeSuite) TestIndexRead(c *C) {
err = plan.ResolveName(stmt, is, ctx)
c.Assert(err, IsNil)
p, err := plan.Optimize(ctx, stmt, is)
c.Assert(err, IsNil)
c.Assert(plan.ToString(p), Equals, tt.best, Commentf("for %s", tt.sql))
}
}
Expand Down Expand Up @@ -205,6 +206,7 @@ func (s *testAnalyzeSuite) TestEmptyTable(c *C) {
err = plan.ResolveName(stmt, is, ctx)
c.Assert(err, IsNil)
p, err := plan.Optimize(ctx, stmt, is)
c.Assert(err, IsNil)
c.Assert(plan.ToString(p), Equals, tt.best, Commentf("for %s", tt.sql))
}
}
Expand Down Expand Up @@ -290,6 +292,7 @@ func (s *testAnalyzeSuite) TestAnalyze(c *C) {
err = plan.ResolveName(stmt, is, ctx)
c.Assert(err, IsNil)
p, err := plan.Optimize(ctx, stmt, is)
c.Assert(err, IsNil)
c.Assert(plan.ToString(p), Equals, tt.best, Commentf("for %s", tt.sql))
}
}
Expand Down
16 changes: 8 additions & 8 deletions plan/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ func (s *testPlanSuite) TestPlanBuilder(c *C) {
}
p := builder.build(stmt)
if lp, ok := p.(LogicalPlan); ok {
p, err = logicalOptimize(flagBuildKeyInfo|flagDecorrelate|flagPrunColumns, lp.(LogicalPlan), builder.ctx, builder.allocator)
p, err = logicalOptimize(flagBuildKeyInfo|flagDecorrelate|flagPrunColumns, lp, builder.ctx, builder.allocator)
c.Assert(err, IsNil)
}
c.Assert(builder.err, IsNil)
c.Assert(ToString(p), Equals, ca.plan, Commentf("for %s", ca.sql))
Expand Down Expand Up @@ -749,10 +750,9 @@ func (s *testPlanSuite) TestJoinReOrder(c *C) {
}
p := builder.build(stmt)
c.Assert(builder.err, IsNil)
lp := p.(LogicalPlan)
p, err = logicalOptimize(flagPredicatePushDown, lp.(LogicalPlan), builder.ctx, builder.allocator)
p, err = logicalOptimize(flagPredicatePushDown, p.(LogicalPlan), builder.ctx, builder.allocator)
c.Assert(err, IsNil)
c.Assert(ToString(lp), Equals, tt.best, Commentf("for %s", tt.sql))
c.Assert(ToString(p), Equals, tt.best, Commentf("for %s", tt.sql))
}
}

Expand Down Expand Up @@ -856,11 +856,10 @@ func (s *testPlanSuite) TestAggPushDown(c *C) {
builder.ctx.GetSessionVars().AllowAggPushDown = true
p := builder.build(stmt)
c.Assert(builder.err, IsNil)
lp := p.(LogicalPlan)
p, err = logicalOptimize(flagBuildKeyInfo|flagPredicatePushDown|flagPrunColumns|flagAggregationOptimize, lp.(LogicalPlan), builder.ctx, builder.allocator)
lp.ResolveIndices()
p, err = logicalOptimize(flagBuildKeyInfo|flagPredicatePushDown|flagPrunColumns|flagAggregationOptimize, p.(LogicalPlan), builder.ctx, builder.allocator)
p.ResolveIndices()
c.Assert(err, IsNil)
c.Assert(ToString(lp), Equals, tt.best, Commentf("for %s", tt.sql))
c.Assert(ToString(p), Equals, tt.best, Commentf("for %s", tt.sql))
}
}

Expand Down Expand Up @@ -1265,6 +1264,7 @@ func (s *testPlanSuite) TestUniqueKeyInfo(c *C) {
c.Assert(builder.err, IsNil, comment)

p, err = logicalOptimize(flagPredicatePushDown|flagPrunColumns|flagBuildKeyInfo, p.(LogicalPlan), builder.ctx, builder.allocator)
c.Assert(err, IsNil)
checkUniqueKeys(p, c, tt.ans, tt.sql)
}
}
Expand Down
2 changes: 2 additions & 0 deletions plan/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ func (s *testPlanSuite) TestProjectionElimination(c *C) {
lp, err := logicalOptimize(flagPredicatePushDown|flagPrunColumns|flagDecorrelate|flagEliminateProjection, p.(LogicalPlan), builder.ctx, builder.allocator)
lp.ResolveIndices()
info, err := lp.convert2PhysicalPlan(&requiredProperty{})
c.Assert(err, IsNil)
info.p = eliminatePhysicalProjection(info.p)
c.Assert(ToString(info.p), Equals, tt.ans, Commentf("for %s", tt.sql))
if i == len(tests)-2 {
Expand Down Expand Up @@ -838,6 +839,7 @@ func (s *testPlanSuite) TestAddCache(c *C) {
lp, err = (&projectionEliminater{}).optimize(lp, nil, nil)
c.Assert(err, IsNil)
info, err := lp.convert2PhysicalPlan(&requiredProperty{})
c.Assert(err, IsNil)
pp := info.p
addCachePlan(pp, builder.allocator)
c.Assert(ToString(pp), Equals, tt.ans, Commentf("for %s", tt.sql))
Expand Down
3 changes: 1 addition & 2 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ func parseHandshakeResponseBody(packet *handshakeResponse41, data []byte, offset
return nil
}
packet.Attrs = attrs
offset += int(num)
}
}

Expand Down Expand Up @@ -622,7 +621,7 @@ func (cc *clientConn) writeEOF(more bool) error {
if more {
status |= mysql.ServerMoreResultsExists
}
data = append(data, dumpUint16(cc.ctx.Status())...)
data = append(data, dumpUint16(status)...)
}

err := cc.writePacket(data)
Expand Down
1 change: 1 addition & 0 deletions store/tikv/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (s *testLockSuite) TestScanLockResolveWithBatchGet(c *C) {
c.Assert(err, IsNil)
snapshot := newTiKVSnapshot(s.store, ver)
m, err := snapshot.BatchGet(keys)
c.Assert(err, IsNil)
c.Assert(len(m), Equals, int('z'-'a'+1))
for ch := byte('a'); ch <= byte('z'); ch++ {
k := []byte{ch}
Expand Down
2 changes: 1 addition & 1 deletion util/codec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (s *testCodecSuite) TestNumberCodec(c *C) {
b, u, err := DecodeComparableUvarint(b)
c.Assert(err, IsNil)
c.Assert(u, Equals, uint64(1))
b, i, err = DecodeComparableVarint(b)
_, i, err = DecodeComparableVarint(b)
c.Assert(err, IsNil)
c.Assert(i, Equals, int64(2))
}
Expand Down
2 changes: 1 addition & 1 deletion util/encrypt/aes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (s *testEncryptSuite) TestUnpad(c *C) {
// Invalid padding: padding content invalid
p = []byte{0x0A, 0x0B, 0x0C, 0x0D, 0x04, 0x04, 0x03, 0x04}
// ^^^^
p, err = PKCS7Unpad(p, 8)
_, err = PKCS7Unpad(p, 8)
c.Assert(err, NotNil)
}

Expand Down
1 change: 0 additions & 1 deletion util/types/mydecimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,6 @@ func DecimalMul(from1, from2, to *MyDecimal) error {
if tmp1 > wordsIntTo {
tmp1 -= wordsIntTo
tmp2 = tmp1 >> 1
wordsInt1 -= tmp2
wordsInt2 -= tmp1 - tmp2
wordsFrac1 = 0
wordsFrac2 = 0
Expand Down
2 changes: 1 addition & 1 deletion util/types/mytime.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func mixDateAndTime(date, time *mysqlTime, neg bool) {
if neg {
sign = 1
}
seconds, microseconds, neg := calcTimeDiff(date, time, sign)
seconds, microseconds, _ := calcTimeDiff(date, time, sign)

// If we want to use this function with arbitrary dates, this code will need
// to cover cases when time is negative and "date < -time".
Expand Down

0 comments on commit 51a6e6f

Please sign in to comment.