Skip to content

Commit

Permalink
executor: fix point get null values (#7790)
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason authored Sep 27, 2018
1 parent 1771d67 commit 86416be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions executor/point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func (e *PointGetExecutor) decodeRowValToChunk(rowVal []byte, chk *chunk.Chunk)
if err != nil {
return errors.Trace(err)
}
if colVals == nil {
colVals = make([][]byte, len(colIDs))
}
decoder := codec.NewDecoder(chk, e.ctx.GetSessionVars().Location())
for id, offset := range colIDs {
if e.tblInfo.PKIsHandle && mysql.HasPriKeyFlag(e.schema.Columns[offset].RetType.Flag) {
Expand All @@ -153,8 +156,7 @@ func (e *PointGetExecutor) decodeRowValToChunk(rowVal []byte, chk *chunk.Chunk)
chk.AppendInt64(offset, e.handle)
continue
}
colVal := colVals[offset]
if len(colVal) == 0 {
if len(colVals[offset]) == 0 {
colInfo := getColInfoByID(e.tblInfo, id)
d, err1 := table.GetColOriginDefaultValue(e.ctx, colInfo)
if err1 != nil {
Expand Down
16 changes: 16 additions & 0 deletions executor/point_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,20 @@ func (s *testSuite) TestPointGet(c *C) {
tk.MustExec("CREATE UNIQUE INDEX idx_tab3_0 ON tab3 (col4);")
tk.MustExec("INSERT INTO tab3 VALUES(0,854,111.96,'mguub',711,966.36,'snwlo');")
tk.MustQuery("SELECT ALL * FROM tab3 WHERE col4 = 85;").Check(testkit.Rows())

tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t(a bigint primary key, b bigint, c bigint);`)
tk.MustExec(`insert into t values(1, NULL, NULL), (2, NULL, 2), (3, 3, NULL), (4, 4, 4);`)
tk.MustQuery(`select * from t where a = 1;`).Check(testkit.Rows(
`1 <nil> <nil>`,
))
tk.MustQuery(`select * from t where a = 2;`).Check(testkit.Rows(
`2 <nil> 2`,
))
tk.MustQuery(`select * from t where a = 3;`).Check(testkit.Rows(
`3 3 <nil>`,
))
tk.MustQuery(`select * from t where a = 4;`).Check(testkit.Rows(
`4 4 4`,
))
}

0 comments on commit 86416be

Please sign in to comment.