Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: fix enum type join binary get wrong result #30445

Merged
merged 8 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 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,10 @@ func (c *tidbToBinaryFunctionClass) getFunction(ctx sessionctx.Context, args []E
return nil, err
}
bf.tp = args[0].GetType().Clone()
// adjust enum/set type
if bf.tp.Tp == mysql.TypeEnum || bf.tp.Tp == mysql.TypeSet {
bf.tp.Tp = mysql.TypeString
}
sylzd marked this conversation as resolved.
Show resolved Hide resolved
bf.tp.Charset, bf.tp.Collate = charset.CharsetBin, charset.CollationBin
sig = &builtinInternalToBinarySig{bf}
sig.setPbCode(tipb.ScalarFuncSig_ToBinary)
Expand Down
12 changes: 12 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9397,3 +9397,15 @@ func (s *testIntegrationSuite) TestIssue30326(c *C) {
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[executor:1242]Subquery returns more than 1 row")
}

func (s *testIntegrationSuite) TestIssue30174(c *C) {
tk := testkit.NewTestKit(c, s.store)
xiongjiwei marked this conversation as resolved.
Show resolved Hide resolved
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())
}