Skip to content

Commit

Permalink
executor: set the inner join keys' field length to unspecified (#21233)…
Browse files Browse the repository at this point in the history
… (#21249)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Nov 25, 2020
1 parent 6b938b8 commit 5e8d6ba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
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 @@ -2169,7 +2175,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
19 changes: 19 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2872,3 +2872,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"))
}

0 comments on commit 5e8d6ba

Please sign in to comment.