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

executor: set the inner join keys' field length to unspecified (#21233) #21249

Merged
merged 7 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 14 additions & 2 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,13 @@ func (b *executorBuilder) buildIndexLookUpJoin(v *plannercore.PhysicalIndexJoin)
innerPlan := v.Children()[v.InnerChildIdx]
innerTypes := make([]*types.FieldType, innerPlan.Schema().Len())
for i, col := range innerPlan.Schema().Columns {
innerTypes[i] = col.RetType
innerTypes[i] = col.RetType.Clone()
// The `innerTypes` would be called for `Datum.ConvertTo` when converting the columns from outer table
// to build hash map or construct lookup keys. So we need to modify its Flen otherwise there would be
// truncate error. See issue https://github.com/pingcap/tidb/issues/21232 for example.
if innerTypes[i].EvalType() == types.ETString {
innerTypes[i].Flen = types.UnspecifiedLength
}
}

var (
Expand Down Expand Up @@ -2158,7 +2164,13 @@ func (b *executorBuilder) buildIndexLookUpMergeJoin(v *plannercore.PhysicalIndex
innerPlan := v.Children()[v.InnerChildIdx]
innerTypes := make([]*types.FieldType, innerPlan.Schema().Len())
for i, col := range innerPlan.Schema().Columns {
innerTypes[i] = col.RetType
innerTypes[i] = col.RetType.Clone()
// The `innerTypes` would be called for `Datum.ConvertTo` when converting the columns from outer table
// to build hash map or construct lookup keys. So we need to modify its Flen otherwise there would be
// truncate error. See issue https://github.com/pingcap/tidb/issues/21232 for example.
if innerTypes[i].EvalType() == types.ETString {
innerTypes[i].Flen = types.UnspecifiedLength
}
}
var (
outerFilter []expression.Expression
Expand Down
20 changes: 20 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -2872,3 +2873,22 @@ func (s *testSerialSuite1) TestIssue20724(c *C) {
tk.MustQuery("select * from t1").Check(testkit.Rows("A"))
tk.MustExec("drop table t1")
}

func (s *testSuite) TestIssue21232(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t, t1")
tk.MustExec("create table t(a varchar(1), index idx(a))")
tk.MustExec("create table t1(a varchar(5), index idx(a))")
tk.MustExec("insert into t values('a'), ('b')")
tk.MustExec("insert into t1 values('a'), ('bbbbb')")
tk.MustExec("update /*+ INL_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a")
tk.MustQuery("show warnings").Check(testkit.Rows())
tk.MustQuery("select * from t").Check(testkit.Rows("a", "b"))
tk.MustExec("update /*+ INL_HASH_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a")
tk.MustQuery("show warnings").Check(testkit.Rows())
tk.MustQuery("select * from t").Check(testkit.Rows("a", "b"))
tk.MustExec("update /*+ INL_MERGE_JOIN(t) */ t, t1 set t.a='a' where t.a=t1.a")
tk.MustQuery("show warnings").Check(testkit.Rows())
tk.MustQuery("select * from t").Check(testkit.Rows("a", "b"))
}