From bcd8a3ce95ea87d64bb546e11c84308b1e4117bf Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Mon, 26 Sep 2022 13:01:43 +0800 Subject: [PATCH] server: fix http schema table_id api with partition ID (#37845) close pingcap/tidb#37844 --- server/http_handler.go | 8 +++++++- server/http_handler_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/server/http_handler.go b/server/http_handler.go index 75b0af0c02..82d9ec051c 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -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 } diff --git a/server/http_handler_test.go b/server/http_handler_test.go index b4859dd05a..7d2b8c3867 100644 --- a/server/http_handler_test.go +++ b/server/http_handler_test.go @@ -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) {