Skip to content

Commit

Permalink
expression: fix enum type join binary get wrong result (#30445)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylzd committed Dec 15, 2021
1 parent 04a9618 commit 3fe9263
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions expression/builtin_convert_charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 3fe9263

Please sign in to comment.