Skip to content

Commit b957a04

Browse files
authored
executor: fix nil pointer for query on tikv_region_status with non-exist table id (pingcap#57534) (pingcap#57565)
close pingcap#57530
1 parent de28749 commit b957a04

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pkg/executor/infoschema_reader.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,7 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx context.Context, sctx
19961996
for _, tableID := range extractorTableIDs {
19971997
regionsInfo, err := e.getRegionsInfoForTable(ctx, tikvHelper, is, tableID)
19981998
if err != nil {
1999-
if errors.ErrorEqual(err, infoschema.ErrTableExists) {
1999+
if errors.ErrorEqual(err, infoschema.ErrTableNotExists) {
20002000
continue
20012001
}
20022002
return err
@@ -2016,6 +2016,10 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx context.Context, sctx
20162016
return err
20172017
}
20182018
}
2019+
if allRegionsInfo == nil {
2020+
return nil
2021+
}
2022+
20192023
tableInfos := tikvHelper.GetRegionsTableInfo(allRegionsInfo, is, nil)
20202024
for i := range allRegionsInfo.Regions {
20212025
regionTableList := tableInfos[allRegionsInfo.Regions[i].ID]
@@ -2040,7 +2044,7 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx context.Context, sctx
20402044
func (e *memtableRetriever) getRegionsInfoForTable(ctx context.Context, h *helper.Helper, is infoschema.InfoSchema, tableID int64) (*pd.RegionsInfo, error) {
20412045
tbl, _ := is.TableByID(ctx, tableID)
20422046
if tbl == nil {
2043-
return nil, infoschema.ErrTableExists.GenWithStackByArgs(tableID)
2047+
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tableID)
20442048
}
20452049

20462050
pt := tbl.Meta().GetPartitionInfo()

tests/realtikvtest/sessiontest/session_fail_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,10 @@ func TestTiKVClientReadTimeout(t *testing.T) {
322322
explain = fmt.Sprintf("%v", rows[0])
323323
require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:(3|4|5).*", explain)
324324
}
325+
326+
func TestIssue57530(t *testing.T) {
327+
store := realtikvtest.CreateMockStoreAndSetup(t)
328+
tk := testkit.NewTestKit(t, store)
329+
tk.MustExec("use information_schema")
330+
tk.MustQuery("select * from TIKV_REGION_STATUS where table_id = 81920").Check(testkit.Rows())
331+
}

0 commit comments

Comments
 (0)