Skip to content

Commit

Permalink
Ignore execution time errors for schemadiff view analysis
Browse files Browse the repository at this point in the history
The UnsupportedConstruct error is returned for execution of select
queries inside vtgate, but when we analyze views we don't care about
those.

Views here are executed at the MySQL level though and always inside a
single shard, so we don't want to return these errors.

The test example here shows a case where it thinks it's in sharded mode
because of a missing dependency, but we only want to show that we're
missing a table dependency.

Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Feb 5, 2025
1 parent 5d439cd commit 10b6758
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/vt/schemadiff/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,11 @@ func (s *Schema) ValidateViewReferences() error {
View: view.Name(),
Column: e.Column.Name.String(),
}
case *semantics.UnsupportedConstruct:
// These are error types from semantic analysis for executing queries. When we
// have a view, we don't have Vitess execute these queries but MySQL does, so
// we don't want to return errors for these.
return nil
}
return err
}
Expand Down
14 changes: 14 additions & 0 deletions go/vt/schemadiff/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,20 @@ func TestInvalidSchema(t *testing.T) {
`,
expectErr: &DuplicateForeignKeyConstraintNameError{Table: "t2", Constraint: "const_id"},
},
{
schema: `
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(255));
CREATE VIEW user_earnings_ranking AS
SELECT
u.id AS user_id,
e.total_earnings AS total_earnings,
ROW_NUMBER() OVER (
ORDER BY e.total_earnings DESC, u.id ASC
) AS ranking
FROM users AS u JOIN earnings AS e ON e.user_id = u.id;
`,
expectErr: &ViewDependencyUnresolvedError{View: "user_earnings_ranking"},
},
}
for _, ts := range tt {
t.Run(ts.schema, func(t *testing.T) {
Expand Down

0 comments on commit 10b6758

Please sign in to comment.