Skip to content

Commit 4c5a9ac

Browse files
alivxxxcoocood
authored andcommitted
executor: fix bug of point get when meet null values (#11219) (#11226)
1 parent 98768ce commit 4c5a9ac

File tree

2 files changed

+19
-34
lines changed

2 files changed

+19
-34
lines changed

executor/point_get.go

+17-34
Original file line numberDiff line numberDiff line change
@@ -196,60 +196,43 @@ func (e *PointGetExecutor) get(key kv.Key) (val []byte, err error) {
196196
}
197197

198198
func (e *PointGetExecutor) decodeRowValToChunk(rowVal []byte, chk *chunk.Chunk) error {
199-
// One column could be filled for multi-times in the schema. e.g. select b, b, c, c from t where a = 1.
200-
// We need to set the positions in the schema for the same column.
201-
colID2DecodedPos := make(map[int64]int, e.schema.Len())
202-
decodedPos2SchemaPos := make([][]int, 0, e.schema.Len())
203-
for schemaPos, col := range e.schema.Columns {
204-
if decodedPos, ok := colID2DecodedPos[col.ID]; !ok {
205-
colID2DecodedPos[col.ID] = len(colID2DecodedPos)
206-
decodedPos2SchemaPos = append(decodedPos2SchemaPos, []int{schemaPos})
207-
} else {
208-
decodedPos2SchemaPos[decodedPos] = append(decodedPos2SchemaPos[decodedPos], schemaPos)
199+
colID2CutPos := make(map[int64]int, e.schema.Len())
200+
for _, col := range e.schema.Columns {
201+
if _, ok := colID2CutPos[col.ID]; !ok {
202+
colID2CutPos[col.ID] = len(colID2CutPos)
209203
}
210204
}
211-
decodedVals, err := tablecodec.CutRowNew(rowVal, colID2DecodedPos)
205+
cutVals, err := tablecodec.CutRowNew(rowVal, colID2CutPos)
212206
if err != nil {
213207
return err
214208
}
215-
if decodedVals == nil {
216-
decodedVals = make([][]byte, len(colID2DecodedPos))
209+
if cutVals == nil {
210+
cutVals = make([][]byte, len(colID2CutPos))
217211
}
218212
decoder := codec.NewDecoder(chk, e.ctx.GetSessionVars().Location())
219-
for id, decodedPos := range colID2DecodedPos {
220-
schemaPoses := decodedPos2SchemaPos[decodedPos]
221-
firstPos := schemaPoses[0]
222-
if e.tblInfo.PKIsHandle && mysql.HasPriKeyFlag(e.schema.Columns[firstPos].RetType.Flag) {
223-
chk.AppendInt64(firstPos, e.handle)
224-
// Fill other positions.
225-
for i := 1; i < len(schemaPoses); i++ {
226-
chk.MakeRef(firstPos, schemaPoses[i])
227-
}
213+
for i, col := range e.schema.Columns {
214+
if e.tblInfo.PKIsHandle && mysql.HasPriKeyFlag(col.RetType.Flag) {
215+
chk.AppendInt64(i, e.handle)
228216
continue
229217
}
230-
// ExtraHandleID is added when building plan, we can make sure that there's only one column's ID is this.
231-
if id == model.ExtraHandleID {
232-
chk.AppendInt64(firstPos, e.handle)
218+
if col.ID == model.ExtraHandleID {
219+
chk.AppendInt64(i, e.handle)
233220
continue
234221
}
235-
if len(decodedVals[decodedPos]) == 0 {
236-
// This branch only entered for updating and deleting. It won't have one column in multiple positions.
237-
colInfo := getColInfoByID(e.tblInfo, id)
222+
cutPos := colID2CutPos[col.ID]
223+
if len(cutVals[cutPos]) == 0 {
224+
colInfo := getColInfoByID(e.tblInfo, col.ID)
238225
d, err1 := table.GetColOriginDefaultValue(e.ctx, colInfo)
239226
if err1 != nil {
240227
return err1
241228
}
242-
chk.AppendDatum(firstPos, &d)
229+
chk.AppendDatum(i, &d)
243230
continue
244231
}
245-
_, err = decoder.DecodeOne(decodedVals[decodedPos], firstPos, e.schema.Columns[firstPos].RetType)
232+
_, err = decoder.DecodeOne(cutVals[cutPos], i, col.RetType)
246233
if err != nil {
247234
return err
248235
}
249-
// Fill other positions.
250-
for i := 1; i < len(schemaPoses); i++ {
251-
chk.MakeRef(firstPos, schemaPoses[i])
252-
}
253236
}
254237
return nil
255238
}

executor/point_get_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ func (s *testPointGetSuite) TestPointGet(c *C) {
101101
tk.MustQuery(`select a, a, b, a, b, c, b, c, c from t where a = 5;`).Check(testkit.Rows(
102102
`5 5 6 5 6 7 6 7 7`,
103103
))
104+
tk.MustQuery(`select b, b from t where a = 1`).Check(testkit.Rows(
105+
"<nil> <nil>"))
104106
}
105107

106108
func (s *testPointGetSuite) TestPointGetCharPK(c *C) {

0 commit comments

Comments
 (0)