diff --git a/expression/builtin_convert_charset.go b/expression/builtin_convert_charset.go index 4101d00a3b66b..fc709cc7c61f0 100644 --- a/expression/builtin_convert_charset.go +++ b/expression/builtin_convert_charset.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/charset" "github.com/pingcap/tidb/parser/model" + "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" @@ -65,6 +66,7 @@ func (c *tidbToBinaryFunctionClass) getFunction(ctx sessionctx.Context, args []E return nil, err } bf.tp = args[0].GetType().Clone() + bf.tp.Tp = mysql.TypeVarString bf.tp.Charset, bf.tp.Collate = charset.CharsetBin, charset.CollationBin sig = &builtinInternalToBinarySig{bf} sig.setPbCode(tipb.ScalarFuncSig_ToBinary) diff --git a/expression/integration_test.go b/expression/integration_test.go index fa26348ab313a..79cb81daf90f6 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6895,3 +6895,17 @@ func TestIssue30326(t *testing.T) { err := tk.QueryToErr("select (FIRST_VALUE(1) over (partition by v.a)) as c3 from (select a from t where t.a = (select a from t t2 where t.a = t2.a)) as v;") require.Error(t, err, "[executor:1242]Subquery returns more than 1 row") } + +func TestIssue30174(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1,t2;") + tk.MustExec("CREATE TABLE `t1` (\n `c1` enum('Alice','Bob','Charlie','David') NOT NULL,\n `c2` blob NOT NULL,\n PRIMARY KEY (`c2`(5)),\n UNIQUE KEY `idx_89` (`c1`)\n);") + tk.MustExec("CREATE TABLE `t2` (\n `c1` enum('Alice','Bob','Charlie','David') NOT NULL DEFAULT 'Alice',\n `c2` set('Alice','Bob','Charlie','David') NOT NULL DEFAULT 'David',\n `c3` enum('Alice','Bob','Charlie','David') NOT NULL,\n PRIMARY KEY (`c3`,`c2`)\n);") + tk.MustExec("insert into t1 values('Charlie','');") + tk.MustExec("insert into t2 values('Charlie','Charlie','Alice');") + tk.MustQuery("select * from t2 where c3 in (select c2 from t1);").Check(testkit.Rows()) + tk.MustQuery("select * from t2 where c2 in (select c2 from t1);").Check(testkit.Rows()) +}