server: fix http schema table_id api with partition ID (#37845)

close pingcap/tidb#37844
This commit is contained in:
Jack Yu
2022-09-26 13:01:43 +08:00
committed by GitHub
parent 35f61a4816
commit bcd8a3ce95
2 changed files with 16 additions and 1 deletions

View File

@ -1201,7 +1201,13 @@ func (h schemaHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
writeData(w, data.Meta())
return
}
writeError(w, infoschema.ErrTableNotExists.GenWithStack("Table which ID = %s does not exist.", tableID))
// The tid maybe a partition ID of the partition-table.
tbl, _, _ := schema.FindTableByPartitionID(int64(tid))
if tbl == nil {
writeError(w, infoschema.ErrTableNotExists.GenWithStack("Table which ID = %s does not exist.", tableID))
return
}
writeData(w, tbl.Meta())
return
}

View File

@ -948,6 +948,15 @@ func TestGetSchema(t *testing.T) {
require.Equal(t, "t1", dbtbl.TableInfo.Name.L)
require.Equal(t, "test", dbtbl.DBInfo.Name.L)
require.Equal(t, ti, dbtbl.TableInfo)
resp, err = ts.fetchStatus(fmt.Sprintf("/schema?table_id=%v", ti.GetPartitionInfo().Definitions[0].ID))
require.NoError(t, err)
decoder = json.NewDecoder(resp.Body)
err = decoder.Decode(&ti)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
require.Equal(t, "t1", ti.Name.L)
require.Equal(t, ti, ti)
}
func TestAllHistory(t *testing.T) {