diff --git a/expression/column.go b/expression/column.go index c245bc10b3..e6f60dbf0c 100644 --- a/expression/column.go +++ b/expression/column.go @@ -237,7 +237,9 @@ func (col *Column) HashCode() []byte { if len(col.hashcode) != 0 { return col.hashcode } - col.hashcode, _ = codec.EncodeValue(col.hashcode, types.NewIntDatum(int64(col.FromID)), types.NewIntDatum(int64(col.Position))) + col.hashcode = make([]byte, 0, 16) + col.hashcode = codec.EncodeInt(col.hashcode, int64(col.FromID)) + col.hashcode = codec.EncodeInt(col.hashcode, int64(col.Position)) return col.hashcode } diff --git a/expression/column_test.go b/expression/column_test.go index 7d5b5a7b0f..0ad3698c38 100644 --- a/expression/column_test.go +++ b/expression/column_test.go @@ -93,6 +93,22 @@ func (s *testEvaluatorSuite) TestColumn(c *C) { c.Assert(err, IsNil) } +func (s *testEvaluatorSuite) TestColumnHashCode(c *C) { + defer testleak.AfterTest(c)() + + col1 := &Column{ + FromID: 1, + Position: 12, + } + c.Assert(col1.HashCode(), DeepEquals, []byte{0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc}) + + col2 := &Column{ + FromID: 11, + Position: 2, + } + c.Assert(col2.HashCode(), DeepEquals, []byte{0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xb, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2}) +} + func (s *testEvaluatorSuite) TestColumn2Expr(c *C) { defer testleak.AfterTest(c)() diff --git a/expression/scalar_function_test.go b/expression/scalar_function_test.go index 6772f62e91..05d67912d8 100644 --- a/expression/scalar_function_test.go +++ b/expression/scalar_function_test.go @@ -38,7 +38,7 @@ func (s *testEvaluatorSuite) TestScalarFunction(c *C) { c.Assert(res, DeepEquals, []byte{0x22, 0x6c, 0x74, 0x28, 0x66, 0x65, 0x69, 0x2e, 0x68, 0x61, 0x6e, 0x2c, 0x20, 0x31, 0x29, 0x22}) c.Assert(sf.IsCorrelated(), IsFalse) c.Assert(sf.Decorrelate(nil).Equal(sf, s.ctx), IsTrue) - c.Assert(sf.HashCode(), DeepEquals, []byte{0x2, 0x8, 0x2, 0x4, 0x6c, 0x74, 0x2, 0x8, 0x8, 0x0, 0x8, 0x2, 0x2, 0x12, 0x5, 0xbf, 0xf0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}) + c.Assert(sf.HashCode(), DeepEquals, []byte{0x2, 0x8, 0x2, 0x4, 0x6c, 0x74, 0x2, 0x20, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x12, 0x5, 0xbf, 0xf0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}) sf = NewValuesFunc(0, types.NewFieldType(mysql.TypeLonglong), s.ctx) newSf, ok := sf.Clone().(*ScalarFunction)