expression: rewrite "HashCode()" for "Column" (#4457)

This commit is contained in:
Jian Zhang
2017-09-07 10:01:05 +08:00
committed by Ewan Chou
parent 9f040b850c
commit 4e580249db
3 changed files with 20 additions and 2 deletions

View File

@ -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
}

View File

@ -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)()

View File

@ -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)