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 all 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
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())
}