Skip to content

Commit

Permalink
executor: fix nil pointer for query on tikv_region_status with non-ex…
Browse files Browse the repository at this point in the history
…ist table id (#57534)

close #57530
  • Loading branch information
tiancaiamao authored Nov 20, 2024
1 parent e234164 commit 4442d49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx context.Context, sctx
for _, tableID := range extractorTableIDs {
regionsInfo, err := e.getRegionsInfoForTable(ctx, tikvHelper, is, tableID)
if err != nil {
if errors.ErrorEqual(err, infoschema.ErrTableExists) {
if errors.ErrorEqual(err, infoschema.ErrTableNotExists) {
continue
}
return err
Expand All @@ -1982,6 +1982,10 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx context.Context, sctx
return err
}
}
if allRegionsInfo == nil {
return nil
}

tableInfos := tikvHelper.GetRegionsTableInfo(allRegionsInfo, is, nil)
for i := range allRegionsInfo.Regions {
regionTableList := tableInfos[allRegionsInfo.Regions[i].ID]
Expand All @@ -2006,7 +2010,7 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx context.Context, sctx
func (e *memtableRetriever) getRegionsInfoForTable(ctx context.Context, h *helper.Helper, is infoschema.InfoSchema, tableID int64) (*pd.RegionsInfo, error) {
tbl, _ := is.TableByID(ctx, tableID)
if tbl == nil {
return nil, infoschema.ErrTableExists.GenWithStackByArgs(tableID)
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tableID)
}

pt := tbl.Meta().GetPartitionInfo()
Expand Down
7 changes: 7 additions & 0 deletions tests/realtikvtest/sessiontest/session_fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,10 @@ func TestTiKVClientReadTimeout(t *testing.T) {
explain = fmt.Sprintf("%v", rows[0])
require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .*num_rpc:(3|4|5).*", explain)
}

func TestIssue57530(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use information_schema")
tk.MustQuery("select * from TIKV_REGION_STATUS where table_id = 81920").Check(testkit.Rows())
}

0 comments on commit 4442d49

Please sign in to comment.