Skip to content

Commit

Permalink
fix: ignore internal tables in GetSchema rpc call
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Feb 6, 2024
1 parent 3d3c86e commit a5cb770
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions go/vt/vttablet/endtoend/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ func TestGetSchemaRPC(t *testing.T) {
},
getSchemaQueryType: querypb.SchemaTableType_ALL,
getSchemaTables: []string{"vitess_temp1", "vitess_temp3", "unknown_table", "vitess_view3", "vitess_view1", "unknown_view"},
}, {
name: "Create some internal tables",
queries: []string{
"create table _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 (eid int);",
"create table vitess_temp1 (eid int);",
"create view vitess_view1 as select eid from vitess_a",
},
deferQueries: []string{
"drop table _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410",
"drop table vitess_temp1",
"drop view vitess_view1",
},
mapToExpect: map[string]string{
"vitess_view1": "CREATE ALGORITHM=UNDEFINED DEFINER=`vt_dba`@`localhost` SQL SECURITY DEFINER VIEW `vitess_view1` AS select `vitess_a`.`eid` AS `eid` from `vitess_a`",
"vitess_temp1": "CREATE TABLE `vitess_temp1` (\n `eid` int DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci",
// These shouldn't be part of the result, so we verify it is empty.
"_vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410": "",
},
getSchemaQueryType: querypb.SchemaTableType_ALL,
},
}

Expand Down
7 changes: 6 additions & 1 deletion go/vt/vttablet/tabletserver/query_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,12 @@ func (qre *QueryExecutor) executeGetSchemaQuery(query string, callback func(sche
return qre.execStreamSQL(conn, false /* isTransaction */, query, func(result *sqltypes.Result) error {
schemaDef := make(map[string]string)
for _, row := range result.Rows {
schemaDef[row[0].ToString()] = row[1].ToString()
tableName := row[0].ToString()
// Schema RPC should ignore the internal table in the response.
if schema.IsInternalOperationTableName(tableName) {
continue
}
schemaDef[tableName] = row[1].ToString()
}
return callback(&querypb.GetSchemaResponse{TableDefinition: schemaDef})
})
Expand Down

0 comments on commit a5cb770

Please sign in to comment.