diff --git a/expression/builtin_other.go b/expression/builtin_other.go index e67e6037c6abb..e90c5d31e6016 100644 --- a/expression/builtin_other.go +++ b/expression/builtin_other.go @@ -797,6 +797,19 @@ func (b *builtinValuesIntSig) evalInt(_ chunk.Row) (int64, bool, error) { if row.IsNull(b.offset) { return 0, true, nil } + // For BinaryLiteral, see issue #15310 + val := row.GetRaw(b.offset) + if len(val) > 8 { + return 0, true, errors.New("Session current insert values is too long") + } + if len(val) < 8 { + var binary types.BinaryLiteral = val + v, err := binary.ToInt(b.ctx.GetSessionVars().StmtCtx) + if err != nil { + return 0, true, errors.Trace(err) + } + return int64(v), false, nil + } return row.GetInt64(b.offset), false, nil } return 0, true, errors.Errorf("Session current insert values len %d and column's offset %v don't match", row.Len(), b.offset) diff --git a/expression/integration_test.go b/expression/integration_test.go index fdbae91195798..3605c66154c94 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5341,6 +5341,21 @@ func (s *testIntegrationSuite) TestCastStrToInt(c *C) { } } +func (s *testIntegrationSuite) TestValuesForBinaryLiteral(c *C) { + // See issue #15310 + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test;") + tk.MustExec("create table testValuesBinary(id int primary key auto_increment, a bit(1));") + tk.MustExec("insert into testValuesBinary values(1,1);") + err := tk.ExecToErr("insert into testValuesBinary values(1,1) on duplicate key update id = values(id),a = values(a);") + c.Assert(err, IsNil) + tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("0")) + err = tk.ExecToErr("insert into testValuesBinary values(1,0) on duplicate key update id = values(id),a = values(a);") + c.Assert(err, IsNil) + tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("1")) + tk.MustExec("drop table testValuesBinary;") +} + func (s *testIntegrationSuite) TestIssue14159(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) tk.MustExec("DROP TABLE IF EXISTS t")