From 7247ccf1cc9b8d0a3bd17079125cf7a7e642cdd8 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Fri, 26 Mar 2021 20:39:23 +0800 Subject: [PATCH] cherry pick #23591 to release-4.0 Signed-off-by: ti-srebot --- expression/integration_test.go | 12 ++++++++++++ types/datum.go | 1 + 2 files changed, 13 insertions(+) diff --git a/expression/integration_test.go b/expression/integration_test.go index 614f06a51b838..6de14fc0137a4 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -8080,3 +8080,15 @@ func (s *testIntegrationSerialSuite) TestIssue19116(c *C) { tk.MustQuery("select coercibility(1);").Check(testkit.Rows("5")) tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5")) } + +func (s *testIntegrationSerialSuite) TestCollationForBinaryLiteral(c *C) { + tk := testkit.NewTestKit(c, s.store) + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("CREATE TABLE t (`COL1` tinyblob NOT NULL, `COL2` binary(1) NOT NULL, `COL3` bigint(11) NOT NULL, PRIMARY KEY (`COL1`(5),`COL2`,`COL3`) /*T![clustered_index] CLUSTERED */)") + tk.MustExec("insert into t values(0x1E,0xEC,6966939640596047133);") + tk.MustQuery("select * from t where col1 not in (0x1B,0x20) order by col1").Check(testkit.Rows("\x1e \xec 6966939640596047133")) + tk.MustExec("drop table t") +} diff --git a/types/datum.go b/types/datum.go index 715ebcb4d315f..7512ff60f0d7f 100644 --- a/types/datum.go +++ b/types/datum.go @@ -252,6 +252,7 @@ func (d *Datum) GetMysqlBit() BinaryLiteral { func (d *Datum) SetBinaryLiteral(b BinaryLiteral) { d.k = KindBinaryLiteral d.b = b + d.collation = charset.CollationBin } // SetMysqlBit sets MysqlBit value