From 10b675889ad33fc604de5d0bcf8601ce3cdb0e28 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Wed, 5 Feb 2025 15:41:12 +0100 Subject: [PATCH] Ignore execution time errors for schemadiff view analysis 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 --- go/vt/schemadiff/schema.go | 5 +++++ go/vt/schemadiff/schema_test.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/go/vt/schemadiff/schema.go b/go/vt/schemadiff/schema.go index bbd1258070e..c251779061c 100644 --- a/go/vt/schemadiff/schema.go +++ b/go/vt/schemadiff/schema.go @@ -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 } diff --git a/go/vt/schemadiff/schema_test.go b/go/vt/schemadiff/schema_test.go index 1710cec12c7..43cfcf78bdc 100644 --- a/go/vt/schemadiff/schema_test.go +++ b/go/vt/schemadiff/schema_test.go @@ -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) {