Skip to content

Commit 86416be

Browse files
authored
executor: fix point get null values (#7790)
1 parent 1771d67 commit 86416be

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

executor/point_get.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func (e *PointGetExecutor) decodeRowValToChunk(rowVal []byte, chk *chunk.Chunk)
143143
if err != nil {
144144
return errors.Trace(err)
145145
}
146+
if colVals == nil {
147+
colVals = make([][]byte, len(colIDs))
148+
}
146149
decoder := codec.NewDecoder(chk, e.ctx.GetSessionVars().Location())
147150
for id, offset := range colIDs {
148151
if e.tblInfo.PKIsHandle && mysql.HasPriKeyFlag(e.schema.Columns[offset].RetType.Flag) {
@@ -153,8 +156,7 @@ func (e *PointGetExecutor) decodeRowValToChunk(rowVal []byte, chk *chunk.Chunk)
153156
chk.AppendInt64(offset, e.handle)
154157
continue
155158
}
156-
colVal := colVals[offset]
157-
if len(colVal) == 0 {
159+
if len(colVals[offset]) == 0 {
158160
colInfo := getColInfoByID(e.tblInfo, id)
159161
d, err1 := table.GetColOriginDefaultValue(e.ctx, colInfo)
160162
if err1 != nil {

executor/point_get_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,20 @@ func (s *testSuite) TestPointGet(c *C) {
3535
tk.MustExec("CREATE UNIQUE INDEX idx_tab3_0 ON tab3 (col4);")
3636
tk.MustExec("INSERT INTO tab3 VALUES(0,854,111.96,'mguub',711,966.36,'snwlo');")
3737
tk.MustQuery("SELECT ALL * FROM tab3 WHERE col4 = 85;").Check(testkit.Rows())
38+
39+
tk.MustExec(`drop table if exists t;`)
40+
tk.MustExec(`create table t(a bigint primary key, b bigint, c bigint);`)
41+
tk.MustExec(`insert into t values(1, NULL, NULL), (2, NULL, 2), (3, 3, NULL), (4, 4, 4);`)
42+
tk.MustQuery(`select * from t where a = 1;`).Check(testkit.Rows(
43+
`1 <nil> <nil>`,
44+
))
45+
tk.MustQuery(`select * from t where a = 2;`).Check(testkit.Rows(
46+
`2 <nil> 2`,
47+
))
48+
tk.MustQuery(`select * from t where a = 3;`).Check(testkit.Rows(
49+
`3 3 <nil>`,
50+
))
51+
tk.MustQuery(`select * from t where a = 4;`).Check(testkit.Rows(
52+
`4 4 4`,
53+
))
3854
}

0 commit comments

Comments
 (0)