Skip to content

Commit 4442d49

Browse files
authored
executor: fix nil pointer for query on tikv_region_status with non-exist table id (#57534)
close #57530
1 parent e234164 commit 4442d49

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
@@ -1962,7 +1962,7 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx context.Context, sctx
19621962
for _, tableID := range extractorTableIDs {
19631963
regionsInfo, err := e.getRegionsInfoForTable(ctx, tikvHelper, is, tableID)
19641964
if err != nil {
1965-
if errors.ErrorEqual(err, infoschema.ErrTableExists) {
1965+
if errors.ErrorEqual(err, infoschema.ErrTableNotExists) {
19661966
continue
19671967
}
19681968
return err
@@ -1982,6 +1982,10 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx context.Context, sctx
19821982
return err
19831983
}
19841984
}
1985+
if allRegionsInfo == nil {
1986+
return nil
1987+
}
1988+
19851989
tableInfos := tikvHelper.GetRegionsTableInfo(allRegionsInfo, is, nil)
19861990
for i := range allRegionsInfo.Regions {
19871991
regionTableList := tableInfos[allRegionsInfo.Regions[i].ID]
@@ -2006,7 +2010,7 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx context.Context, sctx
20062010
func (e *memtableRetriever) getRegionsInfoForTable(ctx context.Context, h *helper.Helper, is infoschema.InfoSchema, tableID int64) (*pd.RegionsInfo, error) {
20072011
tbl, _ := is.TableByID(ctx, tableID)
20082012
if tbl == nil {
2009-
return nil, infoschema.ErrTableExists.GenWithStackByArgs(tableID)
2013+
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tableID)
20102014
}
20112015

20122016
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
@@ -325,3 +325,10 @@ func TestTiKVClientReadTimeout(t *testing.T) {
325325
explain = fmt.Sprintf("%v", rows[0])
326326
require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:(3|4|5).*", explain)
327327
}
328+
329+
func TestIssue57530(t *testing.T) {
330+
store := realtikvtest.CreateMockStoreAndSetup(t)
331+
tk := testkit.NewTestKit(t, store)
332+
tk.MustExec("use information_schema")
333+
tk.MustQuery("select * from TIKV_REGION_STATUS where table_id = 81920").Check(testkit.Rows())
334+
}

0 commit comments

Comments
 (0)