Skip to content

Commit

Permalink
executor, types: copy enum/set instead of refer the underlying data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Apr 29, 2020
1 parent 447106a commit 49de760
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
5 changes: 3 additions & 2 deletions executor/aggfuncs/func_first_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func (e *firstRow4Enum) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup
if err != nil {
return err
}
p.gotFirstRow, p.isNull, p.val = true, d.IsNull(), d.GetMysqlEnum()
p.gotFirstRow, p.isNull, p.val = true, d.IsNull(), d.GetMysqlEnum().Copy()
break
}
return nil
Expand All @@ -500,6 +500,7 @@ func (*firstRow4Enum) MergePartialResult(sctx sessionctx.Context, src PartialRes
}
return nil
}

func (e *firstRow4Enum) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error {
p := (*partialResult4FirstRowEnum)(pr)
if p.isNull || !p.gotFirstRow {
Expand Down Expand Up @@ -533,7 +534,7 @@ func (e *firstRow4Set) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup
if err != nil {
return err
}
p.gotFirstRow, p.isNull, p.val = true, d.IsNull(), d.GetMysqlSet()
p.gotFirstRow, p.isNull, p.val = true, d.IsNull(), d.GetMysqlSet().Copy()
break
}
return nil
Expand Down
23 changes: 23 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4449,3 +4449,26 @@ func (s *testSuite1) TestIssue16025(c *C) {
tk.MustQuery("SELECT * FROM t0 WHERE c0;").Check(testkit.Rows())

}

func (s *testSuite1) TestIssue16854(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists t;")
tk.MustExec("CREATE TABLE `t` ( `a` enum('WAITING','PRINTED','STOCKUP','CHECKED','OUTSTOCK','PICKEDUP','WILLBACK','BACKED') DEFAULT NULL)")
tk.MustExec("insert into t values(1),(2),(3),(4),(5),(6),(7);")
for i := 0; i < 7; i++ {
tk.MustExec("insert into t select * from t;")
}
tk.MustExec("set @@tidb_max_chunk_size=100;")
tk.MustQuery("select distinct a from t order by a").Check(testkit.Rows("WAITING", "PRINTED", "STOCKUP", "CHECKED", "OUTSTOCK", "PICKEDUP", "WILLBACK"))
tk.MustExec("drop table t")

tk.MustExec("CREATE TABLE `t` ( `a` set('WAITING','PRINTED','STOCKUP','CHECKED','OUTSTOCK','PICKEDUP','WILLBACK','BACKED') DEFAULT NULL)")
tk.MustExec("insert into t values(1),(2),(3),(4),(5),(6),(7);")
for i := 0; i < 7; i++ {
tk.MustExec("insert into t select * from t;")
}
tk.MustExec("set @@tidb_max_chunk_size=100;")
tk.MustQuery("select distinct a from t order by a").Check(testkit.Rows("WAITING", "PRINTED", "WAITING,PRINTED", "STOCKUP", "WAITING,STOCKUP", "PRINTED,STOCKUP", "WAITING,PRINTED,STOCKUP"))
tk.MustExec("drop table t")
}
9 changes: 9 additions & 0 deletions types/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/util/stringutil"
)

// Enum is for MySQL enum type.
Expand All @@ -26,6 +27,14 @@ type Enum struct {
Value uint64
}

// Copy deep copy an Enum.
func (e Enum) Copy() Enum {
return Enum{
Name: stringutil.Copy(e.Name),
Value: e.Value,
}
}

// String implements fmt.Stringer interface.
func (e Enum) String() string {
return e.Name
Expand Down
9 changes: 9 additions & 0 deletions types/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/util/stringutil"
)

var zeroSet = Set{Name: "", Value: 0}
Expand All @@ -38,6 +39,14 @@ func (e Set) ToNumber() float64 {
return float64(e.Value)
}

// Copy deep copy a Set.
func (e Set) Copy() Set {
return Set{
Name: stringutil.Copy(e.Name),
Value: e.Value,
}
}

// ParseSetName creates a Set with name.
func ParseSetName(elems []string, name string) (Set, error) {
if len(name) == 0 {
Expand Down

0 comments on commit 49de760

Please sign in to comment.